Code Coverage (llvm-cov) #115
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code Coverage (llvm-cov) | |
on: | |
schedule: | |
- cron: "0 1 * * *" # every day at 1am (UTC) | |
workflow_dispatch: | |
jobs: | |
llvm-cov: | |
name: Generate code coverage | |
runs-on: self-hosted | |
timeout-minutes: 180 | |
env: | |
# Don't emit giant backtraces in the CI logs. | |
RUST_BACKTRACE: short | |
# Rustup | |
RUSTUP_MAX_RETRIES: 10 | |
# Cargo | |
CARGO_TERM_COLOR: always | |
CARGO_INCREMENTAL: 0 | |
# Find a good balance between runtime performance and accurate code coverage analysis. | |
CARGO_PROFILE_TEST_OPT_LEVEL: 1 | |
CARGO_PROFILE_TEST_DEBUG: false | |
CARGO_PROFILE_TEST_DEBUG_ASSERTIONS: false | |
CARGO_PROFILE_TEST_OVERFLOW_CHECKS: false | |
CARGO_PROFILE_TEST_LTO: off | |
CARGO_PROFILE_TEST_CODEGEN_UNITS: 1 | |
# Allow more retries for network requests in cargo (downloading crates) and | |
# rustup (installing toolchains). This should help to reduce flaky CI failures | |
# from transient network timeouts or other issues. | |
CARGO_NET_RETRY: 10 | |
steps: | |
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # pin@v4 | |
- uses: bmwill/rust-cache@fb63fcd7a959767755b88b5af2f5cbf65fb8a127 # pin@v1 | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@125e82eef6e60d2b0c20d4d1f4cf81db37f68bf3 # pin@cargo-llvm-cov | |
- name: Install nextest | |
uses: taiki-e/install-action@7e58f89e24a544d88f7a74c6eed8a3df3fd4c658 # pin@nextest | |
- name: Set Swap Space | |
uses: actionhippie/swap-space@v1 | |
with: | |
size: 256G | |
- name: Install llvm-tools | |
run: | | |
TOOLCHAIN=$(rustup show active-toolchain | cut -d ' ' -f 1) | |
rustup component add llvm-tools --toolchain "$TOOLCHAIN" | |
LLVM_PROFDATA="$HOME/.rustup/toolchains/$TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata" | |
if [ -x "$LLVM_PROFDATA" ]; then | |
$LLVM_PROFDATA --version | |
echo "LLVM_PROFDATA=$LLVM_PROFDATA" >> $GITHUB_ENV | |
else | |
echo "Error: llvm-profdata not found at $LLVM_PROFDATA, or is not executable." | |
exit 1 | |
fi | |
- name: Run code coverage (nextest) | |
run: | | |
set +e | |
IOTA_SKIP_SIMTESTS=1 cargo llvm-cov --ignore-run-fail --no-report nextest -vv | |
find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 $LLVM_PROFDATA merge \ | |
--failure-mode=warn \ | |
--sparse \ | |
--output target/nextest.profdata | |
set -e | |
if [ $? -ne 0]; then | |
echo "Error detected despite `--ignore-run-fail`. Trying to salvage the situation:" | |
echo "Scanning for corrupted .profraw files. This might take a while." | |
find target/llvm-cov-target -name '*.profraw' | while read file; do | |
if ! "$LLVM_PROFDATA" show "$file" > /dev/null 2>&1; then | |
echo "$file: corruped -> removing" | |
rm "$file" | |
else | |
echo "$file: good" | |
fi | |
done | |
find target/llvm-cov-target -name '*.profraw' -print0 | xargs -0 $LLVM_PROFDATA merge \ | |
--failure-mode=warn \ | |
--sparse \ | |
--output target/nextest.profdata | |
fi | |
[ -s "target/nextest.profdata" ] || exit 1 | |
- name: Run code coverage (simtest) | |
run: | | |
git clean -fd | |
set +e | |
./scripts/simtest/simtest-cov.sh | |
set -e | |
if [ ! -s "target/simtest.profdata" ]; then | |
echo "🚨 Warning 🚨: Collecting simtest coverage failed." | |
exit 0 | |
fi | |
- name: Create report (lcov.info) | |
run: | | |
cd target | |
if [ -s "simtest.profdata" ]; then | |
$LLVM_PROFDATA merge --failure-mode=warn --sparse nextest.profdata simtest.profdata --output merged.profdata | |
else | |
mv nextest.profdata merged.profdata | |
fi | |
[ -s "merged.profdata" ] || exit 1 | |
LLVM_PROFILE_FILE="merged.profdata" cargo llvm-cov report \ | |
--lcov \ | |
--output-path lcov.info \ | |
--ignore-filename-regex 'external-crates/.*' | |
echo "Removing absolute path prefix: ${{ github.workspace }} from report." | |
sed --in-place "s#${{ github.workspace }}#.#g" lcov.info | |
- name: Backup report | |
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # pin@v4 | |
with: | |
name: lcov.info | |
path: target/lcov.info | |
if-no-files-found: error | |
retention-days: 30 | |
- name: Upload coverage to Coveralls | |
uses: coverallsapp/github-action@v2 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
path-to-lcov: target/lcov.info | |
flag-name: nextest+simtest | |
fail-on-error: true | |
- name: Upload coverage data to Codecov | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: target/lcov.info | |
flags: nextest+simtest | |
fail_ci_if_error: false | |
verbose: true |