Repository navigation
184 lines (168 loc) · 6.5 KB
/
Copy pathtests.yml
File metadata and controls
184 lines (168 loc) · 6.5 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
name: Tests
# Runs the Jest suite on every PR and fails only on failures the PR
# introduces: develop still carries known failures (#3472), so the head and
# base are tested in parallel and compared. Once #3472 clears the baseline,
# this can gate on zero failures instead (#3479).
on:
# No paths filter: this backs a status check, and a filtered-out run
# never reports.
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: tests-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
scope:
name: Detect test scope
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
docs_only: ${{ steps.scope.outputs.docs_only }}
steps:
- name: Checkout changed files
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
- name: Detect documentation-only changes
id: scope
env:
EVENT_NAME: ${{ github.event_name }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
docs_only=false
if [ "$EVENT_NAME" = "pull_request" ]; then
changed_files="$RUNNER_TEMP/tests-changed-files"
git diff --name-only --no-renames -z "$BASE_SHA" HEAD > "$changed_files"
if [ -s "$changed_files" ]; then
docs_only=true
while IFS= read -r -d '' file; do
case "$file" in
docs/LABEL_STRATEGY.md | docs/LABELING.md)
docs_only=false
break
;;
docs/*.md) ;;
*)
docs_only=false
break
;;
esac
done < "$changed_files"
fi
fi
echo "docs_only=$docs_only" >> "$GITHUB_OUTPUT"
jest:
name: Jest (${{ matrix.target }})
needs: scope
if: needs.scope.outputs.docs_only != 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
target: [head, base]
exclude:
# No base to compare against outside a pull request.
- target: ${{ github.event_name != 'pull_request' && 'base' || 'none' }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 1
# head: the PR merge commit (default); base: the PR base commit.
ref: ${{ matrix.target == 'base' && github.event.pull_request.base.sha || '' }}
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts --prefer-offline --no-audit --no-fund
- name: Run Jest
env:
EVENT_NAME: ${{ github.event_name }}
run: |
# Failing tests are expected on develop; the compare job decides.
# A missing or invalid report fails closed there.
jest_status=0
npx jest --config .jest.config.cjs --ci --coverage=false \
--json --outputFile=jest-report.json || jest_status=$?
jq -r '"suites=\(.numTotalTestSuites) failed_suites=\(.numFailedTestSuites) tests=\(.numTotalTests) failed=\(.numFailedTests)"' \
jest-report.json 2>/dev/null || echo "::warning::No Jest report was written"
if [ "$EVENT_NAME" = "workflow_dispatch" ] \
&& { [ "$jest_status" -ne 0 ] || [ ! -s jest-report.json ]; }; then
exit 1
fi
- name: Check the suite left the working tree clean
run: |
# Tests must not write into the repository (#3482). Warning only
# until that is fixed.
dirty=$(git status --porcelain -- . ':!jest-report.json')
if [ -n "$dirty" ]; then
echo "::warning::Jest modified the working tree (#3482):"
printf '%s\n' "$dirty"
fi
- name: Upload report
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: jest-report-${{ matrix.target }}
path: jest-report.json
if-no-files-found: ignore
retention-days: 7
compare:
name: No new test failures
needs: [scope, jest]
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Report documentation-only skip
if: needs.scope.outputs.docs_only == 'true'
run: |
echo "Documentation-only pull request; Jest comparison skipped." >> "$GITHUB_STEP_SUMMARY"
- name: Checkout comparison script
if: needs.scope.outputs.docs_only != 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 1
sparse-checkout: scripts/validation
- name: Download reports
if: needs.scope.outputs.docs_only != 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: jest-report-*
path: reports
- name: Compare head with base
if: needs.scope.outputs.docs_only != 'true'
run: |
set -o pipefail
for target in head base; do
if ! jq -e '.testResults | type == "array"' "reports/jest-report-$target/jest-report.json" >/dev/null 2>&1; then
echo "::error::Missing or invalid Jest report for $target; failing closed."
exit 1
fi
done
# Both jobs check out to the same workspace path, so one root
# makes their test paths comparable. The default shell is
# bash -e: suspend errexit so a non-zero result still reaches the
# summary below.
set +e
node scripts/validation/compare-jest-failures.cjs \
--head reports/jest-report-head/jest-report.json --head-root "$GITHUB_WORKSPACE" \
--base reports/jest-report-base/jest-report.json --base-root "$GITHUB_WORKSPACE" \
| tee comparison.txt
status=${PIPESTATUS[0]}
set -e
{
echo "## Test comparison (head vs base)"
echo
echo '```'
cat comparison.txt
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
exit "$status"