From caf85fc62b06d0d7c6f878d94f93c12f364a1b7a Mon Sep 17 00:00:00 2001 From: Austin Gill Date: Wed, 25 Dec 2024 12:00:28 -0600 Subject: [PATCH] Add code coverage instrumentation to CI pipeline --- .github/workflows/lint.yml | 27 ++++++++++++++++++++++++--- .github/workflows/release.yml | 2 ++ README.md | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7cf6abf..27f2c53 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -51,13 +51,13 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: stable - components: clippy + components: clippy,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 + tool: cargo-nextest,cargo-llvm-cov - name: Build run: cargo build --release --all-targets --all-features - name: Clippy @@ -65,4 +65,25 @@ jobs: - name: Test run: | git fetch - cargo nextest run --release --all-targets --all-features + cargo llvm-cov --no-report nextest --release --all-targets --all-features + cargo llvm-cov report --cobertura --output-path coverage.xml + RATE="$(grep -o -m 1 -P '(?<=line-rate=").*?(?=")' coverage.xml)" + PERCENT="$(echo "$RATE * 100)/1" | bc)" + echo "$COVERAGE_PERCENT=$PERCENT" + echo "$COVERAGE_PERCENT=$PERCENT" >> $GITHUB_ENV + - name: Update coverage badge + uses: schneegans/dynamic-badges-action@v1.7.0 + 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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 675ba39..ab8fd38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/README.md b/README.md index ad2fa91..042b94d 100644 --- a/README.md +++ b/README.md @@ -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.