@@ -102,32 +102,21 @@ jobs:
102102 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
103103
104104 - name : Install cargo-llvm-cov
105- if : ${{ matrix.rust-version == 'stable' && runner.os == 'Linux' }}
105+ if : ${{ matrix.rust == 'stable' && runner.os == 'Linux' }}
106106 uses : taiki-e/install-action@cargo-llvm-cov
107107
108- - name : Install cargo-nextest
109- uses : taiki-e/install-action@nextest
110-
111- - name : Build and run tests
108+ - name : Build tests
112109 run : |
113- # only collect code coverage for the latest rust release on linux
114- if [[ ${{ matrix.rust-version }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
115- cargo llvm-cov --no-report nextest --features test --workspace --tests
116- cargo llvm-cov report --lcov --output-path lcov.info
117- # remove generated coverage data to avoid caching it
118- find . -name \*.profraw -delete
119- else
120- cargo nextest run --features test --workspace --tests
110+ # only collect coverage for the latest rust release on linux
111+ if [[ ${{ matrix.rust }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
112+ # set environment variables needed for coverage
113+ source <(cargo llvm-cov show-env --export-prefix)
114+ # remove artifacts that may affect coverage results
115+ cargo llvm-cov clean --workspace
121116 fi
122117
123- - name : Upload build artifacts
124- if : ${{ matrix.rust-version == 'stable' && runner.os == 'Linux' }}
125- uses : actions/upload-artifact@v4
126- with :
127- name : coverage
128- path : lcov.info
129- if-no-files-found : error
130- retention-days : 3
118+ # build tests
119+ cargo build --all-features --workspace --tests
131120
132121 - name : Save cache
133122 if : ${{ github.ref_name == 'main' && steps.restore-cache.outputs.cache-hit != 'true' }}
@@ -140,8 +129,46 @@ jobs:
140129 target
141130 key : ${{ steps.restore-cache.outputs.cache-primary-key }}
142131
132+ - name : Install grcov
133+ if : ${{ matrix.rust == 'stable' && runner.os == 'Linux' }}
134+ uses : taiki-e/install-action@grcov
135+
136+ - name : Install cargo-nextest
137+ uses : taiki-e/install-action@nextest
138+
139+ - name : Run tests
140+ run : |
141+ # set environment variables needed for coverage
142+ if [[ ${{ matrix.rust }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
143+ source <(cargo llvm-cov show-env --export-prefix)
144+ fi
145+
146+ # run tests
147+ cargo nextest run --all-features --workspace --tests
148+
149+ # only collect coverage for the latest rust release on linux
150+ if [[ ${{ matrix.rust }} == 'stable' && ${{ runner.os }} == 'Linux' ]]; then
151+ # make sure all profile data is in the expected directory
152+ find crates -name \*.profraw -exec mv '{}' target/debug/ \;
153+
154+ # process coverage information
155+ grcov . -s . --binary-path target/debug \
156+ --keep-only "crates/*/src/*" -t lcov --llvm --branch -o lcov.info \
157+ --excl-line "unreachable!(.*)|grcov-excl-line" \
158+ --excl-start grcov-excl-start \
159+ --excl-stop grcov-excl-stop
160+ fi
161+
162+ - name : Upload build artifacts
163+ if : ${{ matrix.rust == 'stable' && runner.os == 'Linux' }}
164+ uses : actions/upload-artifact@v4
165+ with :
166+ name : coverage
167+ path : lcov.info
168+ if-no-files-found : error
169+ retention-days : 3
170+
143171 coverage :
144- if : ${{ github.ref_name == 'main' }}
145172 needs : test
146173 runs-on : ubuntu-latest
147174 continue-on-error : true
0 commit comments