1919#
2020# A shared run timestamp keeps results under the same tests/runs/<timestamp>/
2121# tree; the publish job republishes failure artifacts from all test legs.
22+ #
23+ # The builds set EDG_BUILD_IDENTIFIER so that identical sources produce
24+ # byte-identical build products. Each test leg keys a cache entry on the
25+ # SHA-256 of the build products it downloaded plus the git trees of
26+ # everything else that affects the results (tests/, dev_tools/, bases/, and
27+ # this workflow, computed once by the prepare job). When a leg passes, it
28+ # saves that entry along with its coverage report; a later run on the same
29+ # ref (a re-run, or a push that leaves the build products and test inputs
30+ # unchanged) restores it, skips edgy, and reuses the coverage report.
31+ # actions/cache scopes entries to the ref that saved them (plus the default
32+ # branch), so one pull request can never vouch for another's build.
33+ #
2234# The bench job runs the cachegrind benchmarks the way
2335# `edg-docker-bench --posture=release` does and uploads them as bench-results
2436# (c/ and cpp/ runs, for comparison against the checked-in
3446name : Build & Test CI
3547
3648on :
37- push :
38- branches :
39- - main
40- # The nightly collect-changes job's commits only move Changes entries.
41- paths-ignore :
42- - ' **/Changes'
43- - ' **/pending_changes/**'
4449 pull_request :
4550 merge_group :
4651
@@ -61,19 +66,40 @@ jobs:
6166 timeout-minutes : 5
6267 outputs :
6368 run_timestamp : ${{ steps.timestamp.outputs.run_timestamp }}
69+ test_inputs : ${{ steps.test-inputs.outputs.test_inputs }}
6470 steps :
6571 - name : Declare shared edgy run timestamp
6672 id : timestamp
6773 run : |
6874 # Match edgutil.RUN_TIMESTAMP_FORMAT (%Y.%m.%d-%H.%M.%S).
6975 echo "run_timestamp=$(date -u +'%Y.%m.%d-%H.%M.%S')" >> "${GITHUB_OUTPUT}"
7076
77+ # Only the git trees are needed, so skip blobs and most of the
78+ # working tree.
79+ - name : Check out repository metadata
80+ uses : actions/checkout@v7
81+ with :
82+ persist-credentials : false
83+ filter : blob:none
84+ sparse-checkout : .github
85+
86+ - name : Hash test inputs
87+ id : test-inputs
88+ run : |
89+ # Everything besides the build products that can change a test
90+ # leg's results. The workflow file covers the container image and
91+ # the edgy options.
92+ hash="$(git rev-parse HEAD:tests HEAD:dev_tools HEAD:bases \
93+ HEAD:.github/workflows/build-and-test-ci.yml |
94+ sha256sum | cut -c1-64)"
95+ echo "test_inputs=${hash}" >> "${GITHUB_OUTPUT}"
96+
7197 build-gcc :
7298 name : Build linux-gcc-debug
7399 runs-on : ubuntu-latest
74100 timeout-minutes : 120
75101 container :
76- image : ghcr.io/edgcpp/ci-runner@sha256:14b3948c2ce12cfa5472e5a6c468393d15426f3a67685cc35d830ea5db2acdf8
102+ image : ghcr.io/edgcpp/ci-runner@sha256:e83cc8c97556cdcb42353915a5164a051ba9c219d5b822f6859c875e07e9851d
77103 defaults :
78104 run :
79105 shell : edg-container-exec "bash -eo pipefail {0}"
87113 - name : Configure linux-gcc-debug
88114 env :
89115 EDG_BASE : ${{ github.workspace }}/bases/docker/dev-env/gcc
90- run : cmake --preset linux-gcc-debug -DEDG_CPFE_USE_GCOV=ON
116+ run : >-
117+ cmake --preset linux-gcc-debug -DEDG_CPFE_USE_GCOV=ON
118+ -DEDG_BUILD_IDENTIFIER=ci
91119
92120 - name : Build linux-gcc-debug
93121 env :
@@ -118,7 +146,7 @@ jobs:
118146 runs-on : ubuntu-latest
119147 timeout-minutes : 120
120148 container :
121- image : ghcr.io/edgcpp/ci-runner@sha256:14b3948c2ce12cfa5472e5a6c468393d15426f3a67685cc35d830ea5db2acdf8
149+ image : ghcr.io/edgcpp/ci-runner@sha256:e83cc8c97556cdcb42353915a5164a051ba9c219d5b822f6859c875e07e9851d
122150 defaults :
123151 run :
124152 shell : edg-container-exec "bash -eo pipefail {0}"
@@ -132,7 +160,9 @@ jobs:
132160 - name : Configure linux-i686-gcc-debug
133161 env :
134162 EDG_BASE : ${{ github.workspace }}/bases/docker/dev-env/gcc-i686
135- run : cmake --preset linux-i686-gcc-debug -DEDG_CPFE_USE_GCOV=ON
163+ run : >-
164+ cmake --preset linux-i686-gcc-debug -DEDG_CPFE_USE_GCOV=ON
165+ -DEDG_BUILD_IDENTIFIER=ci
136166
137167 - name : Build linux-i686-gcc-debug
138168 env :
@@ -168,7 +198,7 @@ jobs:
168198 - edg_x86_64
169199 - edg_x86_64_cp
170200 container :
171- image : ghcr.io/edgcpp/ci-runner@sha256:14b3948c2ce12cfa5472e5a6c468393d15426f3a67685cc35d830ea5db2acdf8
201+ image : ghcr.io/edgcpp/ci-runner@sha256:e83cc8c97556cdcb42353915a5164a051ba9c219d5b822f6859c875e07e9851d
172202 # Required for setarch ... -R (disable ASLR) used by the test harness.
173203 options : --privileged
174204 defaults :
@@ -194,7 +224,38 @@ jobs:
194224 # Artifact round-trip does not reliably preserve +x.
195225 chmod -R a+x build/gcc/bin
196226
227+ - name : Compute test cache key
228+ id : key
229+ env :
230+ CONFIG : ${{ matrix.config }}
231+ TEST_INPUTS : ${{ needs.prepare.outputs.test_inputs }}
232+ run : |
233+ # Hash the names and contents of the downloaded build products.
234+ build="$(cd build/gcc &&
235+ find . -type f -print0 | LC_ALL=C sort -z |
236+ xargs -0 sha256sum | sha256sum | cut -c1-64)"
237+ echo "Build products: ${build}"
238+ echo "key=tested-${CONFIG}-${TEST_INPUTS}-${build}" \
239+ >> "${GITHUB_OUTPUT}"
240+
241+ - name : Look for an earlier passing run of this build
242+ id : tested
243+ uses : actions/cache/restore@v6
244+ with :
245+ key : ${{ steps.key.outputs.key }}
246+ path : .tmp/tested
247+
248+ - name : Reuse earlier results
249+ if : ${{ steps.tested.outputs.cache-hit == 'true' }}
250+ run : |
251+ echo "::notice::This build already passed with the same test" \
252+ "inputs: $(cat .tmp/tested/ci-meta.json)"
253+ mkdir -p coverage
254+ cp .tmp/tested/coverage/*.json coverage/ || true
255+
197256 - name : Run edgy (${{ matrix.config }})
257+ id : edgy
258+ if : ${{ steps.tested.outputs.cache-hit != 'true' }}
198259 env :
199260 RUN_TIMESTAMP : ${{ needs.prepare.outputs.run_timestamp }}
200261 CONFIG : ${{ matrix.config }}
@@ -230,7 +291,7 @@ jobs:
230291 # Coverage problems must never fail the test leg, hence
231292 # continue-on-error.
232293 - name : Install gcovr
233- if : ${{ !cancelled() }}
294+ if : ${{ !cancelled() && steps.tested.outputs.cache-hit != 'true' }}
234295 continue-on-error : true
235296 run : |
236297 python3 -m venv "${RUNNER_TEMP}/gcovr"
@@ -242,7 +303,7 @@ jobs:
242303 # hot loops exceed gcovr's "suspicious hits" threshold; warn about them
243304 # instead of failing.
244305 - name : Generate coverage report
245- if : ${{ !cancelled() }}
306+ if : ${{ !cancelled() && steps.tested.outputs.cache-hit != 'true' }}
246307 continue-on-error : true
247308 env :
248309 CONFIG : ${{ matrix.config }}
@@ -269,6 +330,37 @@ jobs:
269330 if-no-files-found : warn
270331 retention-days : 1
271332
333+ # Record the pass (with its coverage report, so a run that skips edgy
334+ # still contributes coverage). Without a report, don't record it.
335+ - name : Prepare record of this passing run
336+ id : record
337+ if : >-
338+ ${{ steps.edgy.outcome == 'success' &&
339+ hashFiles(format('coverage/{0}.json', matrix.config)) != '' }}
340+ env :
341+ CONFIG : ${{ matrix.config }}
342+ RUN_ID : ${{ github.run_id }}
343+ RUN_ATTEMPT : ${{ github.run_attempt }}
344+ TESTED_SHA : ${{ github.sha }}
345+ run : |
346+ mkdir -p .tmp/tested/coverage
347+ cp "coverage/${CONFIG}.json" .tmp/tested/coverage/
348+ python3 - > .tmp/tested/ci-meta.json <<'EOF'
349+ import json, os
350+ print(json.dumps({
351+ 'tested_sha': os.environ['TESTED_SHA'],
352+ 'run_id': int(os.environ['RUN_ID']),
353+ 'run_attempt': int(os.environ['RUN_ATTEMPT']),
354+ }))
355+ EOF
356+
357+ - name : Save record of this passing run
358+ if : ${{ steps.record.outcome == 'success' }}
359+ uses : actions/cache/save@v6
360+ with :
361+ key : ${{ steps.key.outputs.key }}
362+ path : .tmp/tested
363+
272364 test-i686 :
273365 name : Test ${{ matrix.config }}
274366 needs :
@@ -283,7 +375,7 @@ jobs:
283375 - edg_x86_32
284376 - edg_x86_32_cp
285377 container :
286- image : ghcr.io/edgcpp/ci-runner@sha256:14b3948c2ce12cfa5472e5a6c468393d15426f3a67685cc35d830ea5db2acdf8
378+ image : ghcr.io/edgcpp/ci-runner@sha256:e83cc8c97556cdcb42353915a5164a051ba9c219d5b822f6859c875e07e9851d
287379 # Required for setarch ... -R (disable ASLR) used by the test harness.
288380 options : --privileged
289381 defaults :
@@ -309,7 +401,38 @@ jobs:
309401 # Artifact round-trip does not reliably preserve +x.
310402 chmod -R a+x build/gcc-i686/bin
311403
404+ - name : Compute test cache key
405+ id : key
406+ env :
407+ CONFIG : ${{ matrix.config }}
408+ TEST_INPUTS : ${{ needs.prepare.outputs.test_inputs }}
409+ run : |
410+ # Hash the names and contents of the downloaded build products.
411+ build="$(cd build/gcc-i686 &&
412+ find . -type f -print0 | LC_ALL=C sort -z |
413+ xargs -0 sha256sum | sha256sum | cut -c1-64)"
414+ echo "Build products: ${build}"
415+ echo "key=tested-${CONFIG}-${TEST_INPUTS}-${build}" \
416+ >> "${GITHUB_OUTPUT}"
417+
418+ - name : Look for an earlier passing run of this build
419+ id : tested
420+ uses : actions/cache/restore@v6
421+ with :
422+ key : ${{ steps.key.outputs.key }}
423+ path : .tmp/tested
424+
425+ - name : Reuse earlier results
426+ if : ${{ steps.tested.outputs.cache-hit == 'true' }}
427+ run : |
428+ echo "::notice::This build already passed with the same test" \
429+ "inputs: $(cat .tmp/tested/ci-meta.json)"
430+ mkdir -p coverage
431+ cp .tmp/tested/coverage/*.json coverage/ || true
432+
312433 - name : Run edgy (${{ matrix.config }})
434+ id : edgy
435+ if : ${{ steps.tested.outputs.cache-hit != 'true' }}
313436 env :
314437 RUN_TIMESTAMP : ${{ needs.prepare.outputs.run_timestamp }}
315438 CONFIG : ${{ matrix.config }}
@@ -345,7 +468,7 @@ jobs:
345468 # Coverage problems must never fail the test leg, hence
346469 # continue-on-error.
347470 - name : Install gcovr
348- if : ${{ !cancelled() }}
471+ if : ${{ !cancelled() && steps.tested.outputs.cache-hit != 'true' }}
349472 continue-on-error : true
350473 run : |
351474 python3 -m venv "${RUNNER_TEMP}/gcovr"
@@ -357,7 +480,7 @@ jobs:
357480 # hot loops exceed gcovr's "suspicious hits" threshold; warn about them
358481 # instead of failing.
359482 - name : Generate coverage report
360- if : ${{ !cancelled() }}
483+ if : ${{ !cancelled() && steps.tested.outputs.cache-hit != 'true' }}
361484 continue-on-error : true
362485 env :
363486 CONFIG : ${{ matrix.config }}
@@ -384,6 +507,37 @@ jobs:
384507 if-no-files-found : warn
385508 retention-days : 1
386509
510+ # Record the pass (with its coverage report, so a run that skips edgy
511+ # still contributes coverage). Without a report, don't record it.
512+ - name : Prepare record of this passing run
513+ id : record
514+ if : >-
515+ ${{ steps.edgy.outcome == 'success' &&
516+ hashFiles(format('coverage/{0}.json', matrix.config)) != '' }}
517+ env :
518+ CONFIG : ${{ matrix.config }}
519+ RUN_ID : ${{ github.run_id }}
520+ RUN_ATTEMPT : ${{ github.run_attempt }}
521+ TESTED_SHA : ${{ github.sha }}
522+ run : |
523+ mkdir -p .tmp/tested/coverage
524+ cp "coverage/${CONFIG}.json" .tmp/tested/coverage/
525+ python3 - > .tmp/tested/ci-meta.json <<'EOF'
526+ import json, os
527+ print(json.dumps({
528+ 'tested_sha': os.environ['TESTED_SHA'],
529+ 'run_id': int(os.environ['RUN_ID']),
530+ 'run_attempt': int(os.environ['RUN_ATTEMPT']),
531+ }))
532+ EOF
533+
534+ - name : Save record of this passing run
535+ if : ${{ steps.record.outcome == 'success' }}
536+ uses : actions/cache/save@v6
537+ with :
538+ key : ${{ steps.key.outputs.key }}
539+ path : .tmp/tested
540+
387541 publish-test-results :
388542 name : Publish aggregated test results
389543 needs :
@@ -508,7 +662,7 @@ jobs:
508662 runs-on : ubuntu-latest
509663 timeout-minutes : 120
510664 container :
511- image : ghcr.io/edgcpp/ci-runner@sha256:14b3948c2ce12cfa5472e5a6c468393d15426f3a67685cc35d830ea5db2acdf8
665+ image : ghcr.io/edgcpp/ci-runner@sha256:e83cc8c97556cdcb42353915a5164a051ba9c219d5b822f6859c875e07e9851d
512666 defaults :
513667 run :
514668 shell : edg-container-exec "bash -eo pipefail {0}"
0 commit comments