Skip to content

Commit 78251ef

Browse files
committed
ci: track test coverage
1 parent 140ba9f commit 78251ef

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

.config/nextest.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile.default]
2+
failure-output = "final"
3+
4+
[profile.ci]
5+
fail-fast = false
6+
junit.path = "junit.xml"

.github/workflows/ci.yml

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ jobs:
3030
uses: actions/checkout@v4
3131

3232
- name: Set up Rust toolchain
33-
uses: dtolnay/rust-toolchain@stable
34-
with:
35-
components: clippy
33+
run: rustup install --profile minimal --component clippy
3634

3735
- name: Cache build artifacts
3836
uses: Swatinem/rust-cache@v2
37+
with:
38+
cache-on-failure: true
3939

4040
- name: Lint Rust code
4141
run: cargo clippy --all-targets --workspace --locked
@@ -74,31 +74,90 @@ jobs:
7474
uses: actions/checkout@v4
7575

7676
- name: Set up Rust toolchain
77-
uses: dtolnay/rust-toolchain@stable
78-
with:
79-
components: rustfmt
77+
run: rustup install --profile minimal --component rustfmt
8078

8179
- name: Cache build artifacts
8280
uses: Swatinem/rust-cache@v2
81+
with:
82+
cache-on-failure: true
8383

8484
- name: Check formatting
8585
run: cargo fmt --check --all
8686

8787
test:
8888
name: Run tests
8989
runs-on: ubuntu-latest
90+
permissions:
91+
checks: write
92+
pull-requests: write
93+
contents: read
9094
steps:
9195
- name: Check out sources
9296
uses: actions/checkout@v4
9397

9498
- name: Set up Rust toolchain
95-
uses: dtolnay/rust-toolchain@stable
99+
run: rustup install --profile minimal --component llvm-tools
96100

97101
- name: Cache build artifacts
98102
uses: Swatinem/rust-cache@v2
103+
with:
104+
cache-on-failure: true
105+
106+
- name: Install nextest (if not cached)
107+
run: cargo nextest --version || cargo install --locked cargo-nextest
108+
109+
- name: Install llvm-cov (if not cached)
110+
run: cargo llvm-cov --version || cargo install --locked cargo-llvm-cov
111+
112+
- name: Run tests
113+
run: >-
114+
cargo llvm-cov nextest
115+
--no-report
116+
--no-fail-fast
117+
--locked
118+
--workspace
119+
--all-targets
120+
--all-features
121+
--profile ci
122+
123+
- name: Generate coverage reports
124+
if: ${{ !cancelled() }} # Generate reports even if tests failed
125+
shell: bash
126+
run: |
127+
cargo llvm-cov report --html
128+
cargo llvm-cov report --codecov --output-path target/llvm-cov/codecov.json
99129
100-
- name: Run default tests
101-
run: cargo test --workspace --all-targets --no-fail-fast --locked
130+
- name: Publish test results
131+
uses: EnricoMi/publish-unit-test-result-action@v2
132+
if: ${{ !cancelled() }} # Upload reports even if tests failed
133+
with:
134+
check_run: false
135+
comment_mode: ${{ (github.event_name == 'pull_request') && 'always' || 'off' }}
136+
files: |
137+
target/nextest/ci/junit.xml
138+
139+
- name: Upload test results to Codecov
140+
# if: ${{ !cancelled() }} # Upload reports even if tests failed
141+
if: false # Skip until we set up Codecov for the @purduehackers org
142+
uses: codecov/test-results-action@v1
143+
with:
144+
token: ${{ secrets.CODECOV_TOKEN }}
145+
file: target/nextest/ci/junit.xml
146+
147+
- name: Upload coverage to Codecov
148+
uses: codecov/codecov-action@v5
149+
# if: ${{ !cancelled() }} # Upload reports even if tests failed
150+
if: false # Skip until we set up Codecov for the @purduehackers org
151+
with:
152+
token: ${{ secrets.CODECOV_TOKEN }}
153+
files: target/llvm-cov/codecov.json
154+
155+
- name: Upload HTML coverage report
156+
uses: actions/upload-artifact@v4
157+
if: ${{ !cancelled() }} # Upload reports even if tests failed
158+
with:
159+
name: coverage-html
160+
path: target/llvm-cov/html/
102161

103162
# Adding this because we don't want to run the whole build workflow on each
104163
# push
@@ -110,10 +169,12 @@ jobs:
110169
uses: actions/checkout@v4
111170

112171
- name: Set up Rust toolchain
113-
uses: dtolnay/rust-toolchain@stable
172+
run: rustup install --profile minimal
114173

115174
- name: Cache build artifacts
116175
uses: Swatinem/rust-cache@v2
176+
with:
177+
cache-on-failure: true
117178

118179
- name: Compile project
119180
run: cargo build --workspace --all-targets --release --locked

0 commit comments

Comments
 (0)