Skip to content

Commit 284899c

Browse files
authored
ci: upload Rust coverage to GitHub (#1164)
* ci: upload Rust coverage to GitHub Add a dedicated CI job that generates Cobertura XML from the Rust workspace with cargo-llvm-cov and uploads it through GitHub Code Coverage. The job runs only for pull requests and default-branch pushes after the existing code-change detector passes, which gives GitHub Code Quality both PR coverage data and a default-branch baseline without adding work to docs-only changes. Add cargo-llvm-cov and the llvm-tools-preview component to the Nix-backed toolchain so local and CI environments can produce the report reproducibly. * ci: pin coverage upload action Pin actions/upload-code-coverage to the current v1 commit SHA so the job follows the repository pattern of immutable GitHub Action references. Add an explicit timeout to the coverage job to avoid unbounded runner usage if coverage generation or upload stalls. * ci: make coverage upload best effort Keep generating the Rust Cobertura report and invoking GitHub Code Coverage, but do not fail the whole CI run when the public preview API returns an upload error. The current upload endpoint returns HTTP 404 for this repository even though coverage generation succeeds, which indicates the preview API is not available for the repository yet. The workflow will surface the upload error annotation while allowing the rest of CI to stay green. Grant pull-requests: read for the action path that resolves PR numbers during push events. * ci: fold coverage into test job Run Rust coverage from the existing test job on pull requests and default-branch pushes so CI does not execute the Rust test suite twice. The test job now runs Vitest separately when coverage is enabled, then uses cargo-llvm-cov as the Rust test execution path before uploading the Cobertura report. Non-coverage branch pushes keep the existing pnpm run test path. Keep the upload permissions and best-effort error handling in the test job because GitHub Code Coverage may return preview API errors before the repository-side feature is fully available.
1 parent ae09518 commit 284899c

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,45 @@ jobs:
3535
needs: changes
3636
if: needs.changes.outputs.code-changed == 'true'
3737
runs-on: ubuntu-24.04-arm
38+
timeout-minutes: 30
39+
permissions:
40+
contents: read
41+
code-quality: write
42+
pull-requests: read
3843

3944
steps:
4045
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
46+
with:
47+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
48+
persist-credentials: false
4149
- uses: ./.github/actions/setup-nix
4250
- name: Create default Claude directories for tests
4351
run: |
4452
mkdir -p "$HOME/.claude/projects"
4553
mkdir -p "$HOME/.config/claude/projects"
46-
- run: nix develop --command pnpm run test
54+
- name: Run test suite
55+
if: github.event_name != 'pull_request' && github.ref != format('refs/heads/{0}', github.event.repository.default_branch)
56+
run: nix develop --command pnpm run test
57+
- name: Run Vitest tests
58+
if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
59+
run: nix develop --command pnpm run test:vitest
60+
- name: Generate Rust coverage report
61+
if: github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
62+
run: |
63+
mkdir -p coverage
64+
env -u CFLAGS -u CXXFLAGS nix develop --command cargo llvm-cov \
65+
--manifest-path rust/Cargo.toml \
66+
--workspace \
67+
--cobertura \
68+
--output-path coverage/cobertura.xml
69+
- name: Upload Rust coverage report
70+
if: (github.event_name == 'pull_request' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
71+
uses: actions/upload-code-coverage@b51da2c3c1b23e04d2d6477cfc34350b1f5cd3e9 # v1
72+
with:
73+
file: coverage/cobertura.xml
74+
language: Rust
75+
label: code-coverage/cargo-llvm-cov
76+
fail-on-error: false
4777

4878
build-native-packages:
4979
needs: changes

‎nix/dev-shell.nix‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ in
2626
rustToolchain
2727
cargo-edit
2828
cargo-insta
29+
cargo-llvm-cov
2930
pkg-config
3031
openssl
3132
config.treefmt.build.wrapper

‎rust-toolchain.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
channel = "1.85.1"
3-
components = ["clippy", "rustfmt"]
3+
components = ["clippy", "llvm-tools-preview", "rustfmt"]

0 commit comments

Comments
 (0)