Skip to content

Commit e8306cc

Browse files
chore: improve chromatic CI (#18014)
Following [this Chromatic guide](https://www.chromatic.com/docs/turbosnap-best-practices) to improve our Chromatic jobs.
1 parent ca39931 commit e8306cc

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
2525
docs: ${{ steps.filter.outputs.docs }}
2626
go: ${{ steps.filter.outputs.go }}
27-
ts: ${{ steps.filter.outputs.ts }}
27+
site: ${{ steps.filter.outputs.site }}
2828
k8s: ${{ steps.filter.outputs.k8s }}
2929
ci: ${{ steps.filter.outputs.ci }}
3030
db: ${{ steps.filter.outputs.db }}
@@ -92,9 +92,8 @@ jobs:
9292
gomod:
9393
- "go.mod"
9494
- "go.sum"
95-
ts:
95+
site:
9696
- "site/**"
97-
- "Makefile"
9897
k8s:
9998
- "helm/**"
10099
- "scripts/Dockerfile"
@@ -774,7 +773,7 @@ jobs:
774773
test-js:
775774
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
776775
needs: changes
777-
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
776+
if: needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
778777
timeout-minutes: 20
779778
steps:
780779
- name: Harden Runner
@@ -805,7 +804,7 @@ jobs:
805804
#- premium: true
806805
# name: test-e2e-premium
807806
# Skip test-e2e on forks as they don't have access to CI secrets
808-
if: (needs.changes.outputs.go == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main') && !(github.event.pull_request.head.repo.fork)
807+
if: (needs.changes.outputs.go == 'true' || needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main') && !(github.event.pull_request.head.repo.fork)
809808
timeout-minutes: 20
810809
name: ${{ matrix.variant.name }}
811810
steps:
@@ -874,11 +873,13 @@ jobs:
874873
path: ./site/test-results/**/debug-pprof-*.txt
875874
retention-days: 7
876875

876+
# Reference guide:
877+
# https://www.chromatic.com/docs/turbosnap-best-practices/#run-with-caution-when-using-the-pull_request-event
877878
chromatic:
878879
# REMARK: this is only used to build storybook and deploy it to Chromatic.
879880
runs-on: ubuntu-latest
880881
needs: changes
881-
if: needs.changes.outputs.ts == 'true' || needs.changes.outputs.ci == 'true'
882+
if: needs.changes.outputs.site == 'true' || needs.changes.outputs.ci == 'true'
882883
steps:
883884
- name: Harden Runner
884885
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
@@ -888,9 +889,10 @@ jobs:
888889
- name: Checkout
889890
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
890891
with:
891-
# Required by Chromatic for build-over-build history, otherwise we
892-
# only get 1 commit on shallow checkout.
892+
# 👇 Ensures Chromatic can read your full git history
893893
fetch-depth: 0
894+
# 👇 Tells the checkout which commit hash to reference
895+
ref: ${{ github.event.pull_request.head.ref }}
894896

895897
- name: Setup Node
896898
uses: ./.github/actions/setup-node
@@ -900,7 +902,7 @@ jobs:
900902
# the check to pass. This is desired in PRs, but not in mainline.
901903
- name: Publish to Chromatic (non-mainline)
902904
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
903-
uses: chromaui/action@30b6228aa809059d46219e0f556752e8672a7e26 # v11.11.0
905+
uses: chromaui/action@1cfa065cbdab28f6ca3afaeb3d761383076a35aa # v11.29.0
904906
env:
905907
NODE_OPTIONS: "--max_old_space_size=4096"
906908
STORYBOOK: true
@@ -915,6 +917,7 @@ jobs:
915917
projectToken: 695c25b6cb65
916918
workingDir: "./site"
917919
storybookBaseDir: "./site"
920+
storybookConfigDir: "./site/.storybook"
918921
# Prevent excessive build runs on minor version changes
919922
skip: "@(renovate/**|dependabot/**)"
920923
# Run TurboSnap to trace file dependencies to related stories
@@ -931,7 +934,7 @@ jobs:
931934
# infinitely "in progress" in mainline unless we re-review each build.
932935
- name: Publish to Chromatic (mainline)
933936
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
934-
uses: chromaui/action@30b6228aa809059d46219e0f556752e8672a7e26 # v11.11.0
937+
uses: chromaui/action@1cfa065cbdab28f6ca3afaeb3d761383076a35aa # v11.29.0
935938
env:
936939
NODE_OPTIONS: "--max_old_space_size=4096"
937940
STORYBOOK: true
@@ -944,6 +947,7 @@ jobs:
944947
projectToken: 695c25b6cb65
945948
workingDir: "./site"
946949
storybookBaseDir: "./site"
950+
storybookConfigDir: "./site/.storybook"
947951
# Run TurboSnap to trace file dependencies to related stories
948952
# and tell chromatic to only take snapshots of relevant stories
949953
onlyChanged: true

0 commit comments

Comments
 (0)