name: Codecov
concurrency:
group: codecov-${{ github.ref_name }}
cancel-in-progress: true
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
permissions:
contents: read
checks: write
pull-requests: write
jobs:
coverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
TARPAULIN_VERSION: "0.32.8"
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
fetch-depth: 0
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 with:
cache: true
- name: Cache tarpaulin
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb with:
path: ~/.cargo/bin/cargo-tarpaulin
key: tarpaulin-${{ runner.os }}-${{ env.TARPAULIN_VERSION }}
restore-keys: |
tarpaulin-${{ runner.os }}-
- name: Install tarpaulin
run: |
if ! command -v cargo-tarpaulin &> /dev/null; then
cargo install cargo-tarpaulin --locked --version "${TARPAULIN_VERSION}"
fi
- name: Install just
uses: taiki-e/install-action@06203676c62f0d3c765be3f2fcfbebbcb02d09f5 with:
tool: just
- name: Install nextest
uses: taiki-e/install-action@06203676c62f0d3c765be3f2fcfbebbcb02d09f5 with:
tool: nextest
- name: Run tests with nextest (for JUnit XML)
run: |
# Note: We run tests twice in this workflow (nextest + tarpaulin).
# This is intentional and necessary because:
# 1. nextest: Fast parallel execution → high-quality JUnit XML for test analytics
# 2. tarpaulin: Instrumented execution → accurate code coverage metrics
# Trade-off: ~1-2 extra minutes of CI time for significantly better data quality.
# Using tarpaulin's experimental JUnit output would save time but produces
# less reliable test analytics data.
echo "::group::Running tests with nextest"
# Generate JUnit XML for Codecov Test Analytics
# JUnit path is configured in .config/nextest.toml [profile.ci.junit]
cargo nextest run --all-features --profile ci
echo "::endgroup::"
# Verify JUnit XML was generated at the expected location
# Nextest outputs to target/nextest/<profile>/<path-from-config>
if [ ! -f target/nextest/ci/test-results/junit.xml ]; then
echo "::error::target/nextest/ci/test-results/junit.xml not found"
exit 2
else
echo "::notice::Test results generated: $(wc -l < target/nextest/ci/test-results/junit.xml) lines"
fi
env:
RUST_BACKTRACE: 1
- name: Run coverage
run: |
# Create coverage directory with proper permissions
mkdir -p coverage
chmod 755 coverage
echo "::group::Running coverage"
# Use just coverage-ci for single source of truth
# Configuration is maintained in justfile to avoid duplication
just coverage-ci
echo "::endgroup::"
# Detailed sanity check: verify coverage report was generated
echo "::group::Coverage verification"
echo "Directory listing:"
ls -la coverage/ || echo "Coverage directory not found"
printf "\nSearching for XML files:\n"
find . -name "*.xml" -type f -ls 2>/dev/null || echo "No XML files found"
printf "\nSearching for cobertura files:\n"
find . -name "*cobertura*" -type f -ls 2>/dev/null || echo "No cobertura files found"
if [ ! -f coverage/cobertura.xml ]; then
echo "::error::coverage/cobertura.xml not found. Tarpaulin failed to generate XML output."
echo "::error::Check tarpaulin logs above for errors."
exit 2
else
coverage_bytes=$(wc -c < coverage/cobertura.xml)
coverage_newlines=$(wc -l < coverage/cobertura.xml)
coverage_lines_covered=$(
grep -oE 'lines-covered="[0-9]+"' coverage/cobertura.xml \
| head -n1 \
| cut -d'"' -f2 || true
)
coverage_lines_valid=$(
grep -oE 'lines-valid="[0-9]+"' coverage/cobertura.xml \
| head -n1 \
| cut -d'"' -f2 || true
)
coverage_line_rate=$(
grep -oE 'line-rate="[0-9.]+"' coverage/cobertura.xml \
| head -n1 \
| cut -d'"' -f2 || true
)
if [ -n "${coverage_lines_covered}" ] \
&& [ -n "${coverage_lines_valid}" ] \
&& [ -n "${coverage_line_rate}" ]; then
echo "::notice::Coverage report generated successfully:"
echo "::notice:: bytes=${coverage_bytes}, xml_newlines=${coverage_newlines}"
echo "::notice:: covered=${coverage_lines_covered}, valid=${coverage_lines_valid}"
echo "::notice:: rate=${coverage_line_rate}"
else
echo "::warning::Coverage report generated (${coverage_bytes} bytes),"
echo "::warning:: could not parse Cobertura metrics; XML newlines=${coverage_newlines}"
fi
fi
# Sanity: ensure benches/examples aren't present (defense-in-depth with .codecov.yml)
if command -v rg >/dev/null 2>&1; then
if rg -n '(^|/)(benches|examples)/' coverage/cobertura.xml; then
echo "::warning::benches/ or examples/ paths detected in coverage report"
fi
else
if grep -nE '(^|/)(benches|examples)/' coverage/cobertura.xml; then
echo "::warning::benches/ or examples/ paths detected in coverage report"
fi
fi
echo "::endgroup::"
env:
RUST_BACKTRACE: 1
DELAUNAY_PROPTEST_COVERAGE_LOGS: 1
- name: Upload coverage to Codecov
if: ${{ success() && hashFiles('coverage/cobertura.xml') != '' }}
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad with:
files: coverage/cobertura.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ success() && hashFiles('target/nextest/ci/test-results/junit.xml') != '' }}
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad with:
files: target/nextest/ci/test-results/junit.xml
flags: unittests
name: test-results
report_type: test_results
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codacy
if: ${{ success() && hashFiles('coverage/cobertura.xml') != '' }}
uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699 with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/cobertura.xml
language: rust
continue-on-error: true
- name: Archive coverage results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f if: always()
with:
name: coverage-report
path: coverage/
- name: Archive test results
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f if: always()
with:
name: test-results
path: target/nextest/ci/test-results/