Skip to content

Commit 754771c

Browse files
committed
Use cargo-nextest to run test on CI
+ Build tests in a dedicated step to remove build outputs from tests run. + fetch cargo tools using cargobinstall to get precompiled binaries instead of compiling them (this will also reduce our cache size °°). + Reenable tests reports in CI using junit reports generated by cargo-nextest.
1 parent 6a7130f commit 754771c

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

.config/nextest.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## cargo nextest configuration file
2+
3+
[profile.ci]
4+
# Print out output for failing tests as soon as they fail, and also at the end
5+
# of the run (for easy scrollability).
6+
failure-output = "immediate-final"
7+
# Do not cancel the test run on the first failure.
8+
fail-fast = false
9+
10+
[profile.ci.junit]
11+
path = "tests-result.junit.xml"
12+
report-name = "mithril-tests"

.github/workflows/actions/toolchain-and-cache/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ runs:
2222
uses: Swatinem/rust-cache@v2
2323
with:
2424
key: ${{ runner.os }}-cache-v${{ inputs.cache-version }}
25-
25+
26+
- name: Install cargo tools installer
27+
uses: taiki-e/install-action@v2
28+
if: inputs.cargo-tools != ''
29+
with:
30+
tool: cargo-binstall
31+
2632
- name: Install cargo tools
2733
if: inputs.cargo-tools != ''
2834
shell: bash
2935
run: |
30-
cargo install ${{ inputs.cargo-tools }} 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error
36+
# Sometimes without the `--force` options the installed binaries are not found by cargo
37+
# leading to error such as: `error: no such command: `my-tool``
38+
cargo binstall --force --no-confirm ${{ inputs.cargo-tools }}

.github/workflows/ci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,25 @@ jobs:
122122
uses: ./.github/workflows/actions/toolchain-and-cache
123123
with:
124124
cache-version: ${{ secrets.CACHE_VERSION }}
125-
cargo-tools: cargo2junit
125+
cargo-tools: cargo-nextest
126+
127+
- name: Build tests
128+
run: cargo nextest run --no-run ${{ matrix.test-args }}
126129

127130
- name: Run tests
128131
shell: bash
129132
run: |
130-
set -o pipefail && \
131-
cargo test --no-fail-fast ${{ matrix.test-args }}
132-
# TODO: Previous command that uses unstable options which are not supported anymore in stable toolchain
133-
#cargo test --no-fail-fast ${{ matrix.test-args }} \
134-
# -- -Z unstable-options --format json --report-time \
135-
# | tee >(cargo2junit > test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }}.xml)
133+
cargo nextest run --profile ci ${{ matrix.test-args }}
134+
# Rename junit file to include runner info
135+
mv target/nextest/ci/tests-result.junit.xml test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }}.xml
136136
137137
- name: Upload Tests Results
138138
uses: actions/upload-artifact@v3
139139
if: success() || failure()
140140
with:
141141
name: test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }}
142142
path: |
143-
./**/test-results-*.xml
143+
./test-results-*.xml
144144
145145
check:
146146
runs-on: ubuntu-22.04
@@ -232,9 +232,7 @@ jobs:
232232
if-no-files-found: error
233233

234234
publish-tests-results:
235-
# TODO: reactivate when cargo test errors export to json works in stable version
236-
#if: success() || failure()
237-
if: false
235+
if: success() || failure()
238236
runs-on: ubuntu-22.04
239237
needs:
240238
- test

0 commit comments

Comments
 (0)