-
Notifications
You must be signed in to change notification settings - Fork 45
154 lines (135 loc) · 5.74 KB
/
update-snapshots.yml
File metadata and controls
154 lines (135 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: 03 - Update Snapshots
on:
workflow_dispatch:
inputs:
delete_snapshots:
description: 'Delete existing snapshots before update?'
required: false
default: false
type: boolean
concurrency:
group: 'workflow-${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
jobs:
update:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: components
path: packages/components
type: unit
- name: hydrate-server
path: packages/tools/hydrate-server
type: unit
- name: hydrate
path: packages/adapters/hydrate
type: unit
- name: theme-default
path: packages/themes/default
type: e2e
- name: theme-kern
path: packages/themes/kern
type: e2e
steps:
- name: Checkout branch
uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }}
persist-credentials: false
- uses: ./.github/actions/pnpm-setup
- name: Install Playwright browsers
if: matrix.type == 'e2e'
run: npx playwright install --with-deps firefox
- name: Build
run: pnpm --filter @public-ui/sample-react^... build
- name: Purge existing snapshots
if: inputs.delete_snapshots == true
run: |
if [ "${{ matrix.type }}" = "e2e" ]; then
find ${{ matrix.path }} -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
else
find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
fi
- name: Run snapshot update
run: pnpm --filter @public-ui/${{ matrix.name }} test:update:${{ matrix.type }}
- name: Git status after generating snapshots
run: git status
- name: Package snapshot changes
run: |
if [ "${{ inputs.delete_snapshots }}" = "true" ]; then
# All snapshots were purged and regenerated from scratch – capture every file on disk,
# including those whose content is identical to HEAD (git diff would miss those).
find ${{ matrix.path }} \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
| tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
else
# Only capture files that actually changed (efficient for normal updates).
{
git diff --name-only --diff-filter=d HEAD -- ${{ matrix.path }}
git ls-files --others --exclude-standard -- ${{ matrix.path }}
} | grep -E '(__snapshots__|snapshots)/' | tar cf snapshots.tar -T - 2>/dev/null || tar cf snapshots.tar --files-from /dev/null
fi
- name: Upload snapshot artifacts
uses: actions/upload-artifact@v7
with:
name: snapshots-${{ matrix.name }}
path: snapshots.tar
if-no-files-found: ignore
retention-days: 1
push:
needs: update
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Checkout branch
uses: actions/checkout@v6
with:
ref: ${{ github.ref_name }}
token: ${{ steps.app-token.outputs.token }}
- name: Purge existing snapshots (optional)
if: inputs.delete_snapshots == true
run: |
find packages -name '*.png' -path '*/snapshots/*' | grep -v 'node_modules' | xargs --no-run-if-empty rm -f
find packages \( -path '*/node_modules' -prune \) -o -path '*/__snapshots__/*' -type f -print | xargs --no-run-if-empty rm -f
- name: Download snapshot artifacts
uses: actions/download-artifact@v8
with:
pattern: snapshots-*
path: snapshot-artifacts
- name: Apply snapshot updates
run: |
for dir in snapshot-artifacts/snapshots-*/; do
if [ -f "${dir}snapshots.tar" ]; then
tar xf "${dir}snapshots.tar"
fi
done
rm -rf snapshot-artifacts
- name: Stage snapshot changes
run: |
# Stage updated/new snapshot files (skip gitignored paths)
find packages \( -path '*/node_modules' -prune \) -o \( -path '*/__snapshots__/*' -o -path '*/snapshots/*' \) -type f -print \
| (git check-ignore --stdin --non-matching --verbose || test $? = 1) \
| { grep '^::' || true; } | cut -f2 \
| xargs --no-run-if-empty git add --
# Also stage deletions (e.g. snapshots for removed tests)
{ git diff --name-only --diff-filter=D HEAD || true; } | grep -E '(__snapshots__|snapshots)/' | xargs --no-run-if-empty git add --
- name: Git status after staging
run: git status
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Update all snapshots
# Disable internal git add so that only the files staged above are committed.
file_pattern: ''
commit_user_name: '${{ steps.app-token.outputs.app-slug }}[bot]'
commit_user_email: '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com'