Skip to content

Commit 133eac8

Browse files
authored
ci: run coverage for the free-threaded build (#4638)
1 parent 4bb4058 commit 133eac8

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ jobs:
451451
runs-on: ${{ matrix.os }}
452452
steps:
453453
- uses: actions/checkout@v4
454-
with:
455-
# Use the PR head, not the merge commit, because the head commit (and the base)
456-
# is what codecov uses to calculate diffs.
457-
ref: ${{ github.event.pull_request.head.sha }}
458454
- uses: actions/setup-python@v5
459455
with:
460456
python-version: '3.12'
@@ -572,10 +568,24 @@ jobs:
572568
with:
573569
python-version: '3.13-dev'
574570
nogil: true
571+
- name: Install cargo-llvm-cov
572+
uses: taiki-e/install-action@cargo-llvm-cov
575573
- run: python3 -m sysconfig
576574
- run: python3 -m pip install --upgrade pip && pip install nox
575+
- name: Prepare coverage environment
576+
run: |
577+
cargo llvm-cov clean --workspace --profraw-only
578+
nox -s set-coverage-env
577579
- run: nox -s ffi-check
578580
- run: nox
581+
- name: Generate coverage report
582+
run: nox -s generate-coverage-report
583+
- name: Upload coverage report
584+
uses: codecov/codecov-action@v4
585+
with:
586+
file: coverage.json
587+
name: test-free-threaded
588+
token: ${{ secrets.CODECOV_TOKEN }}
579589

580590
test-version-limits:
581591
needs: [fmt]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This runs as a separate job because it needs to run on the `pull_request_target` event
2+
# in order to access the CODECOV_TOKEN secret.
3+
#
4+
# This is safe because this doesn't run arbitrary code from PRs.
5+
6+
name: Set Codecov PR base
7+
on:
8+
# See safety note / doc at the top of this file.
9+
pull_request_target:
10+
11+
jobs:
12+
coverage-pr-base:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.12'
19+
- name: Set PR base on codecov
20+
run: |
21+
# fetch the merge commit between the PR base and head
22+
BASE_REF=refs/heads/${{ github.event.pull_request.base.ref }}
23+
MERGE_REF=refs/pull/${{ github.event.pull_request.number }}/merge
24+
25+
git fetch --progress --depth=1 origin "+$BASE_REF:$BASE_REF" "+$MERGE_REF:$MERGE_REF"
26+
while [ -z "$(git merge-base "$BASE_REF" "$MERGE_REF")" ]; do
27+
git fetch -q --deepen="10" origin "$BASE_REF" "$MERGE_REF";
28+
done
29+
30+
MERGE_BASE=$(git merge-base "$BASE_REF" "$MERGE_REF")
31+
echo "Merge base: $MERGE_BASE"
32+
33+
# inform codecov about the merge base
34+
pip install codecov-cli
35+
codecovcli pr-base-picking \
36+
--base-sha $MERGE_BASE \
37+
--pr ${{ github.event.number }} \
38+
--slug PyO3/pyo3 \
39+
--token ${{ secrets.CODECOV_TOKEN }} \
40+
--service github

noxfile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,19 @@ def coverage(session: nox.Session) -> None:
7272
session.env.update(_get_coverage_env())
7373
_run_cargo(session, "llvm-cov", "clean", "--workspace")
7474
test(session)
75+
generate_coverage_report(session)
7576

77+
78+
@nox.session(name="set-coverage-env", venv_backend="none")
79+
def set_coverage_env(session: nox.Session) -> None:
80+
"""For use in GitHub Actions to set coverage environment variables."""
81+
with open(os.environ["GITHUB_ENV"], "a") as env_file:
82+
for k, v in _get_coverage_env().items():
83+
print(f"{k}={v}", file=env_file)
84+
85+
86+
@nox.session(name="generate-coverage-report", venv_backend="none")
87+
def generate_coverage_report(session: nox.Session) -> None:
7688
cov_format = "codecov"
7789
output_file = "coverage.json"
7890

0 commit comments

Comments
 (0)