-
Notifications
You must be signed in to change notification settings - Fork 1
81 lines (68 loc) · 2.19 KB
/
coverage.yml
File metadata and controls
81 lines (68 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
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