ci(chromatic): add chromatic workflow for react storybook #6
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: chromatic | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, reopened, synchronize, ready_for_review] | |
| branches: | |
| - main | |
| merge_group: | |
| types: [checks_requested] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| react-storybook: | |
| if: | |
| ${{ github.repository == 'carbon-design-system/carbon' && | |
| github.event.pull_request.draft == false }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| fetch-depth: 0 | |
| # π Tells the checkout which commit hash to reference | |
| # https://www.chromatic.com/docs/github-actions/#recommended-configuration-for-build-events | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Use Node.js version from .nvmrc | |
| uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version-file: '.nvmrc' | |
| - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | |
| if: github.event_name != 'merge_group' | |
| id: cache | |
| with: | |
| path: | | |
| node_modules | |
| */**/node_modules | |
| key: | |
| ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock', | |
| 'packages/**/yarn.lock') }} | |
| - name: Install dependencies | |
| env: | |
| YARN_ENABLE_HARDENED_MODE: 0 | |
| run: yarn install --immutable --immutable-cache | |
| - name: Build project | |
| run: yarn build | |
| - name: Build storybook | |
| run: yarn workspace @carbon/react storybook:build | |
| - name: Run Chromatic | |
| uses: chromaui/action@3378c92d26c32353e53166beac732e2edc14213c # v13.0.0 | |
| with: | |
| # π Token is intentionally plaintext | |
| # https://www.chromatic.com/docs/github-actions/#run-chromatic-on-external-forks-of-open-source-projects | |
| projectToken: 6q6rgoheqk2 | |
| workingDir: packages/react | |
| buildScriptName: storybook:build | |
| zip: true # Runs Chromatic with the option to compress the build output | |
| autoAcceptChanges: 'main' # Option to accept all changes on main | |
| # TODO: set up TurboSnap via onlyChanged w/ externals | |
| # https://www.chromatic.com/docs/github-actions/#enable-turbosnap | |
| # onlyChanged: true # π Required option to enable TurboSnap | |
| # externals: | | |
| # packages/(colors|elements|feature-flags|grid|icons|icons-react|layout|motion|pictograms|pictograms-react|styles|themes|type|utilities|utilities-react)/** | |
| # *.sass | |
| env: | |
| # π Set to the PR branch if it's a PR; otherwise, falls back to the pushed branch name | |
| CHROMATIC_BRANCH: | |
| ${{ github.event.pull_request.head.ref || github.ref_name }} | |
| # π Set to the PR head commit if it's a PR; otherwise to the ref (which typically resolves to the latest commit SHA) | |
| CHROMATIC_SHA: ${{ github.event.pull_request.head.sha || github.ref }} | |
| # π Makes sure this is always set to the corect owner/repo | |
| CHROMATIC_SLUG: ${{ github.repository }} |