From 37632ba047045ea5e055be2746a0fa5fb9e8f6df Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Sun, 15 Oct 2023 21:33:16 +0200 Subject: [PATCH] set explicit version when using is-prerelease check --- .../workflows/prepare-non-patch-release.yml | 2 +- .github/workflows/publish.yml | 2 +- scripts/release/get-changelog-from-file.ts | 2 +- scripts/release/is-prerelease.ts | 28 +++++++++++++++---- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/prepare-non-patch-release.yml b/.github/workflows/prepare-non-patch-release.yml index 8d523a17a7ab..c0b79df361b9 100644 --- a/.github/workflows/prepare-non-patch-release.yml +++ b/.github/workflows/prepare-non-patch-release.yml @@ -114,7 +114,7 @@ jobs: - name: Check release vs prerelease id: is-prerelease - run: yarn release:is-prerelease + run: yarn release:is-prerelease ${{ steps.bump-version.outputs.next-version }} --verbose - name: Write changelog env: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8f02f2d0737c..fc347cfe32ef 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -98,7 +98,7 @@ jobs: - name: Check release vs prerelease if: steps.publish-needed.outputs.published == 'false' id: is-prerelease - run: yarn release:is-prerelease + run: yarn release:is-prerelease ${{ steps.version.outputs.current-version }} --verbose - name: Install code dependencies if: steps.publish-needed.outputs.published == 'false' diff --git a/scripts/release/get-changelog-from-file.ts b/scripts/release/get-changelog-from-file.ts index 78514d7a68af..e01efe959032 100644 --- a/scripts/release/get-changelog-from-file.ts +++ b/scripts/release/get-changelog-from-file.ts @@ -11,7 +11,7 @@ import { getCurrentVersion } from './get-current-version'; program .name('get-changelog-from-file') .description( - 'get changelog entry for specific version. If not version argument specified it will use the current version in code/package.json' + 'get changelog entry for specific version. If no version argument specified it will use the current version in code/package.json' ) .arguments('[version]') .option('-E, --no-escape', 'Escape quote-like characters, so the output is safe in CLIs', true) diff --git a/scripts/release/is-prerelease.ts b/scripts/release/is-prerelease.ts index 5a3f7ef11c9e..25722c098cd6 100644 --- a/scripts/release/is-prerelease.ts +++ b/scripts/release/is-prerelease.ts @@ -7,19 +7,31 @@ import { getCurrentVersion } from './get-current-version'; program .name('is-prerelease') - .description('returns true if the current version is a prerelease') + .description( + 'returns true if the specified version is a prerelease. If no version argument specified it will use the current version in code/package.json' + ) + .arguments('[version]') .option('-V, --verbose', 'Enable verbose logging', false); -export const isPrerelease = async (versionArg?: string) => { - const version = versionArg || (await getCurrentVersion()); +export const isPrerelease = async (args: { version?: string; verbose?: boolean }) => { + if (args.verbose) { + if (args.version) { + console.log(`📦 Checking if version ${chalk.blue(args.version)} is a prerelease`); + } else { + console.log( + `📦 Checking if current version in ${chalk.blue('code/package.json')} is a prerelease` + ); + } + } + const version = args.version || (await getCurrentVersion()); const result = semver.prerelease(version) !== null; if (process.env.GITHUB_ACTIONS === 'true') { setOutput('prerelease', result); } console.log( - `📦 Current version ${chalk.green(version)} ${ - result ? chalk.blue('IS') : chalk.red('IS NOT') + `📦 Version ${chalk.blue(version)} ${ + result ? chalk.green('IS') : chalk.red('IS NOT') } a prerelease` ); @@ -27,7 +39,11 @@ export const isPrerelease = async (versionArg?: string) => { }; if (require.main === module) { - isPrerelease().catch((err) => { + const parsed = program.parse(); + isPrerelease({ + version: parsed.args[0], + verbose: parsed.opts().verbose, + }).catch((err) => { console.error(err); process.exit(1); });