name: Coverage
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
coverage:
runs-on: ubuntu-latest
outputs:
badge_ready: ${{ steps.badge.outcome == 'success' }}
steps:
- uses: actions/checkout@v4
- name: Install Rust coverage tools
run: rustup toolchain install stable --profile minimal --component llvm-tools-preview
- name: Select toolchain
run: rustup override set stable
- name: Fetch Rust dependencies
run: cargo fetch
- uses: taiki-e/install-action@cargo-llvm-cov
- name: Install badge JSON reader
run: sudo apt-get update -qq && sudo apt-get install -y -qq jq
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install pyNastran for independent OP2 output checks
run: python -m pip install pyNastran==1.4.1
- name: Measure Rust line coverage
run: bash scripts/coverage.sh python
- name: Render measured coverage badge
id: badge
if: ${{ always() && hashFiles('target/coverage-source-lines.json') != '' }}
run: bash scripts/coverage_badge.sh target/coverage-source-lines.json target/coverage.svg
- uses: actions/upload-artifact@v4
if: ${{ always() && steps.badge.outcome == 'success' }}
with:
name: rust-coverage
path: |
target/coverage.json
target/coverage-source-lines.json
target/coverage.lcov
target/coverage.svg
retention-days: 14
publish-badge:
needs: coverage
if: ${{ always() && github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.coverage.outputs.badge_ready == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: coverage-badge
- uses: actions/download-artifact@v4
with:
name: rust-coverage
path: /tmp/caexfer-coverage
- name: Publish latest measurement
env:
SOURCE_SHA: ${{ github.sha }}
run: |
# A newer main commit makes this run's percentage stale.
latest=$(git ls-remote origin refs/heads/main | cut -f1)
if [ "$latest" != "$SOURCE_SHA" ]; then
echo "A newer main commit exists; skipping this measurement."
exit 0
fi
cp /tmp/caexfer-coverage/coverage.svg coverage.svg
git add coverage.svg
if git diff --cached --quiet; then
echo "Coverage percentage is unchanged."
exit 0
fi
git -c user.name='github-actions[bot]' -c user.email='41898282+github-actions[bot]@users.noreply.github.com' commit -m "Update coverage for ${SOURCE_SHA:0:7}"
git push origin HEAD:coverage-badge