Skip to content

Commit

Permalink
Merge pull request #25596 from storybookjs/jeppe/versioned-canary-san…
Browse files Browse the repository at this point in the history
…dbox

CLI: Support upgrading to canary versions
(cherry picked from commit f091347)
  • Loading branch information
JReinhold committed Jan 15, 2024
1 parent 5ac3a15 commit a2055b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/canary-release-pr.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Publish canary release of PR
run-name: 'Canary release: PR #${{ inputs.pr }}, triggered by ${{ github.triggering_actor }}'
run-name: "Canary release: PR #${{ inputs.pr }}, triggered by ${{ github.triggering_actor }}"

on:
workflow_dispatch:
inputs:
pr:
description: 'Pull request number to create a canary release for'
description: "Pull request number to create a canary release for"
required: true
type: number

Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
node-version-file: ".nvmrc"
- name: Cache dependencies
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -91,10 +91,10 @@ jobs:
with:
githubToken: ${{ secrets.GH_TOKEN }}
prNumber: ${{ inputs.pr }}
find: 'CANARY_RELEASE_SECTION'
find: "CANARY_RELEASE_SECTION"
isHtmlCommentTag: true
replace: |
This pull request has been released as version [`${{ steps.version.outputs.next-version }}`](https://npmjs.com/package/@storybook/cli/v/${{ steps.version.outputs.next-version }}). Install it by pinning all your Storybook dependencies to that version.
This pull request has been released as version `${{ steps.version.outputs.next-version }}`. Try it out in a new sandbox by running `npx storybook@${{ steps.version.outputs.next-version }} sandbox` or in an existing project with `npx storybook@${{ steps.version.outputs.next-version }} upgrade`.
<details>
<summary>More information</summary>
Expand Down
19 changes: 10 additions & 9 deletions code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,14 @@ export const doUpgrade = async ({

const packageManager = JsPackageManagerFactory.getPackageManager({ force: pkgMgr });

const currentVersion = versions['@storybook/cli'];
const beforeVersion = await getStorybookCoreVersion();
const currentVersion = versions['@storybook/cli'];
const isCanary = currentVersion.startsWith('0.0.0');

if (lt(currentVersion, beforeVersion)) {
if (!isCanary && lt(currentVersion, beforeVersion)) {
throw new UpgradeStorybookToLowerVersionError({ beforeVersion, currentVersion });
}
if (eq(currentVersion, beforeVersion)) {
if (!isCanary && eq(currentVersion, beforeVersion)) {
throw new UpgradeStorybookToSameVersionError({ beforeVersion });
}

Expand Down Expand Up @@ -348,12 +349,12 @@ export const doUpgrade = async ({
// only upgrade packages that are in the monorepo
return dependency in versions;
}) as Array<keyof typeof versions>;
return monorepoDependencies.map(
(dependency) =>
// add ^ modifier to the version if this is the latest and stable version
// example output: @storybook/react@^8.0.0
`${dependency}@${!isOutdated || isPrerelease ? '^' : ''}${versions[dependency]}`
);
return monorepoDependencies.map((dependency) => {
/* add ^ modifier to the version if this is the latest stable or prerelease version
example outputs: @storybook/react@^8.0.0 */
const maybeCaret = (!isOutdated || isPrerelease) && !isCanary ? '^' : '';
return `${dependency}@${maybeCaret}${versions[dependency]}`;
});
};

const upgradedDependencies = toUpgradedDependencies(packageJson.dependencies);
Expand Down

0 comments on commit a2055b3

Please sign in to comment.