Skip to content

Commit 318539c

Browse files
Replace code covergage reporting with lighter weight code coverage integration []
1 parent 5d279ed commit 318539c

5 files changed

Lines changed: 95 additions & 221 deletions

File tree

‎.github/codecov.yml‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
#
66
# Codecov configuration (https://docs.codecov.com/docs/codecov-yaml).
77
# The coverage job of .github/workflows/build-and-test-ci.yml merges the
8-
# reports of all test legs and uploads them as a single report, so no
9-
# upload count needs to be configured here.
8+
# reports of the test legs that ran and uploads them as a single report, so
9+
# no upload count needs to be configured here.
10+
#
11+
# Only the nightly scheduled run on main tests every leg; other runs skip
12+
# the legs whose results they can reuse, so their reports cover only part of
13+
# the tests. Codecov therefore compares nothing: no comment, no status
14+
# checks, and no annotations of uncovered lines. A pull request links to its
15+
# report through the "coverage" commit status that the coverage job sets.
1016

1117
codecov:
12-
# Wait for CI to pass before posting coverage results: a failed test leg
13-
# can leave the report incomplete, which would look like a regression.
1418
require_ci_to_pass: true
1519

1620
coverage:
1721
precision: 2
1822
round: down
1923
range: "20...80"
2024
status:
21-
# Report, but never fail, the project and patch checks.
22-
project:
23-
default:
24-
informational: true
25-
patch:
26-
default:
27-
informational: true
25+
project: off
26+
patch: off
27+
changes: off
28+
29+
comment: false
2830

29-
comment:
30-
layout: "header, diff, files, footer"
31-
behavior: default
32-
require_changes: false
31+
github_checks:
32+
annotations: false
3333

3434
# Only src/ is reported (see the gcovr --filter in build-and-test-ci.yml);
3535
# keep the rest of the tree out of Codecov's view even if a report includes

‎.github/scripts/.gitignore‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎.github/scripts/remap-gcovr-lines.py‎

Lines changed: 0 additions & 165 deletions
This file was deleted.

‎.github/workflows/build-and-test-ci.yml‎

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
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
@@ -50,15 +50,23 @@
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

5760
name: Build & Test CI
5861

5962
on:
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

6371
permissions:
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

Comments
 (0)