Skip to content

Commit

Permalink
Add code coverage instrumentation to CI pipeline
Browse files Browse the repository at this point in the history
Additionally, split apart build and test CI jobs. Originally, the tests
required the binary produced by 'cargo build', but now that that's
fixed, and the tests require code coverage instrumentation (forcing a
rebuild anyways), it's better to do the build and test in parallel.
  • Loading branch information
Notgnoshi committed Dec 25, 2024
1 parent 189b8c4 commit cc1416c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
47 changes: 41 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,50 @@ jobs:
components: clippy
- name: Setup Rust cache
uses: swatinem/rust-cache@v2
- name: Build
run: cargo build --all-targets --all-features
- name: Clippy
run: cargo clippy --no-deps --all-targets --all-features

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: llvm-tools-preview
- name: Setup Rust cache
uses: swatinem/rust-cache@v2
- name: Setup nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest
- name: Build
run: cargo build --release --all-targets --all-features
- name: Clippy
run: cargo clippy --no-deps --release --all-targets --all-features
tool: cargo-nextest,cargo-llvm-cov
- name: Test
run: |
git fetch
cargo nextest run --release --all-targets --all-features
cargo llvm-cov --no-report nextest --all-targets --all-features
cargo llvm-cov report --cobertura --output-path coverage.xml
head coverage.xml
RATE="$(grep -o -m 1 -P '(?<=line-rate=").*?(?=")' coverage.xml | head -1)"
echo "RATE=$RATE"
PERCENT="$(echo "$RATE * 100)/1" | bc)"
echo "PERCENT=$PERCENT"
echo "$COVERAGE_PERCENT=$PERCENT" >> $GITHUB_ENV
- name: Update coverage badge
uses: schneegans/[email protected]
if: github.ref_name == github.event.repository.default_branch
with:
# https://github.com/Notgnoshi/herostratus/settings/secrets/actions
# https://github.com/settings/personal-access-tokens
# https://gist.github.com/Notgnoshi/b20aa388c90ca92aba6aa37ec55a7f12
# https://github.com/marketplace/actions/dynamic-badges
auth: ${{ secrets.HEROSTRATUS_COVERAGE_GIST_TOKEN }}
gistID: b20aa388c90ca92aba6aa37ec55a7f12
filename: herostratus-coverage.json
label: Code Coverage
message: "${{ env.COVERAGE_PERCENT }}%"
valColorRange: ${{ env.COVERAGE_PERCENT }}
minColorRange: 60
maxColorRange: 95
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
# https://github.com/Notgnoshi/herostratus/settings/secrets/actions
# https://github.com/settings/personal-access-tokens
token: ${{ secrets.HEROSTRATUS_RELEASE_TOKEN }}
- name: Validate SemVer Version
shell: bash # Explicitly setting the shell sets errexit and pipefail flags
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

![lint workflow](https://github.com/Notgnoshi/herostratus/actions/workflows/lint.yml/badge.svg?event=push)
![release workflow](https://github.com/Notgnoshi/herostratus/actions/workflows/release.yml/badge.svg?event=push)
![code coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Notgnoshi/b20aa388c90ca92aba6aa37ec55a7f12/raw/herostratus-coverage.json)

**Herostratus** _n._ **1.** An [ancient Greek](https://en.wikipedia.org/wiki/Herostratus) known for
seeking fame through crime and destruction. **2.** A Git repository achievements engine.
Expand Down

0 comments on commit cc1416c

Please sign in to comment.