Skip to content

Commit 54adb6e

Browse files
committed
feat: enhance snapshot update workflow with matrix strategy and improved artifact handling
1 parent 96fe79f commit 54adb6e

File tree

1 file changed

+104
-51
lines changed

1 file changed

+104
-51
lines changed

.github/workflows/update-snapshots.yml

Lines changed: 104 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,90 @@ 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: Git status after generating snapshots
70+
run: git status
71+
72+
- name: Package snapshot changes
73+
run: |
74+
if [ "${{ inputs.delete_snapshots }}" = "true" ]; then
75+
# All snapshots were purged and regenerated from scratch – capture every file on disk,
76+
# including those whose content is identical to HEAD (git diff would miss those).
77+
find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
78+
| tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
79+
else
80+
# Only capture files that actually changed (efficient for normal updates).
81+
{
82+
git diff --name-only --diff-filter=d HEAD -- ${{ matrix.path }}
83+
git ls-files --others --exclude-standard -- ${{ matrix.path }}
84+
} | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
85+
fi
86+
87+
- name: Upload snapshot artifacts
88+
uses: actions/upload-artifact@v7
89+
with:
90+
name: snapshots-${{ matrix.name }}
91+
path: snapshots.tar
92+
if-no-files-found: ignore
93+
retention-days: 1
94+
95+
push:
96+
needs: update
1897
runs-on: ubuntu-latest
1998
steps:
2099
- uses: actions/create-github-app-token@v3
@@ -34,64 +113,38 @@ jobs:
34113
with:
35114
ref: ${{ github.ref_name }}
36115
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-
73116
- name: Purge existing snapshots (optional)
74117
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
118+
run: |
119+
find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
120+
find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
79121
80-
- name: Run snapshot updates
81-
run: pnpm test:update
122+
- name: Download snapshot artifacts
123+
uses: actions/download-artifact@v8
124+
with:
125+
pattern: snapshots-*
126+
path: snapshot-artifacts
82127

83-
- name: Display git status (after test-update)
84-
run: git status
128+
- name: Apply snapshot updates
129+
run: |
130+
for dir in snapshot-artifacts/snapshots-*/; do
131+
if [ -f "${dir}snapshots.tar" ]; then
132+
tar xf "${dir}snapshots.tar"
133+
fi
134+
done
135+
rm -rf snapshot-artifacts
85136
86137
- name: Stage snapshot changes
87138
run: |
88-
# find does not follow symlinks by default, avoiding "beyond a symbolic link" git errors.
89-
# test-tag-name-transformer is excluded because its snapshots/ folder is listed in its .gitignore.
90-
find packages \( -path '*/node_modules' -o -path '*/test-tag-name-transformer' \) -prune \
91-
-o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -print \
139+
# Stage updated/new snapshot files (skip gitignored paths)
140+
find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
141+
| (git check-ignore --stdin --non-matching --verbose || test $? = 1) \
142+
| { grep '^::' || true; } | cut -f2 \
92143
| xargs --no-run-if-empty git add --
144+
# Also stage deletions (e.g. snapshots for removed tests)
145+
{ git diff --name-only --diff-filter=D HEAD || true; } | grep -E '(__snapshots__|snapshots)/' | xargs --no-run-if-empty git add --
93146
94-
- name: Display git status (after git add)
147+
- name: Git status after staging
95148
run: git status
96149

97150
- name: Commit and push changes

0 commit comments

Comments
 (0)