From 754771caf681b91ca226bc8b103ebe2c14404ffc Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Thu, 29 Jun 2023 14:56:35 +0200 Subject: [PATCH] Use cargo-nextest to run test on CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + 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. --- .config/nextest.toml | 12 +++++++++++ .../actions/toolchain-and-cache/action.yml | 12 +++++++++-- .github/workflows/ci.yml | 20 +++++++++---------- 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 .config/nextest.toml diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 00000000000..2ffbc8b0f9b --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,12 @@ +## cargo nextest configuration file + +[profile.ci] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false + +[profile.ci.junit] +path = "tests-result.junit.xml" +report-name = "mithril-tests" diff --git a/.github/workflows/actions/toolchain-and-cache/action.yml b/.github/workflows/actions/toolchain-and-cache/action.yml index 1135e0479ae..be140a3032d 100644 --- a/.github/workflows/actions/toolchain-and-cache/action.yml +++ b/.github/workflows/actions/toolchain-and-cache/action.yml @@ -22,9 +22,17 @@ runs: uses: Swatinem/rust-cache@v2 with: key: ${{ runner.os }}-cache-v${{ inputs.cache-version }} - + + - name: Install cargo tools installer + uses: taiki-e/install-action@v2 + if: inputs.cargo-tools != '' + with: + tool: cargo-binstall + - name: Install cargo tools if: inputs.cargo-tools != '' shell: bash run: | - cargo install ${{ inputs.cargo-tools }} 2>/dev/null || true # Suppress the "binary `xyz` already exists in destination" error + # Sometimes without the `--force` options the installed binaries are not found by cargo + # leading to error such as: `error: no such command: `my-tool`` + cargo binstall --force --no-confirm ${{ inputs.cargo-tools }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e32b94dd5a..21f27e64e82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -122,17 +122,17 @@ jobs: uses: ./.github/workflows/actions/toolchain-and-cache with: cache-version: ${{ secrets.CACHE_VERSION }} - cargo-tools: cargo2junit + cargo-tools: cargo-nextest + + - name: Build tests + run: cargo nextest run --no-run ${{ matrix.test-args }} - name: Run tests shell: bash run: | - set -o pipefail && \ - cargo test --no-fail-fast ${{ matrix.test-args }} - # TODO: Previous command that uses unstable options which are not supported anymore in stable toolchain - #cargo test --no-fail-fast ${{ matrix.test-args }} \ - # -- -Z unstable-options --format json --report-time \ - # | tee >(cargo2junit > test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }}.xml) + cargo nextest run --profile ci ${{ matrix.test-args }} + # Rename junit file to include runner info + mv target/nextest/ci/tests-result.junit.xml test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }}.xml - name: Upload Tests Results uses: actions/upload-artifact@v3 @@ -140,7 +140,7 @@ jobs: with: name: test-results${{ matrix.artifact-suffix }}-${{ runner.os }}-${{ runner.arch }} path: | - ./**/test-results-*.xml + ./test-results-*.xml check: runs-on: ubuntu-22.04 @@ -232,9 +232,7 @@ jobs: if-no-files-found: error publish-tests-results: - # TODO: reactivate when cargo test errors export to json works in stable version - #if: success() || failure() - if: false + if: success() || failure() runs-on: ubuntu-22.04 needs: - test