From 24ffee3fd6a2434a2f432403c54f9af9abe26acc Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 20 Aug 2024 20:55:18 +0300 Subject: [PATCH] ci: Use cargo nextest as the test runner and export junit reports Part-of: --- .config/nextest.toml | 6 ++++++ .gitlab-ci.yml | 25 ++++++++++++++++++++---- ci/run_windows_tests.ps1 | 42 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .config/nextest.toml diff --git a/.config/nextest.toml b/.config/nextest.toml new file mode 100644 index 00000000..dde5328c --- /dev/null +++ b/.config/nextest.toml @@ -0,0 +1,6 @@ +[profile.ci] +failure-output = "immediate-final" +fail-fast = false + +[profile.ci.junit] +path = "junit.xml" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b64907f2..6e831faf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -106,13 +106,24 @@ trigger: script: - rustc --version - CARGO_FLAGS="-j${FDO_CI_CONCURRENT:-$(nproc)} --locked --color=always --all --all-targets" + - new_report_dir="$CI_PROJECT_DIR/junit_reports" + - mkdir -p "$new_report_dir" + - cargo build $CARGO_FLAGS - - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo test $CARGO_FLAGS + - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo nextest run --profile=ci $CARGO_FLAGS + - mv "$CI_PROJECT_DIR/target/nextest/ci/junit.xml" "$new_report_dir/junit-tests-default.xml" + - cargo build $CARGO_FLAGS --all-features --exclude gst-plugin-gtk4 - - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo test $CARGO_FLAGS --all-features --exclude gst-plugin-gtk4 + - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo nextest run --profile=ci $CARGO_FLAGS --all-features --exclude gst-plugin-gtk4 + - mv "$CI_PROJECT_DIR/target/nextest/ci/junit.xml" "$new_report_dir/junit-tests-all.xml" + - cargo build $CARGO_FLAGS --no-default-features - - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo test $CARGO_FLAGS --no-default-features + - RUST_BACKTRACE=1 G_DEBUG=fatal_warnings cargo nextest run --profile=ci $CARGO_FLAGS --no-default-features + - mv "$CI_PROJECT_DIR/target/nextest/ci/junit.xml" "$new_report_dir/junit-tests-no-default.xml" + artifacts: + reports: + junit: "junit_reports/*.xml" test msrv: extends: @@ -392,7 +403,12 @@ coverage: script: - CARGO_FLAGS="-j${FDO_CI_CONCURRENT:-$(nproc)} --locked --color=always --all" - - cargo test $CARGO_FLAGS --all-features --exclude gst-plugin-gtk4 + - cargo nextest run --profile=ci $CARGO_FLAGS --all-features --exclude gst-plugin-gtk4 + + - new_report_dir="$CI_PROJECT_DIR/junit_reports" + - mkdir -p "$new_report_dir" + - mv "$CI_PROJECT_DIR/target/nextest/ci/junit.xml" "$new_report_dir/coverage-junit.xml" + # generate html report - mkdir -p coverage - grcov . --binary-path ./target/debug/ -s . -t html,cobertura --branch --ignore-not-existing --ignore "*target*" --ignore "*/build.rs" -o ./coverage/ @@ -403,6 +419,7 @@ coverage: paths: - 'coverage' reports: + junit: "junit_reports/*.xml" coverage_report: coverage_format: cobertura path: "coverage/cobertura.xml" diff --git a/ci/run_windows_tests.ps1 b/ci/run_windows_tests.ps1 index fd793b28..3ff197a1 100644 --- a/ci/run_windows_tests.ps1 +++ b/ci/run_windows_tests.ps1 @@ -37,12 +37,50 @@ function Run-Tests { $env:G_DEBUG="fatal_warnings" $env:RUST_BACKTRACE="1" - cargo test --no-fail-fast --color=always --workspace $local_exclude --all-targets $Features - + cargo nextest run --profile=ci --no-fail-fast --color=always --workspace $local_exclude --all-targets $Features if (!$?) { Write-Host "Tests failed" Exit 1 } + + Move-Junit -Features $Features +} + +function Move-Junit { + param ( + $Features + ) + + if ($env:CI_PROJECT_DIR) { + $parent = $env:CI_PROJECT_DIR + } else { + $parent = $PWD.path + } + Write-Host "Parent directory: $parent" + + $new_report_dir = "$parent/junit_reports/" + If(!(test-path -PathType container $new_report_dir)) + { + New-Item -Path "$new_report_dir" -ItemType "directory" + if (!$?) { + Write-Host "Failed to create directory: $new_report_dir" + Exit 1 + } + } + + if ($Features -eq "--all-features") { + $suffix = "all" + } elseif ($Features -eq "--no-default-features") { + $suffix = "no-default" + } else { + $suffix = "default" + } + + Move-Item "$parent/target/nextest/ci/junit.xml" "$new_report_dir/junit-$suffix.xml" + if (!$?) { + Write-Host "Failed to move junit file" + Exit 1 + } } foreach($feature in $features_matrix) {