3232# one configuration doesn't invalidate the others), and the git trees of the
3333# other inputs it reads from the checkout (bases/, include_c++/,
3434# util/eccp.sh, and the workflow files, computed once by the prepare job).
35- # When a leg passes, it saves that entry along with its coverage report; a
36- # later run on the same ref (a re-run, or a push that leaves the build
37- # products and test inputs unchanged) restores it, skips edgy, and reuses
38- # the coverage report, with its line numbers moved to match the sources
39- # being tested (.github/scripts/remap-gcovr-lines.py ).
35+ # When a leg passes, it saves that entry; a later run on the same ref ( a
36+ # re-run, or a push that leaves the build products and test inputs
37+ # unchanged) restores it and skips edgy, and so reports no coverage (the
38+ # earlier run's coverage could point at lines that have since moved).
39+ # Scheduled and manual runs reuse nothing (see reuse_results ).
4040# actions/cache scopes entries to the ref that saved them (plus the default
4141# branch), so one pull request can never vouch for another's build. The
4242# merge queue's entries are saved again for main by promote-test-cache.yml
5050# The debug builds are instrumented for gcov (EDG_CPFE_USE_GCOV) and ship
5151# their .gcno files with the build products. Each test leg turns the .gcda
5252# files its run produces into a gcovr JSON report for src/; the coverage job
53- # merges the reports of all test legs and uploads one report to Codecov
54- # (see .github/codecov.yml). The coverage steps never fail the run; only
53+ # merges the reports of the test legs that ran and uploads one report to
54+ # Codecov (see .github/codecov.yml), which compares nothing and posts
55+ # nothing on pull requests; a pull request links to its report through a
56+ # "coverage" commit status. The nightly scheduled run tests every leg, so it
57+ # gives main complete coverage. The coverage steps never fail the run; only
5558# edgy's results do.
5659
5760name : Build & Test CI
5861
5962on :
6063 pull_request :
6164 merge_group :
65+ # The nightly run tests every leg (no reused results), for complete
66+ # coverage of main.
67+ schedule :
68+ - cron : ' 17 6 * * *'
69+ workflow_dispatch :
6270
6371permissions :
6472 contents : read
@@ -135,6 +143,9 @@ jobs:
135143 configs : ${{ matrix.configs }}
136144 run_timestamp : ${{ needs.prepare.outputs.run_timestamp }}
137145 test_inputs : ${{ needs.prepare.outputs.test_inputs }}
146+ reuse_results : >-
147+ ${{ github.event_name == 'pull_request' ||
148+ github.event_name == 'merge_group' }}
138149
139150 publish-test-results :
140151 name : Publish aggregated test results
@@ -191,6 +202,10 @@ jobs:
191202 if : ${{ !cancelled() }}
192203 runs-on : ubuntu-latest
193204 timeout-minutes : 30
205+ permissions :
206+ contents : read
207+ # To link a pull request to its coverage report.
208+ statuses : write
194209 steps :
195210 - name : Check out repository
196211 uses : actions/checkout@v7
@@ -232,11 +247,17 @@ jobs:
232247 # gcov run (plugins: noop) and its "file fixes" pass, which opens every
233248 # file git tracks and crashes on the dangling symlinks used as test
234249 # inputs (e.g. tests/.../embed___has_embed/embed___has_embed.c).
250+ #
251+ # The report covers the commit tested, which for a pull request is the
252+ # merge commit, not the head commit the action would otherwise report
253+ # it under, so name the commit explicitly.
235254 - name : Upload coverage to Codecov
255+ id : upload
236256 if : ${{ hashFiles('coverage.xml') != '' }}
237257 continue-on-error : true
238258 uses : codecov/codecov-action@v7
239259 with :
260+ override_commit : ${{ github.sha }}
240261 token : ${{ secrets.CODECOV_TOKEN }}
241262 files : coverage.xml
242263 disable_search : true
@@ -246,6 +267,39 @@ jobs:
246267 fail_ci_if_error : true
247268 verbose : true
248269
270+ # Codecov posts no comment or checks (see .github/codecov.yml), so link
271+ # the report from a commit status instead. The report is filed under
272+ # the commit tested, but the status goes on the pull request's head
273+ # commit, as the pull request shows only that commit's statuses. A pull
274+ # request from a fork gets a read-only token and can't set the status;
275+ # the job summary has the link either way.
276+ - name : Link coverage report
277+ if : ${{ !cancelled() }}
278+ continue-on-error : true
279+ env :
280+ GH_TOKEN : ${{ github.token }}
281+ UPLOADED : ${{ steps.upload.outcome == 'success' }}
282+ IS_PULL_REQUEST : ${{ github.event_name == 'pull_request' }}
283+ TESTED_SHA : ${{ github.sha }}
284+ HEAD_SHA : ${{ github.event.pull_request.head.sha || github.sha }}
285+ run : |
286+ if [ "${UPLOADED}" != true ]; then
287+ echo "No coverage report: every test leg reused an earlier" \
288+ "run's results, or coverage failed (see above)." \
289+ >> "${GITHUB_STEP_SUMMARY}"
290+ exit 0
291+ fi
292+ url="https://app.codecov.io/gh/${GITHUB_REPOSITORY}/commit/${TESTED_SHA}"
293+ echo "[Coverage report](${url}) of the test legs this run ran" \
294+ "(legs that reused earlier results add none)." \
295+ >> "${GITHUB_STEP_SUMMARY}"
296+ if [ "${IS_PULL_REQUEST}" = true ]; then
297+ gh api "repos/${GITHUB_REPOSITORY}/statuses/${HEAD_SHA}" \
298+ -f state=success -f context=coverage \
299+ -f description='Coverage of the tests this run ran' \
300+ -f target_url="${url}" > /dev/null
301+ fi
302+
249303 bench :
250304 name : Benchmark linux-gcc-release
251305 if : ${{ github.event_name == 'pull_request' }}
0 commit comments