Skip to content

Commit 2b5b675

Browse files
committed
feat: enhance snapshot update workflow with matrix strategy and improved artifact handling
1 parent 5d55266 commit 2b5b675

File tree

1 file changed

+107
-48
lines changed

1 file changed

+107
-48
lines changed

.github/workflows/update-snapshots.yml

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,87 @@ on:
1010
type: boolean
1111

1212
concurrency:
13-
group: 'workflow-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}'
13+
group: 'workflow-${{ github.workflow }}-${{ github.ref }}'
1414
cancel-in-progress: true
1515

1616
jobs:
17-
update-snapshots:
17+
update:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- name: components
24+
path: packages/components
25+
type: unit
26+
- name: hydrate-server
27+
path: packages/tools/hydrate-server
28+
type: unit
29+
- name: hydrate
30+
path: packages/adapters/hydrate
31+
type: unit
32+
- name: theme-default
33+
path: packages/themes/default
34+
type: e2e
35+
- name: theme-kern
36+
path: packages/themes/kern
37+
type: e2e
38+
- name: test-tag-name-transformer
39+
path: packages/test-tag-name-transformer
40+
type: e2e
41+
steps:
42+
- name: Checkout branch
43+
uses: actions/checkout@v6
44+
with:
45+
ref: ${{ github.ref_name }}
46+
persist-credentials: false
47+
48+
- uses: ./.github/actions/pnpm-setup
49+
50+
- name: Install Playwright browsers
51+
if: matrix.type == 'e2e'
52+
run: npx playwright install --with-deps firefox
53+
54+
- name: Build
55+
run: pnpm --filter @public-ui/sample-react^... build
56+
57+
- name: Purge existing snapshots
58+
if: inputs.delete_snapshots == true
59+
run: |
60+
if [ "${{ matrix.type }}" = "e2e" ]; then
61+
find ${{ matrix.path }} -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
62+
else
63+
find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
64+
fi
65+
66+
- name: Run snapshot update
67+
run: pnpm --filter @public-ui/${{ matrix.name }} test:update:${{ matrix.type }}
68+
69+
- name: Package snapshot changes
70+
run: |
71+
if [ "${{ inputs.delete_snapshots }}" = "true" ]; then
72+
# All snapshots were purged and regenerated from scratch – capture every file on disk,
73+
# including those whose content is identical to HEAD (git diff would miss those).
74+
find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
75+
| tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
76+
else
77+
# Only capture files that actually changed (efficient for normal updates).
78+
{
79+
git diff --name-only --diff-filter=d HEAD -- ${{ matrix.path }}
80+
git ls-files --others --exclude-standard -- ${{ matrix.path }}
81+
} | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
82+
fi
83+
84+
- name: Upload snapshot artifacts
85+
uses: actions/upload-artifact@v7
86+
with:
87+
name: snapshots-${{ matrix.name }}
88+
path: snapshots.tar
89+
if-no-files-found: ignore
90+
retention-days: 1
91+
92+
push:
93+
needs: update
1894
runs-on: ubuntu-latest
1995
steps:
2096
- uses: actions/create-github-app-token@v3
@@ -34,61 +110,44 @@ jobs:
34110
with:
35111
ref: ${{ github.ref_name }}
36112
token: ${{ steps.app-token.outputs.token }}
37-
38-
# https://github.com/pnpm/action-setup#use-cache-to-reduce-installation-time
39-
- name: Install Node.js
40-
uses: actions/setup-node@v6
41-
with:
42-
node-version: 22
43-
44-
- name: Install pnpm
45-
uses: pnpm/action-setup@v4
46-
id: pnpm-install
47-
with:
48-
version: 10
49-
run_install: false
50-
51-
- name: Get pnpm store directory
52-
id: pnpm-cache
53-
shell: bash
54-
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
55-
56-
- name: Setup pnpm cache
57-
uses: actions/cache@v5
58-
with:
59-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
60-
key: ${{ runner.os }}-pnpm-store
61-
restore-keys: |
62-
${{ runner.os }}-pnpm-store
63-
64-
- name: Install
65-
run: pnpm i --no-frozen-lockfile
66-
67-
- name: Install Playwright browsers
68-
run: npx playwright install --with-deps firefox
69-
70-
- name: Build
71-
run: pnpm --filter @public-ui/sample-react^... build
72-
73113
- name: Purge existing snapshots (optional)
74114
if: inputs.delete_snapshots == true
75-
run: find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs rm # Remove any existing snapshots, except those in node_modules
76-
77-
- name: Display git status (before test-update)
78-
run: git status
115+
run: |
116+
find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
117+
find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
79118
80-
- name: Run snapshot updates
81-
run: pnpm test:update
82-
83-
- name: Display git status (after test-update)
84-
run: git status
119+
- name: Download snapshot artifacts
120+
uses: actions/download-artifact@v8
121+
with:
122+
pattern: snapshots-*
123+
path: snapshot-artifacts
124+
125+
- name: Apply snapshot updates
126+
run: |
127+
for dir in snapshot-artifacts/snapshots-*/; do
128+
if [ -f "${dir}snapshots.tar" ]; then
129+
tar xf "${dir}snapshots.tar"
130+
fi
131+
done
132+
rm -rf snapshot-artifacts
85133
86134
- name: Stage snapshot changes
87-
run: find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -print | xargs --no-run-if-empty git add --
135+
run: |
136+
# Stage updated/new snapshot files (skip gitignored paths)
137+
find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
138+
| (git check-ignore --stdin --non-matching --verbose || test $? = 1) \
139+
| { grep '^::' || true; } | cut -f2 \
140+
| xargs --no-run-if-empty git add --
141+
# Also stage deletions (e.g. snapshots for removed tests)
142+
{ git diff --name-only --diff-filter=D HEAD || true; } | grep -E '(__snapshots__|snapshots)/' | xargs --no-run-if-empty git add --
143+
144+
- name: Display git status after staging
145+
run: git status
88146

89147
- name: Commit and push changes
90148
uses: stefanzweifel/git-auto-commit-action@v7
91149
with:
92150
commit_message: Update all snapshots
151+
file_pattern: ''
93152
commit_user_name: '${{ steps.app-token.outputs.app-slug }}[bot]'
94153
commit_user_email: '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'

0 commit comments

Comments
 (0)