Skip to content

Commit

Permalink
Merge pull request storybookjs#24479 from storybookjs/fix-prerelease-…
Browse files Browse the repository at this point in the history
…detection

Release tooling: Fix prerelease-detection in non-patch preparation
  • Loading branch information
JReinhold authored Oct 15, 2023
2 parents 0a6e94c + 37632ba commit d4fdd00
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prepare-non-patch-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/get-changelog-from-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 22 additions & 6 deletions scripts/release/is-prerelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,43 @@ 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`
);

return result;
};

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);
});
Expand Down

0 comments on commit d4fdd00

Please sign in to comment.