Support changeset-driven versioning for non-Rust packages in a Cargo workspace #22
Workflow file for this run
This file contains hidden or 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: Coverage | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| coverage: | |
| name: Code Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install cargo-llvm-cov | |
| uses: taiki-e/install-action@cargo-llvm-cov | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.cargo/registry | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo index | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo build | |
| uses: actions/cache@v5 | |
| with: | |
| path: target | |
| key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Generate coverage | |
| run: cargo llvm-cov --workspace --all-features --json --output-path coverage.json | |
| - name: Extract coverage percentage | |
| id: coverage | |
| run: | | |
| COVERAGE=$(python3 -c " | |
| import json, sys | |
| data = json.load(open('coverage.json')) | |
| totals = data['data'][0]['totals']['lines'] | |
| pct = totals['percent'] | |
| print(f'{pct:.1f}') | |
| ") | |
| echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT" | |
| - name: Upload coverage artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: coverage-report | |
| path: coverage.json | |
| - name: Update coverage badge | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: schneegans/dynamic-badges-action@v1.7.0 | |
| with: | |
| auth: ${{ secrets.GIST_TOKEN }} | |
| gistID: ${{ secrets.COVERAGE_GIST_ID }} | |
| filename: cargo-changeset-coverage.json | |
| label: coverage | |
| message: ${{ steps.coverage.outputs.percentage }}% | |
| valColorRange: ${{ steps.coverage.outputs.percentage }} | |
| minColorRange: 50 | |
| maxColorRange: 90 |