-
Notifications
You must be signed in to change notification settings - Fork 57
214 lines (182 loc) · 8.5 KB
/
snapshotUpdate.yml
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Update Snapshots
on:
# allow for manual triggers
workflow_dispatch: {}
pull_request:
types: [labeled]
jobs:
getMatrix:
name: Get Matrix
if: github.event.label.name == 'snapshots' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
testPathPatterns: ${{ steps.setTestPathPatterns.outputs.testPathPatterns }}
testConfigs: ${{ steps.setTestConfigs.outputs.testConfigs }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
persist-credentials: false
- id: setTestPathPatterns
run: |
echo "testPathPatterns=$(./.github/scripts/getTestPathPatterns.sh)" >> $GITHUB_OUTPUT
- id: setTestConfigs
name: Set test config environment variables
run: |
echo "testConfigs=$(./.github/scripts/getTestConfigs.sh)" >> $GITHUB_OUTPUT
captureMetadata:
name: Capture Metadata
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: getMatrix
steps:
- name: Capture PR Number
run: |
mkdir -p ./workflow/metadata
echo ${{ github.event.number }} > ./workflow/metadata/pull_number.txt
- name: Save Metadata
uses: actions/upload-artifact@v4
with:
name: metadata
path: workflow/metadata/
updateSnapshots:
name: Update
runs-on: ubuntu-latest
needs: getMatrix
strategy:
matrix:
testPathPattern: ${{ fromJSON(needs.getMatrix.outputs.testPathPatterns) }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false
- name: Run server
run: |
./.github/scripts/runServer.sh
- name: Update Snapshots - ${{ matrix.testPathPattern }}
run: |
npm run test:func:ciupdate -- --testPathPattern "${{ matrix.testPathPattern }}"
git status --porcelain
- name: Format Artifact Inputs
id: artifactInputs
run: |
if [ -z "$(git status --porcelain)" ]
then
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
ARTIFACT_NAME="snapshot-$(sed 's/\//-/g' <<< '${{ matrix.testPathPattern }}')"
echo "name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
ARTIFACT_PATH="snapshots/"
echo "filePath=$ARTIFACT_PATH" >> $GITHUB_OUTPUT
UPDATED_SNAPSHOTS=$(git status --porcelain | grep 'snapshots' | sed -E "s/^.{3}//")
echo "$UPDATED_SNAPSHOTS" | while read -r filePath
do
newPath=$(echo $filePath | sed -E "s/^.+(snapshots.+)$/\\1/")
newDir=$(echo $newPath | sed -E "s/^(.+\/)[^\/]+$/\\1/")
echo "filePath=$filePath"
echo "newPath=$newPath"
echo "newDir=$newDir"
echo "mkdir ${{ github.workspace }}/$newDir"
mkdir -p "${{ github.workspace }}/$newDir"
if [ -d "${{ github.workspace }}/$filePath" ]; then
# If filePath is a directory we want to move all of its contents
# into the new directory location to prevent duplicate directory nesting
echo "moving directory"
echo "mv ${{ github.workspace }}/$filePath* ${{ github.workspace }}/$newDir"
mv "${{ github.workspace }}/$filePath"* "${{ github.workspace }}/$newDir"
else
echo "moving file"
echo "mv ${{ github.workspace }}/$filePath ${{ github.workspace }}/$newPath"
mv "${{ github.workspace }}/$filePath" "${{ github.workspace }}/$newPath"
fi
done
- name: Save Snapshot Artifact
if: steps.artifactInputs.outputs.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifactInputs.outputs.name }}
path: ${{ steps.artifactInputs.outputs.filePath }}
retention-days: 1
updateSnapshotsV2:
name: Update V2
runs-on: ubuntu-latest
needs: getMatrix
strategy:
matrix:
testConfig: ${{ fromJSON(needs.getMatrix.outputs.testConfigs) }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false
- name: Run server
run: |
./.github/scripts/runServerV2.sh
- name: Update Snapshots - ${{ matrix.testConfig }}
run: |
CONFIG_PATH=${{ matrix.testConfig }} npm run test:func:snapshots:ciupdate
git status --porcelain
- name: Format Artifact Inputs
id: artifactInputs
run: |
if [ -z "$(git status --porcelain)" ]
then
echo "skip=true" >> $GITHUB_OUTPUT
exit 0
fi
ARTIFACT_NAME="snapshot-v2-$(sed 's/\//-/g' <<< '${{ matrix.testConfig }}')"
echo "name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
ARTIFACT_PATH="snapshotsV2/"
echo "filePath=$ARTIFACT_PATH" >> $GITHUB_OUTPUT
# even though we're not committing files here, this forces git to list full file paths, not folders
git add .
# porcelain flag makes "git status" easy to interpret for scripts. grep searches for snapshot files
# sed removes the initial 3 characters of "git status", which show the state of the file
UPDATED_SNAPSHOTS=$(git status --porcelain | grep 'v2/snapshots' | sed -E "s/^.{3}//")
echo "$UPDATED_SNAPSHOTS" | while read -r filePath
do
newPath=$(echo $filePath | sed -E "s/^.+(snapshots.+)$/\\1/")
newDir=$(echo $newPath | sed -E "s/^(.+\/)[^\/]+$/\\1/")
echo "filePath=$filePath"
echo "newPath=$newPath"
echo "newDir=$newDir"
echo "mkdir ${{ github.workspace }}/$newDir"
mkdir -p "${{ github.workspace }}/$newDir"
if [ -d "${{ github.workspace }}/$filePath" ]; then
# If filePath is a directory we want to move all of its contents
# into the new directory location to prevent duplicate directory nesting
echo "moving directory"
echo "mv ${{ github.workspace }}/$filePath* ${{ github.workspace }}/$newDir"
mv "${{ github.workspace }}/$filePath"* "${{ github.workspace }}/$newDir"
else
echo "moving file"
echo "mv ${{ github.workspace }}/$filePath" "${{ github.workspace }}/$newPath"
mv "${{ github.workspace }}/$filePath" "${{ github.workspace }}/$newPath"
fi
done
mv "${{ github.workspace }}/snapshots" "${{ github.workspace }}/snapshotsV2"
- name: Save Snapshot Artifact
if: steps.artifactInputs.outputs.skip != 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifactInputs.outputs.name }}
path: ${{ steps.artifactInputs.outputs.filePath }}
retention-days: 1