-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
376 lines (337 loc) · 18.1 KB
/
get-requirements.yml
File metadata and controls
376 lines (337 loc) · 18.1 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
371
372
373
374
375
376
# Centralised "should this job run?" workflow.
name: Get workflow and job requirements
on:
workflow_call:
outputs:
skip_everything:
description: 'Whether all jobs should be skipped in merge-queue (branch is already up-to-date with latest commit)'
value: ${{ jobs.detect-changes.outputs.skip_everything }}
skip_e2e:
description: 'Whether all E2E builds and tests should be skipped. True for any skip signal (labels or commit tag). Check block_merge_for_e2e_readiness separately to know if merge is also blocked'
value: ${{ jobs.detect-changes.outputs.skip_e2e }}
android_e2e_needed:
description: 'Whether Android E2E tests and builds should run (true when Android-specific or shared files changed)'
value: ${{ jobs.detect-changes.outputs.android_e2e_needed }}
ios_e2e_needed:
description: 'Whether iOS E2E tests and builds should run (true when iOS-specific or shared files changed)'
value: ${{ jobs.detect-changes.outputs.ios_e2e_needed }}
changed_files:
description: 'Space-separated list of changed file paths. Smoke test workflows use this to run modified spec files twice for flakiness detection (catches flaky tests before they land on main)'
value: ${{ jobs.detect-changes.outputs.changed_files }}
block_merge_for_e2e_readiness:
description: 'Whether merge should be blocked for E2E readiness. True when "pr-not-ready-for-e2e" label is applied AND changes are not ignorable-only (i.e. E2E is actually relevant). Ignorable-only PRs (docs, assets, configs, test files) bypass the block automatically.'
value: ${{ jobs.detect-changes.outputs.block_merge_for_e2e_readiness }}
run_smart_e2e_selection:
description: 'Whether the smart-e2e-selection job should run. False for non-PR events, forks, or hard E2E skips.'
value: ${{ jobs.detect-changes.outputs.run_smart_e2e_selection }}
locales_only:
description: 'Whether every changed file is a locale translation JSON file under locales/languages.'
value: ${{ jobs.detect-changes.outputs.locales_only }}
locales_validation_needed:
description: 'Whether the future minimal locale validation job should run for locale translation JSON-only changes.'
value: ${{ jobs.detect-changes.outputs.locales_validation_needed }}
standard_ci_needed:
description: 'Whether standard CI is required by the changed-file classification. Shadow-only until enforcement is enabled.'
value: ${{ jobs.detect-changes.outputs.standard_ci_needed }}
requirements_enforced:
description: 'Whether standard-CI/locales requirements enforcement is enabled for this event and target branch.'
value: ${{ jobs.detect-changes.outputs.requirements_enforced }}
jobs:
detect-changes:
name: Filter files changed and decide which jobs to run
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
skip_everything: ${{ steps.skip-merge-queue.outputs.up-to-date == 'true' && 'true' || 'false' }}
skip_e2e: ${{ steps.set-outputs.outputs.e2e_needed != 'true' && 'true' || 'false' }}
android_e2e_needed: ${{ steps.set-outputs.outputs.android_final }}
ios_e2e_needed: ${{ steps.set-outputs.outputs.ios_final }}
changed_files: ${{ steps.set-outputs.outputs.changed_files }}
block_merge_for_e2e_readiness: ${{ steps.set-outputs.outputs.block_merge }}
run_smart_e2e_selection: ${{ steps.set-outputs.outputs.run_smart_e2e_selection }}
locales_only: ${{ steps.set-standard-outputs.outputs.locales_only || 'false' }}
locales_validation_needed: ${{ steps.set-standard-outputs.outputs.locales_validation_needed || 'false' }}
standard_ci_needed: ${{ steps.skip-merge-queue.outputs.up-to-date == 'true' && 'false' || steps.set-standard-outputs.outputs.standard_ci_needed || 'true' }}
requirements_enforced: ${{ steps.set-standard-outputs.outputs.requirements_enforced || 'false' }}
env:
# For a `pull_request` event, the head commit hash is `github.event.pull_request.head.sha`.
# For a `push` event, the head commit hash is `github.sha`.
HEAD_COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
steps:
- name: Check pull request merge queue status
id: skip-merge-queue
if: github.event_name == 'merge_group'
uses: MetaMask/github-tools/.github/actions/check-skip-merge-queue@v1
- name: Checkout repository
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Fetch HEAD commit for message checks
if: ${{ steps.skip-merge-queue.outputs.up-to-date != 'true' }}
run: git fetch --depth=1 origin "${HEAD_COMMIT_HASH}"
- name: Check skip E2E commit tag
id: skip-e2e-tag
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
echo "SKIP=false" >> "$GITHUB_OUTPUT"
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]] || [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then
if git show --format='%B' --no-patch "${HEAD_COMMIT_HASH}" | grep --fixed-strings --quiet '[skip-e2e]'; then
echo "SKIP=true" >> "$GITHUB_OUTPUT"
echo "-> SKIP=true due to [skip-e2e] tag in last commit message"
fi
fi
- name: Check PR labels
id: check-labels
if: steps.skip-merge-queue.outputs.up-to-date != 'true' && github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
{
echo "SKIP_E2E=false"
echo "LABEL_BLOCKS_MERGE=false"
echo "SKIP_SMART_SELECTION=false"
} >> "$GITHUB_OUTPUT"
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
if echo "$LABELS" | grep -qx "skip-e2e"; then
echo "SKIP_E2E=true" >> "$GITHUB_OUTPUT"
echo "-> SKIP_E2E=true due to 'skip-e2e' label on PR"
fi
if echo "$LABELS" | grep -qx "pr-not-ready-for-e2e"; then
{
echo "SKIP_E2E=true"
echo "LABEL_BLOCKS_MERGE=true"
} >> "$GITHUB_OUTPUT"
echo "-> SKIP_E2E=true and LABEL_BLOCKS_MERGE=true due to 'pr-not-ready-for-e2e' label on PR"
fi
if echo "$LABELS" | grep -qx "skip-smart-e2e-selection"; then
echo "SKIP_SMART_SELECTION=true" >> "$GITHUB_OUTPUT"
echo "-> SKIP_SMART_SELECTION=true due to 'skip-smart-e2e-selection' label on PR"
fi
- name: Filter changed files
id: filter
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
uses: dorny/paths-filter@9d7afb8d214ad99e78fbd4247752c4caed2b6e4c # v4.0.0
with:
filters: .github/rules/filter-rules.yml
list-files: shell
- name: Compute E2E flags
id: set-outputs
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
SHOULD_SKIP_E2E: ${{ steps.skip-e2e-tag.outputs.SKIP == 'true' || steps.check-labels.outputs.SKIP_E2E == 'true' }}
LABEL_BLOCKS_MERGE: ${{ steps.check-labels.outputs.LABEL_BLOCKS_MERGE }}
ALL_CHANGES_COUNT: ${{ steps.filter.outputs.all_changes_count }}
ALL_CHANGES_FILES: ${{ github.event_name == 'pull_request' && steps.filter.outputs.all_changes_files || '' }}
IGNORABLE_COUNT: ${{ steps.filter.outputs.e2e_ignorable_count }}
E2E_WORKFLOWS_COUNT: ${{ steps.filter.outputs.e2e_relevant_workflows_count }}
ANDROID_COUNT: ${{ steps.filter.outputs.android_count }}
IOS_COUNT: ${{ steps.filter.outputs.ios_count }}
ANDROID_OR_IGNORABLE_COUNT: ${{ steps.filter.outputs.android_or_ignorable_count }}
IOS_OR_IGNORABLE_COUNT: ${{ steps.filter.outputs.ios_or_ignorable_count }}
run: |
set -euo pipefail
ANDROID=false
IOS=false
CHANGED=""
MSG=""
# Compute ignorable-only signal up-front so it's available for the merge-block
# bypass below regardless of which platform-decision branch fires.
# The label-driven SHOULD_SKIP_E2E branch would otherwise short-circuit and leave
# this flag unset for the very PRs that should bypass the merge block.
IGNORABLE_ONLY=false
if [[ "$ALL_CHANGES_COUNT" -gt 0 &&
"$IGNORABLE_COUNT" -eq "$ALL_CHANGES_COUNT" &&
"$E2E_WORKFLOWS_COUNT" -eq 0 ]]; then
IGNORABLE_ONLY=true
fi
# Scheduled runs and push to main always test both platforms
if [[ "$GITHUB_EVENT_NAME" == "schedule" || "$GITHUB_EVENT_NAME" == "push" ]]; then
MSG="E2E for both platforms (scheduled or push to main)"
ANDROID=true; IOS=true
# Merge queue: E2E builds and tests never run
elif [[ "$GITHUB_EVENT_NAME" == "merge_group" ]]; then
MSG="Skipping E2E (merge queue)"
# Fork PRs should not run E2E
elif [[ "$IS_FORK" == "true" ]]; then
MSG="Skipping E2E (fork PR)"
# Hard skip signals (label / commit tag) ALWAYS win for PRs
elif [[ "$SHOULD_SKIP_E2E" == "true" ]]; then
MSG="Skipping E2E (skip signal)"
# All changed files are ignorable AND no E2E-relevant workflow touched
elif [[ "$IGNORABLE_ONLY" == "true" ]]; then
MSG="Skipping E2E (ignorable-only changes)"
# Android-only: all changed files are android/** or ignorable, no iOS, no E2E workflows
elif [[ "$ANDROID_COUNT" -gt 0 &&
"$IOS_COUNT" -eq 0 &&
"$E2E_WORKFLOWS_COUNT" -eq 0 &&
"$ANDROID_OR_IGNORABLE_COUNT" -ge "$ALL_CHANGES_COUNT" ]]; then
MSG="E2E Android only"
ANDROID=true
CHANGED="$ALL_CHANGES_FILES"
# iOS-only: all changed files are ios/** or ignorable, no Android, no E2E workflows
elif [[ "$IOS_COUNT" -gt 0 &&
"$ANDROID_COUNT" -eq 0 &&
"$E2E_WORKFLOWS_COUNT" -eq 0 &&
"$IOS_OR_IGNORABLE_COUNT" -ge "$ALL_CHANGES_COUNT" ]]; then
MSG="E2E iOS only"
IOS=true
CHANGED="$ALL_CHANGES_FILES"
# Conservative default
else
MSG="E2E for both platforms"
ANDROID=true; IOS=true
CHANGED="$ALL_CHANGES_FILES"
fi
E2E_NEEDED=false
[[ "$ANDROID" == "true" || "$IOS" == "true" ]] && E2E_NEEDED=true
# Run smart-e2e-selection for non-fork, non-hard-skip PRs with no skip-smart-e2e-selection label.
# Non-PR events and all skip signals bypass AI selection.
RUN_SMART=false
if [[ "$GITHUB_EVENT_NAME" == "pull_request" && \
"$E2E_NEEDED" == "true" && \
"$IS_FORK" != "true" && \
"$SHOULD_SKIP_E2E" != "true" ]]; then
RUN_SMART=true
fi
# Compute final merge-block signal.
# The label blocks merge in general, but is bypassed for ignorable-only PRs:
# E2E doesn't run on those, so requiring the label to be removed adds friction with no benefit.
BLOCK_MERGE=false
if [[ "$LABEL_BLOCKS_MERGE" == "true" && "$IGNORABLE_ONLY" != "true" ]]; then
BLOCK_MERGE=true
elif [[ "$LABEL_BLOCKS_MERGE" == "true" && "$IGNORABLE_ONLY" == "true" ]]; then
echo "-> BLOCK_MERGE bypassed — ignorable-only changes, E2E_WORKFLOWS_COUNT=0"
fi
echo "$MSG"
{
echo "android_final=$ANDROID"
echo "ios_final=$IOS"
echo "e2e_needed=$E2E_NEEDED"
echo "run_smart_e2e_selection=$RUN_SMART"
echo "block_merge=$BLOCK_MERGE"
} >> "$GITHUB_OUTPUT"
{
echo "changed_files<<GH_EOF"
printf '%s\n' "$CHANGED"
echo "GH_EOF"
} >> "$GITHUB_OUTPUT"
- name: Compute standard CI shadow flags
id: set-standard-outputs
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
MERGE_GROUP_BASE_REF: ${{ github.event.merge_group.base_ref }}
REQUIREMENTS_ENFORCED_CONFIG: ${{ vars.MOBILE_CI_REQUIREMENTS_ENFORCED == 'true' && 'true' || 'false' }}
ALL_CHANGES_COUNT: ${{ steps.filter.outputs.all_changes_count }}
LOCALE_TRANSLATION_COUNT: ${{ steps.filter.outputs.locale_translation_files_count }}
run: |
set -euo pipefail
all_changes_count="${ALL_CHANGES_COUNT:-0}"
locale_translation_count="${LOCALE_TRANSLATION_COUNT:-0}"
target_allows_enforcement=false
if [[ "$GITHUB_EVENT_NAME" == "pull_request" && "$PR_BASE_REF" == "main" ]]; then
target_allows_enforcement=true
elif [[ "$GITHUB_EVENT_NAME" == "merge_group" && "$MERGE_GROUP_BASE_REF" == "refs/heads/main" ]]; then
target_allows_enforcement=true
fi
requirements_enforced=false
if [[ "$REQUIREMENTS_ENFORCED_CONFIG" == "true" && "$target_allows_enforcement" == "true" ]]; then
requirements_enforced=true
fi
locales_only=false
locales_validation_needed=false
standard_ci_needed=true
decision_reason="Standard CI remains required because the change set is not locale translation JSON-only."
if [[ "$all_changes_count" -gt 0 && "$locale_translation_count" -eq "$all_changes_count" ]]; then
locales_only=true
locales_validation_needed=true
standard_ci_needed=false
decision_reason="Only locale translation JSON files changed."
elif [[ "$all_changes_count" -eq 0 ]]; then
decision_reason="No changed files were reported; keep the conservative standard CI path."
fi
{
echo "locales_only=$locales_only"
echo "locales_validation_needed=$locales_validation_needed"
echo "standard_ci_needed=$standard_ci_needed"
echo "requirements_enforced=$requirements_enforced"
echo "target_allows_enforcement=$target_allows_enforcement"
echo "decision_reason=$decision_reason"
} >> "$GITHUB_OUTPUT"
- name: Summarize CI requirements decisions
if: steps.skip-merge-queue.outputs.up-to-date != 'true'
env:
ALL_CHANGES_COUNT: ${{ steps.filter.outputs.all_changes_count }}
LOCALE_TRANSLATION_COUNT: ${{ steps.filter.outputs.locale_translation_files_count }}
LOCALES_ONLY: ${{ steps.set-standard-outputs.outputs.locales_only }}
LOCALES_VALIDATION_NEEDED: ${{ steps.set-standard-outputs.outputs.locales_validation_needed }}
STANDARD_CI_NEEDED: ${{ steps.set-standard-outputs.outputs.standard_ci_needed }}
REQUIREMENTS_ENFORCED: ${{ steps.set-standard-outputs.outputs.requirements_enforced }}
TARGET_ALLOWS_ENFORCEMENT: ${{ steps.set-standard-outputs.outputs.target_allows_enforcement }}
DECISION_REASON: ${{ steps.set-standard-outputs.outputs.decision_reason }}
SKIP_E2E: ${{ steps.set-outputs.outputs.e2e_needed != 'true' && 'true' || 'false' }}
ANDROID_E2E_NEEDED: ${{ steps.set-outputs.outputs.android_final }}
IOS_E2E_NEEDED: ${{ steps.set-outputs.outputs.ios_final }}
RUN_SMART_E2E_SELECTION: ${{ steps.set-outputs.outputs.run_smart_e2e_selection }}
BLOCK_MERGE_FOR_E2E_READINESS: ${{ steps.set-outputs.outputs.block_merge }}
run: |
set -euo pipefail
if [[ -z "${GITHUB_STEP_SUMMARY:-}" ]]; then
exit 0
fi
standard_decision="run"
if [[ "$STANDARD_CI_NEEDED" == "false" ]]; then
standard_decision="would skip if enforcement is enabled"
fi
{
echo "### CI requirements shadow summary"
echo
echo "Standard CI jobs still run in this PR. These outputs are for validation before enforcement."
echo
echo "| Signal | Value |"
echo "|---|---|"
echo "| All changed files | ${ALL_CHANGES_COUNT:-0} |"
echo "| Locale translation JSON files | ${LOCALE_TRANSLATION_COUNT:-0} |"
echo "| locales_only | ${LOCALES_ONLY:-false} |"
echo "| locales_validation_needed | ${LOCALES_VALIDATION_NEEDED:-false} |"
echo "| standard_ci_needed | ${STANDARD_CI_NEEDED:-true} |"
echo "| requirements_enforced | ${REQUIREMENTS_ENFORCED:-false} |"
echo "| target_allows_enforcement | ${TARGET_ALLOWS_ENFORCEMENT:-false} |"
echo "| reason | ${DECISION_REASON:-n/a} |"
echo
echo "| E2E signal | Value |"
echo "|---|---|"
echo "| skip_e2e | ${SKIP_E2E:-false} |"
echo "| android_e2e_needed | ${ANDROID_E2E_NEEDED:-false} |"
echo "| ios_e2e_needed | ${IOS_E2E_NEEDED:-false} |"
echo "| run_smart_e2e_selection | ${RUN_SMART_E2E_SELECTION:-false} |"
echo "| block_merge_for_e2e_readiness | ${BLOCK_MERGE_FOR_E2E_READINESS:-false} |"
echo
echo "### Planned standard-CI enforcement mapping"
echo
echo "| Job | Shadow decision |"
echo "|---|---|"
for job in \
check-diff \
dedupe \
git-safe-dependencies \
scripts \
js-bundle-size-check \
unit-tests \
component-view-tests \
merge-unit-and-component-view-tests \
check-workflows \
sonar-cloud \
sonar-cloud-quality-gate-status
do
echo "| \`$job\` | $standard_decision |"
done
} >> "$GITHUB_STEP_SUMMARY"