From e5c9551cb8905181b54f1456eafdbf04d339a6e7 Mon Sep 17 00:00:00 2001 From: Dan Selman Date: Tue, 12 Dec 2023 00:54:07 +0000 Subject: [PATCH] fix: publish Signed-off-by: Dan Selman --- scripts/coverage.cjs | 50 +++++++++++++++++++++++++++++++++++++++++++ scripts/tag.cjs | 29 +++++++++++++++++++++++++ scripts/timestamp.cjs | 32 +++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100755 scripts/coverage.cjs create mode 100755 scripts/tag.cjs create mode 100755 scripts/timestamp.cjs diff --git a/scripts/coverage.cjs b/scripts/coverage.cjs new file mode 100755 index 0000000..10cd64b --- /dev/null +++ b/scripts/coverage.cjs @@ -0,0 +1,50 @@ +#!/usr/bin/env node + +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const globPattern = process.argv[2]; + +const util = require('util'); +const fs = require('fs'); +const path = require('path'); +const copyFilePromise = util.promisify(fs.copyFile); +const glob = require('glob'); + +// eslint-disable-next-line require-jsdoc +function copyFiles(files, destDir) { + if (!fs.existsSync('coverage')) { + fs.mkdirSync('coverage'); + } + return Promise.all(files.map(f => { + return copyFilePromise(f.source, path.join(destDir, f.destination)); + })); +} + +const lcovs = glob.sync(globPattern).map((dir) => { + const packageName = dir.split('/').pop(); + return { + source: path.join(dir, 'coverage/coverage-final.json'), + destination: `${packageName}.json` + }; +}); + +// usage +copyFiles(lcovs, 'coverage').then(() => { + console.log('done'); +}).catch(err => { + console.log(err); +}); \ No newline at end of file diff --git a/scripts/tag.cjs b/scripts/tag.cjs new file mode 100755 index 0000000..01fc4d1 --- /dev/null +++ b/scripts/tag.cjs @@ -0,0 +1,29 @@ +#!/usr/bin/env node +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const semver = require('semver'); +const targetVersion = process.argv[2]; + +if (!semver.valid(targetVersion)) { + console.error(`Error: the version "${targetVersion}" is invalid!`); + process.exit(1); +} + +const prerelease = semver.prerelease(targetVersion); +const tag = prerelease ? 'unstable' : 'latest'; + +console.log(`::set-output name=tag::--tag=${tag}`); diff --git a/scripts/timestamp.cjs b/scripts/timestamp.cjs new file mode 100755 index 0000000..3f38386 --- /dev/null +++ b/scripts/timestamp.cjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const path = require('path'); +const semver = require('semver'); +const dayjs = require('dayjs'); +const utc = require('dayjs/plugin/utc'); +dayjs.extend(utc); + +const timestamp = dayjs.utc().format('YYYYMMDDHHmmss'); + +const rootDir = path.resolve('.'); +const packageJson = path.resolve(rootDir, 'package.json'); +const meta = require(packageJson); +meta.version.replace(/-.*/, ''); +const targetVersion = semver.inc(meta.version, 'patch') + '-' + timestamp; +console.log(`::set-output name=stamp::${targetVersion}`); \ No newline at end of file