From 0a58cc61aa03e560b5bbe92001f571207947119f Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 6 Jul 2023 12:03:41 +0200 Subject: [PATCH 01/12] Introduce ci:normal label Co-authored-by: Kasper Peulen --- .circleci/config.yml | 59 +------------------ .github/PULL_REQUEST_TEMPLATE.md | 3 +- .../workflows/trigger-circle-ci-workflow.yml | 23 +------- 3 files changed, 6 insertions(+), 79 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 596da221fa85..144428777e9c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,8 +4,8 @@ parameters: workflow: description: Which workflow to run type: enum - enum: ['ci', 'pr', 'merged', 'daily'] - default: 'ci' + enum: ['pr', 'merged', 'daily'] + default: 'pr' executors: sb_node_16_classic: @@ -257,7 +257,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_node_16_browsers @@ -282,7 +281,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_node_16_browsers @@ -303,7 +301,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: large name: sb_node_16_browsers @@ -338,7 +335,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_playwright @@ -359,7 +355,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: large name: sb_playwright @@ -380,7 +375,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_node_16_browsers @@ -400,7 +394,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_playwright @@ -424,7 +417,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_playwright @@ -448,7 +440,6 @@ jobs: parameters: parallelism: type: integer - default: 2 executor: class: medium name: sb_playwright @@ -468,51 +459,6 @@ jobs: template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench) workflows: - ci: - when: - and: - - equal: [api, << pipeline.trigger_source >>] - - equal: [ci, << pipeline.parameters.workflow >>] - jobs: - - pretty-docs - - build - - lint: - requires: - - build - - check: - requires: - - build - - unit-tests: - requires: - - build - - script-unit-tests: - requires: - - build - - chromatic-internal-storybooks: - requires: - - build - - create-sandboxes: - requires: - - build - - build-sandboxes: - requires: - - create-sandboxes - - chromatic-sandboxes: - requires: - - build-sandboxes - - e2e-production: - requires: - - build-sandboxes - - e2e-dev: - requires: - - create-sandboxes - - test-runner-production: - requires: - - build-sandboxes - # TODO: reenable once we find out the source of flakyness - # - test-runner-dev: - # requires: - # - create-sandboxes pr: when: equal: [pr, << pipeline.parameters.workflow >>] @@ -554,6 +500,7 @@ workflows: requires: - build-sandboxes - e2e-dev: + parallelism: 2 requires: - create-sandboxes - test-runner-production: diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 655dd310ffaf..c4caf9cb3f0e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -27,8 +27,7 @@ Closes # #### Maintainers -- [ ] If this PR should be tested against many or all sandboxes, - make sure to add the `ci:merged` or `ci:daily` GH label to it. +- [ ] When this PR is ready for testing, make sure to add `ci:normal`, `ci:merged` or `ci:daily` GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in `code/lib/cli/src/sandbox-templates.ts` - [ ] Make sure this PR contains **one** of the labels below. `["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]` diff --git a/.github/workflows/trigger-circle-ci-workflow.yml b/.github/workflows/trigger-circle-ci-workflow.yml index 7b1f853bde1e..235d05833824 100644 --- a/.github/workflows/trigger-circle-ci-workflow.yml +++ b/.github/workflows/trigger-circle-ci-workflow.yml @@ -32,29 +32,10 @@ jobs: outputs: branch: ${{ env.branch }} - trigger-ci-tests: - runs-on: ubuntu-latest - needs: get-branch - if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == true && !contains(github.event.pull_request.labels.*.name, 'ci:pr') && !contains(github.event.pull_request.labels.*.name, 'ci:merged') && !contains(github.event.pull_request.labels.*.name, 'ci:daily') - steps: - - name: Trigger draft PR tests - run: > - curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \ - -H "Content-Type: application/json" \ - -H "Circle-Token: $CIRCLE_CI_TOKEN" \ - -d '{ - "branch": "'"$BRANCH"'", - "parameters": { - "workflow": "ci" - } - }' - env: - CIRCLE_CI_TOKEN: ${{ secrets.CIRCLE_CI_TOKEN }} - BRANCH: ${{ needs.get-branch.outputs.branch }} trigger-pr-tests: runs-on: ubuntu-latest needs: get-branch - if: github.event_name == 'pull_request_target' && (((github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'release')) || contains(github.event.pull_request.labels.*.name, 'ci:pr')) && !contains(github.event.pull_request.labels.*.name, 'ci:merged') && !contains(github.event.pull_request.labels.*.name, 'ci:daily')) + if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'ci:normal') steps: - name: Trigger PR tests run: > @@ -73,7 +54,7 @@ jobs: trigger-merged-tests: runs-on: ubuntu-latest needs: get-branch - if: github.event_name == 'push' || (contains(github.event.pull_request.labels.*.name, 'ci:merged') && !contains(github.event.pull_request.labels.*.name, 'ci:daily')) + if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci:merged') steps: - name: Trigger merged tests run: > From 9f8d871ae711222d0ed5b2677e8bfed8d67b7036 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 6 Jul 2023 12:24:38 +0200 Subject: [PATCH 02/12] Adjust Danger.js to enforce setting one of the ci labels --- scripts/dangerfile.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/dangerfile.ts b/scripts/dangerfile.ts index 1d80df10e0da..4ab0d218b38a 100644 --- a/scripts/dangerfile.ts +++ b/scripts/dangerfile.ts @@ -17,6 +17,8 @@ const Versions = { MAJOR: 'MAJOR', }; +const ciLabels = ['ci:normal', 'ci:merged', 'ci:daily']; + const branchVersion = Versions.MINOR; const checkRequiredLabels = (labels: string[]) => { @@ -47,6 +49,13 @@ const checkRequiredLabels = (labels: string[]) => { } else if (foundLabels.length > 1) { fail(`Please choose only one of these labels: ${JSON.stringify(foundLabels)}`); } + + const foundCILabels = intersection(ciLabels, labels); + if (isEmpty(foundCILabels)) { + fail(`PR is not labeled with one of: ${JSON.stringify(ciLabels)}`); + } else if (foundCILabels.length > 1) { + fail(`Please choose only one of these labels: ${JSON.stringify(foundCILabels)}`); + } }; const checkPrTitle = (title: string) => { From 6715c52a51a4434c2d512a5fb943c510f61f4994 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 6 Jul 2023 12:26:20 +0200 Subject: [PATCH 03/12] Do not run a workflow per default --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 144428777e9c..d8a7978310ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -5,7 +5,6 @@ parameters: description: Which workflow to run type: enum enum: ['pr', 'merged', 'daily'] - default: 'pr' executors: sb_node_16_classic: From d1473ec35dbfb8fce48db6013486d2d7a940de35 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 6 Jul 2023 12:29:58 +0200 Subject: [PATCH 04/12] Add noop job to trick circleci --- .circleci/config.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d8a7978310ee..dec04c821bf5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,8 @@ parameters: workflow: description: Which workflow to run type: enum - enum: ['pr', 'merged', 'daily'] + enum: ['noop', 'pr', 'merged', 'daily'] + default: 'noop' executors: sb_node_16_classic: @@ -81,6 +82,14 @@ commands: fail_only: true failure_message: $(yarn get-report-message << pipeline.parameters.workflow >> << parameters.template >>) jobs: + noop: + executor: + class: small + name: sb_node_16_classic + steps: + - run: + name: Noop + command: echo "Noop" pretty-docs: executor: class: small @@ -458,6 +467,11 @@ jobs: template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench) workflows: + noop: + when: + equal: [noop, << pipeline.parameters.workflow >>] + jobs: + - noop pr: when: equal: [pr, << pipeline.parameters.workflow >>] From 7193c361e8a9cc17147443a306ea8b1f7074d160 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 6 Jul 2023 14:51:38 +0200 Subject: [PATCH 05/12] Retrigger pipeline From f30612849700a66f0d5b4da4d708bd4bfd59ef56 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Mon, 10 Jul 2023 11:16:42 +0200 Subject: [PATCH 06/12] Remove noop workflow and rename 'pr' workflow to 'normal' --- .circleci/config.yml | 21 ++++--------------- .../workflows/trigger-circle-ci-workflow.yml | 6 +++--- code/lib/cli/src/sandbox-templates.ts | 10 ++++----- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dec04c821bf5..00c5bad1fac2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,8 +4,8 @@ parameters: workflow: description: Which workflow to run type: enum - enum: ['noop', 'pr', 'merged', 'daily'] - default: 'noop' + enum: ['normal', 'merged', 'daily'] + default: 'normal' executors: sb_node_16_classic: @@ -82,14 +82,6 @@ commands: fail_only: true failure_message: $(yarn get-report-message << pipeline.parameters.workflow >> << parameters.template >>) jobs: - noop: - executor: - class: small - name: sb_node_16_classic - steps: - - run: - name: Noop - command: echo "Noop" pretty-docs: executor: class: small @@ -467,14 +459,9 @@ jobs: template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench) workflows: - noop: - when: - equal: [noop, << pipeline.parameters.workflow >>] - jobs: - - noop - pr: + normal: when: - equal: [pr, << pipeline.parameters.workflow >>] + equal: [normal, << pipeline.parameters.workflow >>] jobs: - pretty-docs - build diff --git a/.github/workflows/trigger-circle-ci-workflow.yml b/.github/workflows/trigger-circle-ci-workflow.yml index 235d05833824..f4b5d96ea75a 100644 --- a/.github/workflows/trigger-circle-ci-workflow.yml +++ b/.github/workflows/trigger-circle-ci-workflow.yml @@ -32,12 +32,12 @@ jobs: outputs: branch: ${{ env.branch }} - trigger-pr-tests: + trigger-normal-tests: runs-on: ubuntu-latest needs: get-branch if: github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'ci:normal') steps: - - name: Trigger PR tests + - name: Trigger Normal tests run: > curl -X POST --location "https://circleci.com/api/v2/project/gh/storybookjs/storybook/pipeline" \ -H "Content-Type: application/json" \ @@ -45,7 +45,7 @@ jobs: -d '{ "branch": "'"$BRANCH"'", "parameters": { - "workflow": "pr" + "workflow": "normal" } }' env: diff --git a/code/lib/cli/src/sandbox-templates.ts b/code/lib/cli/src/sandbox-templates.ts index 2ca650b32eb4..40e5dab1f268 100644 --- a/code/lib/cli/src/sandbox-templates.ts +++ b/code/lib/cli/src/sandbox-templates.ts @@ -534,9 +534,9 @@ export const allTemplates: Record = { ...benchTemplates, }; -export const ci: TemplateKey[] = ['cra/default-ts', 'react-vite/default-ts']; -export const pr: TemplateKey[] = [ - ...ci, +export const normal: TemplateKey[] = [ + 'cra/default-ts', + 'react-vite/default-ts', 'angular-cli/default-ts', 'vue3-vite/default-ts', 'vue-cli/vue2-default-js', @@ -548,7 +548,7 @@ export const pr: TemplateKey[] = [ 'bench/react-webpack-18-ts', ]; export const merged: TemplateKey[] = [ - ...pr, + ...normal, 'react-webpack/18-ts', 'react-webpack/17-ts', 'angular-cli/14-ts', @@ -578,4 +578,4 @@ export const daily: TemplateKey[] = [ 'html-vite/default-js', ]; -export const templatesByCadence = { ci, pr, merged, daily }; +export const templatesByCadence = { normal, merged, daily }; From bc2114c558270e57bada8a68e92806da1f72742c Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 11 Jul 2023 15:53:01 +0200 Subject: [PATCH 07/12] Only cancel in-progress jobs or runs for the current workflow --- .github/workflows/trigger-circle-ci-workflow.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/trigger-circle-ci-workflow.yml b/.github/workflows/trigger-circle-ci-workflow.yml index f4b5d96ea75a..2547a08218a3 100644 --- a/.github/workflows/trigger-circle-ci-workflow.yml +++ b/.github/workflows/trigger-circle-ci-workflow.yml @@ -10,6 +10,10 @@ on: - next - main +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: get-branch: runs-on: ubuntu-latest From bbc275f06f66e6479a4bba3df80ecea1c7c4900d Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 11 Jul 2023 16:40:27 +0200 Subject: [PATCH 08/12] Fix Danger.js output --- scripts/dangerfile.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/dangerfile.ts b/scripts/dangerfile.ts index 826fa973e391..6e8c5a2536ae 100644 --- a/scripts/dangerfile.ts +++ b/scripts/dangerfile.ts @@ -50,9 +50,10 @@ const checkRequiredLabels = (labels: string[]) => { fail(`Please choose only one of these labels: ${JSON.stringify(foundRequiredLabels)}`); } - const foundPatchLabels = intersection(['patch:no', 'patch:yes'], labels); + const labelsForPatchStatus = ['patch:no', 'patch:yes']; + const foundPatchLabels = intersection(labelsForPatchStatus, labels); if (isEmpty(foundPatchLabels)) { - fail(`PR is not labeled with one of: ${JSON.stringify(foundPatchLabels)}`); + fail(`PR is not labeled with one of: ${JSON.stringify(labelsForPatchStatus)}`); } else if (foundPatchLabels.length > 1) { fail(`Please choose only one of these labels: ${JSON.stringify(foundPatchLabels)}`); } From 3810fd19f37ea34f0979bbe73db08e103ed249a3 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Wed, 12 Jul 2023 13:06:32 +0200 Subject: [PATCH 09/12] improve onboarding detection in whats new module --- code/lib/manager-api/src/modules/whatsnew.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/lib/manager-api/src/modules/whatsnew.ts b/code/lib/manager-api/src/modules/whatsnew.ts index 21d0596683f6..5890eaae6fc7 100644 --- a/code/lib/manager-api/src/modules/whatsnew.ts +++ b/code/lib/manager-api/src/modules/whatsnew.ts @@ -73,10 +73,12 @@ export const init: ModuleFn = ({ fullAPI, store }) => { const whatsNewData = await getLatestWhatsNewPost(); setWhatsNewState(whatsNewData); - const isNewStoryBookUser = fullAPI.getUrlState().path.includes('onboarding'); + const urlState = fullAPI.getUrlState(); + const isOnboardingView = + urlState?.path === '/onboarding' || urlState.queryParams?.onboarding === 'true'; if ( - !isNewStoryBookUser && + !isOnboardingView && whatsNewData.status === 'SUCCESS' && !whatsNewData.disableWhatsNewNotifications && whatsNewData.showNotification From ca8a47af6a9979a44dd13accd428e7108e78b777 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Thu, 13 Jul 2023 14:58:53 +0800 Subject: [PATCH 10/12] Telemetry: Add globals usage to project.json --- code/lib/telemetry/package.json | 1 + code/lib/telemetry/src/storybook-metadata.ts | 11 +++++++++++ code/lib/telemetry/src/types.ts | 3 +++ code/yarn.lock | 1 + 4 files changed, 16 insertions(+) diff --git a/code/lib/telemetry/package.json b/code/lib/telemetry/package.json index 31a3f8b1ffa7..8ad9770dfae6 100644 --- a/code/lib/telemetry/package.json +++ b/code/lib/telemetry/package.json @@ -45,6 +45,7 @@ "dependencies": { "@storybook/client-logger": "7.1.0-rc.1", "@storybook/core-common": "7.1.0-rc.1", + "@storybook/csf-tools": "7.1.0-rc.1", "chalk": "^4.1.0", "detect-package-manager": "^2.0.1", "fetch-retry": "^5.0.2", diff --git a/code/lib/telemetry/src/storybook-metadata.ts b/code/lib/telemetry/src/storybook-metadata.ts index d17294256497..01a54d9c9ec0 100644 --- a/code/lib/telemetry/src/storybook-metadata.ts +++ b/code/lib/telemetry/src/storybook-metadata.ts @@ -7,6 +7,7 @@ import { getProjectRoot, } from '@storybook/core-common'; import type { StorybookConfig, PackageJson } from '@storybook/types'; +import { readConfig } from '@storybook/csf-tools'; import type { StorybookMetadata, Dependency, StorybookAddon } from './types'; import { getActualPackageVersion, getActualPackageVersions } from './package-json'; @@ -160,6 +161,16 @@ export const computeStorybookMetadata = async ({ const hasStorybookEslint = !!allDependencies['eslint-plugin-storybook']; const storybookInfo = getStorybookInfo(packageJson); + + const { previewConfig } = storybookInfo; + if (previewConfig) { + const config = await readConfig(previewConfig); + const usesGlobals = !!( + config.getFieldNode(['globals']) || config.getFieldNode(['globalTypes']) + ); + metadata.preview = { ...metadata.preview, usesGlobals }; + } + const storybookVersion = storybookPackages[storybookInfo.frameworkPackage]?.version; return { diff --git a/code/lib/telemetry/src/types.ts b/code/lib/telemetry/src/types.ts index 25100149fd44..ba3af37719c0 100644 --- a/code/lib/telemetry/src/types.ts +++ b/code/lib/telemetry/src/types.ts @@ -54,6 +54,9 @@ export type StorybookMetadata = { hasCustomBabel?: boolean; features?: StorybookConfig['features']; refCount?: number; + preview?: { + usesGlobals?: boolean; + }; }; export interface Payload { diff --git a/code/yarn.lock b/code/yarn.lock index 820f77a52beb..746279daa5dc 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -7452,6 +7452,7 @@ __metadata: dependencies: "@storybook/client-logger": 7.1.0-rc.1 "@storybook/core-common": 7.1.0-rc.1 + "@storybook/csf-tools": 7.1.0-rc.1 chalk: ^4.1.0 detect-package-manager: ^2.0.1 fetch-retry: ^5.0.2 From 1b627aea6402a94d3fea5136daabbaeb4150e77a Mon Sep 17 00:00:00 2001 From: Jeppe Reinhold Date: Thu, 13 Jul 2023 09:34:55 +0200 Subject: [PATCH 11/12] dont self-trigger publish workflow in publish workflow --- .github/workflows/publish.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 23a8f37bfaa4..d319a540c376 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,6 +27,15 @@ jobs: run: working-directory: scripts steps: + - name: Cancel if [skip ci] + if: contains(github.event.head_commit.message, '[skip ci]') + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # From https://stackoverflow.com/a/75809743 + run: | + gh run cancel ${{ github.run_id }} + gh run watch ${{ github.run_id }} + - name: Checkout ${{ github.ref_name }} uses: actions/checkout@v3 with: @@ -71,7 +80,7 @@ jobs: git config --global user.name "storybook-bot" git config --global user.email "32066757+storybook-bot@users.noreply.github.com" git add . - git commit -m "Bump version from $CURRENT_VERSION to $DEFERRED_NEXT_VERSION" || true + git commit -m "Bump version from $CURRENT_VERSION to $DEFERRED_NEXT_VERSION [skip ci]" || true git push origin ${{ github.ref_name }} - name: Get current version @@ -149,7 +158,7 @@ jobs: git pull git checkout origin/main ./CHANGELOG.md git add ./CHANGELOG.md - git commit -m "Update CHANGELOG.md for v${{ steps.version.outputs.current-version }}" + git commit -m "Update CHANGELOG.md for v${{ steps.version.outputs.current-version }} [skip ci]" git push origin next - name: Sync versions/next.json from `next` to `main` From 79c01df23b4cb33dac5819c69dc7bf2f3ad4326d Mon Sep 17 00:00:00 2001 From: Zan Markan Date: Thu, 13 Jul 2023 11:05:42 +0100 Subject: [PATCH 12/12] Skip the default CircleCI workflow when no workflow argument is set --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bc0cc4f918b0..6709cc29daf3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,8 +4,8 @@ parameters: workflow: description: Which workflow to run type: enum - enum: ['normal', 'merged', 'daily'] - default: 'normal' + enum: ['normal', 'merged', 'daily', 'skipped'] + default: 'skipped' executors: sb_node_16_classic: