Merge pull request #229 from storytold/sonarcloud/bin-exe-paths

sonarcloud: let shard tests find workspace binaries by their build path
This commit is contained in:
FredApps authored and GitHub committed 2026-11-13 21:10:36 +01:00
commit cb96afc6e2
3 files changed
+135

No files matched your search

+29
View File
@@ -280,6 +280,9 @@ jobs:
# shellcheck disable=SC1090 # generated by cargo-llvm-cov at runtime
source <(cargo llvm-cov show-env --sh)
cargo nextest archive --workspace "${features[@]}" --archive-file nextest-archive.tar.zst
# env!("CARGO_BIN_EXE_<name>") compiles this target directory's absolute path into
# every test that runs a workspace binary; the shards link it to their extracted copy.
cargo metadata --format-version 1 --no-deps | jq -r .target_directory > target-dir.txt
- name: Record the toolchain that built the archive
run: |
rustc -vV | sed -n 's/^release: //p' > rustc-release.txt
@@ -289,6 +292,7 @@ jobs:
path: |
nextest-archive.tar.zst
rustc-release.txt
target-dir.txt
retention-days: 1
coverage:
@@ -385,12 +389,36 @@ jobs:
run: |
python3 scripts/fetch-pdf-test-fonts.py "$RUNNER_TEMP/craft-pdf-test-fonts"
echo "CRAFT_PDF_TEST_FONT_DIR=$RUNNER_TEMP/craft-pdf-test-fonts" >> "$GITHUB_ENV"
- name: Link the build's target directory to the extracted archive
# Tests that run a workspace binary through env!("CARGO_BIN_EXE_<name>") hold the build
# job's absolute target path, which nextest's NEXTEST_BIN_EXE_<name> remapping cannot
# change. nextest extracts the archive elsewhere, so without this link every such test
# fails with "No such file or directory" under coverage while it passes in the gate.
shell: bash
env:
NEXTEST_EXTRACT_DIR: ${{ runner.temp }}/nextest-archive
run: |
set -euo pipefail
target_dir="$(cat archive/target-dir.txt)"
if [[ "$target_dir" != /* || "$target_dir" == *$'\n'* || "$target_dir" == */../* ]]; then
echo "::error::archive/target-dir.txt must hold one absolute path, got '$target_dir'"
exit 1
fi
if [ -e "$target_dir" ] || [ -L "$target_dir" ]; then
echo "::error::$target_dir already exists, so it cannot be linked to the extracted archive"
exit 1
fi
mkdir -p "$(dirname "$target_dir")" "$NEXTEST_EXTRACT_DIR"
ln -s "$NEXTEST_EXTRACT_DIR/target" "$target_dir"
echo "$target_dir -> $NEXTEST_EXTRACT_DIR/target"
- name: Run this shard's tests
env:
# Each instrumented binary writes its profile here; the scan job merges them.
LLVM_PROFILE_FILE: ${{ github.workspace }}/profraw/shard-${{ matrix.shard }}-%p-%m.profraw
SHARD: ${{ matrix.shard }}
TOTAL_SHARDS: ${{ inputs.shards }}
# The previous step links the build's target directory here.
NEXTEST_EXTRACT_DIR: ${{ runner.temp }}/nextest-archive
run: |
mkdir -p profraw
# nextest exits 100 when tests fail. A red test must not hide the static analysis, so
@@ -399,6 +427,7 @@ jobs:
# shard that runs nothing would scan an empty coverage report.
rc=0
cargo nextest run --archive-file archive/nextest-archive.tar.zst \
--extract-to "$NEXTEST_EXTRACT_DIR" --extract-overwrite \
--partition "count:$SHARD/$TOTAL_SHARDS" --no-fail-fast || rc=$?
if [ "$rc" -ne 0 ] && [ "$rc" -ne 100 ]; then
echo "::error::nextest could not run shard $SHARD (exit $rc)"