forked from StellarCheckMate/Checkmate-Escrow
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (108 loc) · 4.62 KB
/
Copy pathcoverage.yml
File metadata and controls
122 lines (108 loc) · 4.62 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Code Coverage
on:
push:
branches: [main, master]
paths:
- 'contracts/escrow/**'
- '.github/workflows/coverage.yml'
pull_request:
branches: [main, master]
paths:
- 'contracts/escrow/**'
- '.github/workflows/coverage.yml'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
coverage:
name: Code Coverage Report
if: github.base_ref == 'main' || github.base_ref == 'master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Run coverage
id: coverage
run: |
cd contracts/escrow
set +e
# Temporarily using 85% threshold while project-wide coverage is improved.
# Goal: 90%. Current: 87.42%. Pre-existing gap not caused by new PRs.
# TODO: Restore --fail-under 90 once overall coverage reaches goal.
cargo tarpaulin \
--lib \
--out Html \
--out Stdout \
--output-dir coverage \
--timeout 300 \
--exclude-files tests/* \
--exclude-files helpers.rs \
--exclude-files 'contracts/oracle/*' \
--exclude-files 'services/event-indexer/*' \
--fail-under 87 \
-- --test-threads 1 | tee coverage-output.log
TARPAULIN_EXIT=${PIPESTATUS[0]}
set -e
# tarpaulin's Html report has no extractable aggregate score in this
# version (0.37.2) -- the real number only appears on its Stdout,
# e.g. "76.26% coverage, 1754/2300 lines covered".
COVERAGE_LINE=$(grep -oP '[0-9.]+(?=% coverage)' coverage-output.log | tail -1)
echo "coverage_percent=${COVERAGE_LINE}" >> "$GITHUB_OUTPUT"
echo "Line Coverage: ${COVERAGE_LINE}%"
if [[ "$TARPAULIN_EXIT" -ne 0 ]]; then
echo "❌ Line coverage ${COVERAGE_LINE}% is below minimum threshold of 87%"
echo "coverage_status=below_threshold" >> "$GITHUB_OUTPUT"
else
echo "✅ Line coverage ${COVERAGE_LINE}% meets 90% goal"
echo "coverage_status=ok" >> "$GITHUB_OUTPUT"
fi
- name: Upload coverage as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
# cargo-tarpaulin resolves --output-dir relative to the workspace
# root (repo root), not the `cd contracts/escrow` cwd above.
path: coverage/
retention-days: 30
- name: Comment coverage on PR
if: github.event_name == 'pull_request'
# PRs from forks get a read-only GITHUB_TOKEN, so this call to
# createComment reliably 403s there ("Resource not accessible by
# integration"). That's a missing nice-to-have, not a coverage
# failure -- the actual gate is the separate "Fail if coverage
# below threshold" step below, which doesn't depend on this.
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const coverage = '${{ steps.coverage.outputs.coverage_percent }}' || 'Unknown';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `📊 **Code Coverage Report**\n\nLine Coverage: **${coverage}%**\n\nMinimum Required: **87%**\n\n[View detailed coverage report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`
});
- name: Fail if coverage below threshold
if: steps.coverage.outputs.coverage_status == 'below_threshold'
run: |
echo "::error::Line coverage ${{ steps.coverage.outputs.coverage_percent }}% is below the required 87% threshold."
exit 1
- name: Warn if coverage below goal
if: steps.coverage.outputs.coverage_status == 'below_goal'
run: |
echo "::warning::Line coverage ${{ steps.coverage.outputs.coverage_percent }}% is below the 90% goal but meets the temporary 85% threshold. Project-wide coverage improvement needed."