Skip to content

Commit fccf571

Browse files
committed
perf(ci): replace coverage report with a plain Rust test run
The nixified `cargo llvm-cov` coverage build recompiled the whole workspace with instrumentation (~230s) and produced a cobertura report nothing consumed (no badge, no docs reference). Drop coverage entirely and run the workspace tests instead via crane's `cargoTest`, which reuses the shared, non-instrumented `cargoArtifacts` and only compiles the test binaries. - nix/coverage.nix -> nix/tests.nix: `ccusage-tests` package built with `cargoTest` (doCheck enabled), source scoped to the Rust tree plus the few out-of-tree files the build/tests `include_str!`, so unrelated edits don't invalidate it. - CI test job: replace the coverage generate + upload steps with `nix build .#ccusage-tests`; drop the now-unused `code-quality` permission and the upload-code-coverage action. Verified locally: the derivation runs the suite (253 + 10 + 51 + 16 + 2 tests pass) rather than skipping it.
1 parent 42e5b16 commit fccf571

3 files changed

Lines changed: 29 additions & 32 deletions

File tree

‎.github/workflows/ci.yaml‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
timeout-minutes: 30
4040
permissions:
4141
contents: read
42-
code-quality: write
4342
pull-requests: read
4443

4544
steps:
@@ -48,10 +47,10 @@ jobs:
4847
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4948
persist-credentials: false
5049
- uses: ./.github/actions/setup-nix
51-
# Vitest is the only step that needs the JS toolchain (the coverage step
52-
# builds via `nix build`), so install just pnpm/node/just instead of
53-
# realizing the full dev shell, which drags in every linter, formatter,
54-
# and the pre-commit hook closure and dominated this job's wall time.
50+
# Vitest needs the JS toolchain; the Rust tests run via `nix build`. Install
51+
# just pnpm/node/just instead of realizing the full dev shell, which drags
52+
# in every linter, formatter, and the pre-commit hook closure and dominated
53+
# this job's wall time.
5554
- name: Install JS tooling
5655
run: nix profile install --inputs-from . nixpkgs#pnpm nixpkgs#nodejs nixpkgs#just
5756
- run: pnpm install --frozen-lockfile
@@ -61,19 +60,8 @@ jobs:
6160
mkdir -p "$HOME/.config/claude/projects"
6261
- name: Run Vitest tests
6362
run: just test-vitest
64-
- name: Generate Rust coverage report
65-
run: |
66-
mkdir -p coverage
67-
nix build .#ccusage-coverage --print-build-logs --out-link "$RUNNER_TEMP/coverage-report"
68-
cp "$RUNNER_TEMP/coverage-report" coverage/cobertura.xml
69-
- name: Upload Rust coverage report
70-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
71-
uses: actions/upload-code-coverage@abb5995db9e0199b0e2bb9dbd136fce4cb1ec4d3 # v1.3.0
72-
with:
73-
file: coverage/cobertura.xml
74-
language: Rust
75-
label: code-coverage/cargo-llvm-cov
76-
fail-on-error: false
63+
- name: Run Rust tests
64+
run: nix build .#ccusage-tests --print-build-logs
7765

7866
build-native-packages:
7967
needs: changes

‎flake.nix‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
./nix/git-hooks.nix
5151
./nix/packages.nix
5252
./nix/static-package.nix
53-
./nix/coverage.nix
53+
./nix/tests.nix
5454
./nix/checks.nix
5555
./nix/dev-shell.nix
5656
];

nix/coverage.nix renamed to nix/tests.nix

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Rust coverage report built as a Nix derivation so it shares the crane
1+
# Rust workspace test run as a Nix derivation so it shares the crane
22
# `cargoArtifacts` cache (warm on the per-job Blacksmith sticky disk) instead of
3-
# the dev-shell's `cargo llvm-cov`, which recompiled the whole workspace into an
4-
# uncached `rust/target` on every CI run. Output is the cobertura XML file at
5-
# `$out`, consumed by the coverage upload step in CI via `nix build`.
3+
# recompiling into an uncached `rust/target` on every CI run. Built by the CI
4+
# test job via `nix build .#ccusage-tests`; the derivation succeeds only when
5+
# `cargo test --workspace` passes.
66
{ inputs, ... }:
77
let
88
root = ./..;
@@ -23,26 +23,35 @@ in
2323
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
2424
inherit (config.packages.ccusage.passthru) cargoArtifacts commonArgs;
2525
nixFilter = inputs.nix-filter.lib;
26-
repoSrc = nixFilter {
26+
# Scope the source to the Rust tree plus the few out-of-tree files the
27+
# build and tests pull in at compile time, so the derivation only rebuilds
28+
# when something it actually depends on changes — not on every docs, TS, or
29+
# config edit elsewhere in the repo:
30+
# * rust/build.rs reads ../../../flake.lock
31+
# * config_schema.rs tests include_str! ../../../../ccusage.example.json
32+
# * ccusage-cli tests include_str! ../../../../apps/ccusage/package.json
33+
testSrc = nixFilter {
2734
inherit root;
28-
exclude = [
29-
(nixFilter.matchName "node_modules")
30-
(nixFilter.matchName "target")
31-
(nixFilter.matchName "dist")
32-
(nixFilter.matchName "coverage")
35+
include = [
36+
"rust"
37+
"flake.lock"
38+
"ccusage.example.json"
39+
"apps/ccusage/package.json"
3340
];
3441
};
3542
in
3643
{
37-
packages.ccusage-coverage = craneLib.cargoLlvmCov (
44+
packages.ccusage-tests = craneLib.cargoTest (
3845
commonArgs
3946
// {
40-
src = repoSrc;
47+
src = testSrc;
4148
sourceRoot = "source/rust";
4249
cargoLock = root + /rust/Cargo.lock;
4350
inherit cargoArtifacts;
51+
# commonArgs disables checks for the release build; re-enable here so
52+
# cargoTest actually runs the test suite rather than skipping it.
53+
doCheck = true;
4454
cargoExtraArgs = "--workspace";
45-
cargoLlvmCovExtraArgs = "--cobertura --output-path $out";
4655
# jiff resolves named time zones (e.g. Asia/Tokyo) from the system
4756
# zoneinfo database, which the hermetic build sandbox lacks, so it
4857
# would fall back to UTC and shift the timezone-dependent tests by a

0 commit comments

Comments
 (0)