-
Notifications
You must be signed in to change notification settings - Fork 2k
381 lines (351 loc) · 14.2 KB
/
test.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
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
377
378
379
380
381
name: 🧪 test
on:
push:
paths-ignore:
- "**.md"
branches:
- long_lived/**
- main
- release/**
tags:
- "**"
pull_request:
paths-ignore:
- "**.md"
branches:
- "**"
workflow_dispatch:
inputs:
build-job-matrix-arguments:
description: "extra arguments for build-job-matrix.py"
default: ""
required: false
type: string
per:
description: "individual job scope"
default: "directory"
required: false
type: choice
options:
- directory
- file
only:
description: "only run this job"
default: ""
required: false
type: string
duplicates:
description: "times to run each job"
default: 1
required: false
type: number
run-linux:
description: "run Linux tests"
default: true
required: false
type: boolean
run-macos-intel:
description: "run macOS-intel tests"
default: true
required: false
type: boolean
run-macos-arm:
description: "run macOS-arm tests"
default: true
required: false
type: boolean
run-windows:
description: "run Windows tests"
default: true
required: false
type: boolean
full-python-matrix:
description: "run full Python version matrix"
default: false
required: false
type: boolean
schedule:
- cron: "0 13 * * *"
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'workflow_dispatch' && github.run_id || '' }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
cancel-in-progress: true
jobs:
configure:
name: Configure matrix
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python environment
uses: Chia-Network/actions/setup-python@main
with:
python-version: "3.10"
- name: Generate matrix configuration
id: configure
run: |
python chia/_tests/build-job-matrix.py --per directory --verbose ${{ inputs.only && format('--only {0}', inputs.only) || '' }} ${{ inputs.duplicates > 1 && format('--duplicates {0}', inputs.duplicates) || '' }} ${{ inputs.build-job-matrix-arguments }} > matrix.json
cat matrix.json
echo configuration=$(cat matrix.json) >> "$GITHUB_OUTPUT"
echo matrix_mode=${{
( github.repository_owner == 'Chia-Network' && github.repository != 'Chia-Network/chia-blockchain' )
&& 'limited'
|| (
( github.event_name == 'schedule' || inputs.full-python-matrix )
|| ( github.repository_owner == 'Chia-Network' && github.repository == 'Chia-Network/chia-blockchain' && startsWith(github.ref, 'refs/heads/release/') )
|| ( github.repository_owner == 'Chia-Network' && github.repository == 'Chia-Network/chia-blockchain' && startsWith(github.base_ref, 'release/') )
)
&& 'all'
|| 'main'
}} >> "$GITHUB_OUTPUT"
outputs:
configuration: ${{ steps.configure.outputs.configuration }}
matrix_mode: ${{ steps.configure.outputs.matrix_mode }}
macos-intel:
if: github.event_name != 'workflow_dispatch' || inputs.run-macos-intel
uses: ./.github/workflows/test-single.yml
needs: configure
with:
emoji: 🍎
matrix: macos-intel
name: macOS Intel
file_name: macos
concurrency_name: macos-intel
configuration: ${{ needs.configure.outputs.configuration }}
matrix_mode: ${{ needs.configure.outputs.matrix_mode }}
runs-on: macos-12
arch: intel
macos-arm:
if: github.event_name != 'workflow_dispatch' || inputs.run-macos-arm
uses: ./.github/workflows/test-single.yml
needs: configure
with:
emoji: 🍎
matrix: macos
name: macOS ARM
file_name: macos-arm
concurrency_name: macos-arm
configuration: ${{ needs.configure.outputs.configuration }}
matrix_mode: ${{ needs.configure.outputs.matrix_mode }}
runs-on: macos-14
arch: arm
collect-junit: false
ubuntu:
if: github.event_name != 'workflow_dispatch' || inputs.run-linux
uses: ./.github/workflows/test-single.yml
needs: configure
with:
emoji: 🐧
matrix: ubuntu
name: Ubuntu
file_name: ubuntu
concurrency_name: ubuntu
configuration: ${{ needs.configure.outputs.configuration }}
matrix_mode: ${{ needs.configure.outputs.matrix_mode }}
runs-on: ubuntu-latest
arch: intel
collect-junit: false
windows:
if: github.event_name != 'workflow_dispatch' || inputs.run-windows
uses: ./.github/workflows/test-single.yml
needs: configure
with:
emoji: 🪟
matrix: windows
name: Windows
file_name: windows
concurrency_name: windows
configuration: ${{ needs.configure.outputs.configuration }}
matrix_mode: ${{ needs.configure.outputs.matrix_mode }}
runs-on: windows-latest
arch: intel
collect-junit: false
coverage:
name: ${{ matrix.os.emoji }} Coverage - ${{ matrix.python.name }}
runs-on: ${{ matrix.os.runs-on }}
needs:
- macos-intel
- macos-arm
- ubuntu
- windows
strategy:
fail-fast: false
matrix:
os:
- emoji: 🐧
matrix: ubuntu
name: Ubuntu
runs-on: ubuntu-latest
python:
- name: "3.10"
action: "3.10"
apt: "3.10"
install_sh: "3.10"
matrix: "3.10"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Env
uses: Chia-Network/actions/setjobenv@main
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download Results
if: false
uses: actions/download-artifact@v4
with:
merge-multiple: true
pattern: junit-data-*
path: junit-data
- name: Format JUnit data and prepare results
if: false
run: |
sudo snap install yq
ls junit-data/*.xml | xargs --max-procs=10 --replace={} yq eval '.testsuites.testsuite.testcase |= sort_by(.+@classname, .+@name)' --inplace {}
sudo apt-get install junitparser
mkdir junit-results
junitparser merge junit-data/*.xml junit-results/junit.xml
ls junit-results/*.xml | xargs --max-procs=10 --replace={} yq eval '.testsuites.testsuite |= sort_by(.+@name) | .testsuites.testsuite[].testcase |= sort_by(.+@classname, .+@name)' --inplace {}
- name: Publish formatted JUnit data
if: false
uses: actions/upload-artifact@v4
with:
name: junit-data
path: junit-data/*
if-no-files-found: error
- name: Download Coverage
uses: actions/download-artifact@v4
with:
merge-multiple: true
pattern: coverage-data-*
path: coverage-data
- name: Set up ${{ matrix.python.name }}
uses: Chia-Network/actions/setup-python@main
with:
python-version: ${{ matrix.python.action }}
- uses: ./.github/actions/install
with:
python-version: ${{ matrix.python.action }}
development: true
- uses: chia-network/actions/activate-venv@main
- name: Add time out assert results to workflow summary
if: always() && false
run: |
python -m chia._tests.process_junit --limit 50 --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> "$GITHUB_STEP_SUMMARY"
python -m chia._tests.process_junit --type time_out_assert --xml junit-results/junit.xml --markdown --link-prefix ${{ github.event.repository.html_url }}/blob/${{ github.sha }}/ --link-line-separator \#L >> junit-results/time_out_assert.md
- name: Publish JUnit results
if: always() && false
uses: actions/upload-artifact@v4
with:
name: junit-results
path: junit-results/*
if-no-files-found: error
- name: Coverage Processing
run: |
coverage combine --rcfile=.coveragerc --data-file=coverage-reports/.coverage coverage-data/
coverage xml --rcfile=.coveragerc --data-file=coverage-reports/.coverage -o coverage-reports/coverage.xml
coverage html --rcfile=.coveragerc --data-file=coverage-reports/.coverage --directory coverage-reports/html/
- uses: coverallsapp/github-action@v2
if: always()
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
- name: Coverage report (chia/)
if: always()
run: |
set -o pipefail
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia/**/*' --omit='chia/_tests/**/*' --show-missing | tee coverage-reports/coverage-chia-stdout
- name: Coverage report (chia/_tests/)
if: always()
run: |
set -o pipefail
coverage report --rcfile=.coveragerc --data-file=coverage-reports/.coverage --include='chia/_tests/**/*' --show-missing | tee coverage-reports/coverage-tests-stdout
- name: Coverage report (diff)
if: (github.base_ref != '' || github.event.before != '') && always()
env:
compare-branch: ${{ github.base_ref == '' && github.event.before || format('origin/{0}', github.base_ref) }}
run: |
diff-cover --config-file=.diffcover.toml --compare-branch=${{ env.compare-branch }} --fail-under=100 --html-report=coverage-reports/diff-cover.html --markdown-report=coverage-reports/diff-cover.md coverage-reports/coverage.xml | tee coverage-reports/diff-cover-stdout
COV_STATUS="${PIPESTATUS[0]}"
echo "COV_STATUS=$COV_STATUS" >> "$GITHUB_ENV"
if [[ $COV_STATUS != '0' && "$GITHUB_BASE_REF" != '' ]]; then
exit 1
fi
- name: Remove previous coverage report comment and label from PR
if: github.base_ref != '' && always()
shell: bash
env:
COV_STATUS: ${{ env.COV_STATUS }}
GH_TOKEN: ${{ github.token }}
ORG_REPO: ${{ github.repository }}
run: |
PR_NUM=$(jq -r '.number' "$GITHUB_EVENT_PATH")
COMMENTS=$(gh api -X GET /repos/"${ORG_REPO}"/issues/"${PR_NUM}"/comments)
COMMENT_ID=$(echo "$COMMENTS" | jq '.[] | select(.user.login == "github-actions[bot]" and (.body | tostring | contains("<!-- COVERAGE_COMMENT_'${PR_NUM}' -->"))) | .id')
COVERAGE_LABEL=$(gh pr view "$PR_NUM" --json labels --jq ' .labels[].name | select(. == "coverage-diff")')
if [[ -n "$COMMENT_ID" ]]; then
gh api -X DELETE /repos/"${ORG_REPO}"/issues/comments/"${COMMENT_ID}"
fi
if [[ "$COV_STATUS" == '0' ]]; then
if [[ "$COVERAGE_LABEL" == "coverage-diff" ]]; then
gh pr edit "$PR_NUM" --remove-label "coverage-diff"
fi
fi
- name: Add diff coverage report comment to PR
if: github.base_ref != '' && always()
env:
BRANCH_NAME: ${{ github.sha }}
COV_STATUS: ${{ env.COV_STATUS }}
GH_TOKEN: ${{ github.token }}
ORG_REPO: ${{ github.repository }}
run: |
if [[ $COV_STATUS != '0' ]]; then
BASE_URL="https://github.com/${ORG_REPO}/blob/${BRANCH_NAME}"
PR_NUM=$(jq -r '.number' "$GITHUB_EVENT_PATH")
COVERAGE_LABEL=$(gh pr view "$PR_NUM" --json labels --jq ' .labels[].name | select(. == "coverage-diff")')
CONTENT=$(<coverage-reports/diff-cover-stdout)
OUTPUT="<!-- COVERAGE_COMMENT_${PR_NUM} -->\n| File | Coverage | Missing Lines |\n|------|----------|---------------|\n"
TOTAL_LINES="Unknown"
MISSING_LINES="Unknown"
TOTAL_COVERAGE="Unknown"
IFS=$'\n'
for LINE in $CONTENT; do
if [[ $LINE =~ ^(.*\.py)\ \(([0-9\.]+%)\)\:\ Missing\ lines\ (.*)$ ]]; then
FILE="${BASH_REMATCH[1]}"
COVERAGE="${BASH_REMATCH[2]}"
MISSING="${BASH_REMATCH[3]}"
MISSING_TRANSFORMED="lines "
IFS=',' read -ra MISSING_PARTS <<< "$MISSING"
for PART in "${MISSING_PARTS[@]}"; do
if [[ $PART =~ ^([0-9]+)\-([0-9]+)$ ]]; then
MISSING_TRANSFORMED+="[${BASH_REMATCH[1]}-${BASH_REMATCH[2]}](${BASE_URL}/${FILE}#L${BASH_REMATCH[1]}-L${BASH_REMATCH[2]}), "
else
MISSING_TRANSFORMED+="[${PART}](${BASE_URL}/${FILE}#L${PART}), "
fi
done
MISSING_TRANSFORMED=${MISSING_TRANSFORMED%, }
OUTPUT+="| [\`${FILE}\`](${BASE_URL}/${FILE}) | ${COVERAGE} | ${MISSING_TRANSFORMED} |\n"
elif [[ $LINE =~ ^Total:\ \ \ (.*)\ lines$ ]]; then
TOTAL_LINES="${BASH_REMATCH[1]} lines"
elif [[ $LINE =~ ^Missing:\ (.*)\ lines$ ]]; then
MISSING_LINES="${BASH_REMATCH[1]} lines"
elif [[ $LINE =~ ^Coverage:\ (.*)%$ ]]; then
TOTAL_COVERAGE="${BASH_REMATCH[1]}%"
fi
done
OUTPUT+="\n| Total | Missing | Coverage |\n|-------|---------|----------|\n| ${TOTAL_LINES} | ${MISSING_LINES} | ${TOTAL_COVERAGE} |\n"
echo -e "$OUTPUT" > temp_comment.txt
gh pr comment "$PR_NUM" -F temp_comment.txt
if [[ $COVERAGE_LABEL != "coverage-diff" ]]; then
gh pr edit "$PR_NUM" --add-label "coverage-diff"
fi
fi
- name: Add diff coverage report to workflow summary
if: (github.base_ref != '' || github.event.before != '') && always()
run: |
cat coverage-reports/diff-cover.md >> "$GITHUB_STEP_SUMMARY"
- name: Publish coverage reports
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: coverage-reports/*
if-no-files-found: error