Skip to content

Commit b9f593d

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

File tree

1 file changed

+100
-47
lines changed

1 file changed

+100
-47
lines changed

.github/workflows/update-snapshots.yml

Lines changed: 100 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,81 @@ 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:
1717
update-snapshots:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- name: components
24+
type: unit
25+
- name: hydrate-server
26+
type: unit
27+
- name: hydrate
28+
type: unit
29+
- name: theme-default
30+
type: e2e
31+
- name: theme-kern
32+
type: e2e
33+
- name: test-tag-name-transformer
34+
type: e2e
35+
steps:
36+
- name: Checkout branch
37+
uses: actions/checkout@v6
38+
with:
39+
ref: ${{ github.ref_name }}
40+
persist-credentials: false
41+
42+
- uses: ./.github/actions/pnpm-setup
43+
44+
- name: Install Playwright browsers
45+
if: matrix.type == 'e2e'
46+
run: npx playwright install --with-deps firefox
47+
48+
- name: Build
49+
run: pnpm --filter @public-ui/sample-react^... build
50+
51+
- name: Purge existing snapshots
52+
if: inputs.delete_snapshots == true
53+
run: |
54+
if [ "${{ matrix.type }}" = "e2e" ]; then
55+
find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
56+
else
57+
find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
58+
fi
59+
60+
- name: Run snapshot update
61+
run: pnpm --filter @public-ui/${{ matrix.name }} test:update:${{ matrix.type }}
62+
63+
- name: Package snapshot changes
64+
run: |
65+
if [ "${{ inputs.delete_snapshots }}" = "true" ]; then
66+
# All snapshots were purged and regenerated from scratch – capture every file on disk,
67+
# including those whose content is identical to HEAD (git diff would miss those).
68+
find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
69+
| tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
70+
else
71+
# Only capture files that actually changed (efficient for normal updates).
72+
{
73+
git diff --name-only --diff-filter=d HEAD
74+
git ls-files --others --exclude-standard
75+
} | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
76+
fi
77+
78+
- name: Upload snapshot artifacts
79+
uses: actions/upload-artifact@v7
80+
with:
81+
name: snapshots-${{ matrix.name }}
82+
path: snapshots.tar
83+
if-no-files-found: ignore
84+
retention-days: 1
85+
86+
push-snapshots:
87+
needs: update-snapshots
1888
runs-on: ubuntu-latest
1989
steps:
2090
- uses: actions/create-github-app-token@v3
@@ -34,61 +104,44 @@ jobs:
34104
with:
35105
ref: ${{ github.ref_name }}
36106
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-
73107
- name: Purge existing snapshots (optional)
74108
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
109+
run: |
110+
find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
111+
find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
79112
80-
- name: Run snapshot updates
81-
run: pnpm test:update
82-
83-
- name: Display git status (after test-update)
84-
run: git status
113+
- name: Download snapshot artifacts
114+
uses: actions/download-artifact@v8
115+
with:
116+
pattern: snapshots-*
117+
path: snapshot-artifacts
118+
119+
- name: Apply snapshot updates
120+
run: |
121+
for dir in snapshot-artifacts/snapshots-*/; do
122+
if [ -f "${dir}snapshots.tar" ]; then
123+
tar xf "${dir}snapshots.tar"
124+
fi
125+
done
126+
rm -rf snapshot-artifacts
85127
86128
- 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 --
129+
run: |
130+
# Stage updated/new snapshot files (skip gitignored paths)
131+
find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
132+
| git check-ignore --stdin --non-matching --verbose \
133+
| grep '^::' | cut -f2 \
134+
| xargs --no-run-if-empty git add --
135+
# Also stage deletions (e.g. snapshots for removed tests)
136+
git diff --name-only --diff-filter=D HEAD | grep -E '(__snapshots__|snapshots)/' | xargs --no-run-if-empty git add --
137+
138+
- name: Display git status after staging
139+
run: git status
88140

89141
- name: Commit and push changes
90142
uses: stefanzweifel/git-auto-commit-action@v7
91143
with:
92144
commit_message: Update all snapshots
145+
file_pattern: ''
93146
commit_user_name: '${{ steps.app-token.outputs.app-slug }}[bot]'
94147
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)