-
-
Notifications
You must be signed in to change notification settings - Fork 42
370 lines (351 loc) · 15.4 KB
/
pr.yml
File metadata and controls
370 lines (351 loc) · 15.4 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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
name: Uploady Build
on:
workflow_dispatch:
pull_request:
# `labeled`/`unlabeled` let us trigger an e2e re-run by toggling the
# "rune2e" label on a PR. Using `pull_request` (NOT `pull_request_target`)
# keeps untrusted PR code out of the default branch's privileged context,
# avoiding the cache-poisoning / TOCTOU issues that CodeQL flags for
# `issue_comment` + `pull_request_target` workflows.
types:
- opened
- synchronize
- reopened
- ready_for_review
- labeled
- unlabeled
push:
branches:
- master
defaults:
run:
shell: bash
permissions:
contents: read
pull-requests: read
actions: read
checks: read
env:
RUNE2E_LABEL: rune2e
jobs:
workflow-gate:
runs-on: ubuntu-latest
outputs:
# Whether the build pipeline should run at all. We ignore `unlabeled`
# events entirely (nothing to do when a label is removed) and ignore
# `labeled` events for labels other than the e2e re-run label
# (to avoid wasteful re-runs on unrelated labels).
proceed: ${{ steps.gate.outputs.proceed }}
# Whether this run was triggered specifically by adding the e2e
# re-run label (used to skip redundant build jobs on label-only runs).
rune2e_label_added: ${{ steps.gate.outputs.rune2e_label_added }}
# Whether this is a label-only event (i.e. nothing actually changed
# on the PR code-wise). Used to skip non-e2e jobs that already ran
# for the same SHA on the original opened/synchronize event.
is_label_event: ${{ steps.gate.outputs.is_label_event }}
# Current PR carries the rune2e label (any pull_request event). When
# true, prep-e2e and e2e always run, even if watched paths did not change.
has_rune2e_label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, env.RUNE2E_LABEL) }}
steps:
- name: Evaluate gate
id: gate
env:
EVENT_NAME: ${{ github.event_name }}
PR_ACTION: ${{ github.event.action }}
LABEL_NAME: ${{ github.event.label.name }}
run: |
proceed=true
rune2e_label_added=false
is_label_event=false
if [ "$EVENT_NAME" = "pull_request" ]; then
case "$PR_ACTION" in
unlabeled)
proceed=false
;;
labeled)
is_label_event=true
if [ "$LABEL_NAME" = "$RUNE2E_LABEL" ]; then
rune2e_label_added=true
else
# Some other label was added - nothing to do.
proceed=false
fi
;;
esac
fi
{
echo "proceed=$proceed"
echo "rune2e_label_added=$rune2e_label_added"
echo "is_label_event=$is_label_event"
} >> "$GITHUB_OUTPUT"
code-changes:
runs-on: ubuntu-latest
needs:
- workflow-gate
if: needs.workflow-gate.outputs.proceed == 'true'
outputs:
IS_CODE_CHANGED: ${{ steps.check-changes.outputs.code_changed }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 2
- name: Check for code changes
id: check-changes
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "code_changed=true" >> $GITHUB_OUTPUT
exit 0
fi
if [ "${{ github.event_name }}" == "pull_request" ]; then
git fetch origin ${{ github.base_ref }} --depth=1
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
else
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
fi
echo "Changed files:"
echo "$CHANGED_FILES"
if echo "$CHANGED_FILES" | grep -q -E '^packages/|^cypress/|^package.json$|^story-helpers/'; then
echo "Code changes detected in watched paths"
echo "code_changed=true" >> $GITHUB_OUTPUT
else
echo "No code changes in watched paths"
echo "code_changed=false" >> $GITHUB_OUTPUT
fi
prep-e2e:
runs-on: ubuntu-latest
needs:
- workflow-gate
- code-changes
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && (needs.code-changes.outputs.IS_CODE_CHANGED == 'true' || needs.workflow-gate.outputs.has_rune2e_label == 'true') }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: Install dependencies
uses: cypress-io/github-action@dace029018fcdf86e0df89a31bc3cfa5b32570d8 # v7.3
with:
runTests: false
build:
name: Build Library
runs-on: ubuntu-latest
needs:
- workflow-gate
# Skip on label-only events: the same SHA already built on the
# opened/synchronize event, no need to rebuild just because a label
# was toggled.
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && needs.workflow-gate.outputs.is_label_event != 'true' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: Build
run: pnpm build
bundle:
name: Create code bundles
runs-on: ubuntu-latest
needs:
- workflow-gate
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && needs.workflow-gate.outputs.is_label_event != 'true' }}
permissions:
pull-requests: write
contents: write
actions: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: Bundle for Production
run: |
pnpm bundle:prod
- name: Cache Bundle Folder
id: cache-bundle
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: bundle
key: bundle-${{ runner.os }}-${{ hashFiles('bundle/**') }}
- name: Bundle Size Check (Overweight)
uses: yoavniran/overweight@ee294a046ad2637d648b7b9c67e34928c93c7806 # v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
update-baseline: true
report-file: overweight-report.json
baseline-protected-branches: "master"
comment-on-pr-each-run: true
sb:
name: Build Storybook
runs-on: ubuntu-latest
needs:
- workflow-gate
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && needs.workflow-gate.outputs.is_label_event != 'true' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: build storybook
run: pnpm sb:build:internal
- name: Cache SB Build
id: cache-sb
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: .sb-static
key: sb-static-${{ hashFiles('lerna.json') }}-${{ github.run_id }}
lft:
name: Lint, Flow, Types
runs-on: ubuntu-latest
needs:
- workflow-gate
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && needs.workflow-gate.outputs.is_label_event != 'true' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: lft
run: pnpm test:ci
unit-test:
name: Unit-Test (Vitest)
runs-on: ubuntu-latest
needs:
- workflow-gate
if: ${{ needs.workflow-gate.outputs.proceed == 'true' && needs.workflow-gate.outputs.is_label_event != 'true' }}
environment: "Rpldy-Build"
permissions:
contents: read
pull-requests: write
checks: write
actions: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: unit-test
run: pnpm vitest:ci
- name: Show Report Coverage
uses: davelosert/vitest-coverage-report-action@02f3c2e641286b7fa308cd3e430783103ce6103b # v2
- name: Test Report
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3
if: success() || failure()
with:
name: Unit-test Report
path: reports/junit/js-*.xml
reporter: jest-junit
badge-title: 'unit tests'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Coverage (master only)
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
if: ${{ github.ref_name == 'master' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/coverage-final.json
fail_ci_if_error: true
verbose: true
e2e:
runs-on: ubuntu-latest
# DAG: gate → path check → bundle/sb (artifacts) and prep-e2e (deps); e2e
# restores bundle/sb caches and reuses prep-e2e’s install.
needs:
- workflow-gate
- code-changes
- bundle
- sb
- prep-e2e
# On a `labeled` event the bundle/sb jobs are skipped (already built on
# the original opened/synchronize event); skipped status satisfies
# `needs` since we don't require success() here.
if: ${{ always() && needs.workflow-gate.outputs.proceed == 'true' && (needs.code-changes.outputs.IS_CODE_CHANGED == 'true' || needs.workflow-gate.outputs.has_rune2e_label == 'true') && needs.prep-e2e.result == 'success' && (needs.bundle.result == 'success' || needs.bundle.result == 'skipped') && (needs.sb.result == 'success' || needs.sb.result == 'skipped') }}
permissions:
contents: write
checks: write
actions: write
pull-requests: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && 1 || 0 }}
- name: Prepare
uses: ./.github/actions/prepare
with:
with-cypress: true
with-frozen: true
- name: Restore SB Build Cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: .sb-static
key: sb-static-${{ hashFiles('lerna.json') }}-${{ github.run_id }}
restore-keys: sb-static-${{ hashFiles('lerna.json') }}-
- name: Restore Bundle Cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: bundle
key: bundle-${{ runner.os }}-
restore-keys: bundle-${{ runner.os }}-
- name: Cypress run
id: cypress-e2e
uses: cypress-io/github-action@dace029018fcdf86e0df89a31bc3cfa5b32570d8 # v7.3
with:
install: false
start: |
pnpm sb:serve
pnpm bundle:serve
wait-on: 'http://127.0.0.1:8001, http://127.0.0.1:8009'
command: pnpm cy:parallel:gh
- name: Check for GIT Changes (Weights File)
id: check-weights-changes
if: ${{ github.event_name == 'pull_request' && steps.cypress-e2e.outcome == 'success' }}
run: |
if [[ `git status --porcelain` ]]; then
echo "found changes to weights file!"
echo "WEIGHTS_HAS_CHANGES=true" >> $GITHUB_OUTPUT
else
echo "NO changes to weights file!"
fi
- name: Commit Weights File (only if there was a change)
if: ${{ steps.check-weights-changes.outputs.WEIGHTS_HAS_CHANGES == 'true' }}
run: |
git config user.email "ci@react-uploady.org"
git config user.name "Uploady CI"
git status
git add cypress/e2e-weights.json
git commit -m "chore: update e2e weights file"
git push
- name: Store screenshots
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore
- name: E2E Report
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3
if: success() || failure()
with:
name: E2E Report
path: cypress/results/results-*.xml
reporter: java-junit
badge-title: 'E2E tests'