-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (100 loc) · 3.24 KB
/
Copy pathcoverage.yml
File metadata and controls
120 lines (100 loc) · 3.24 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
name: Coverage Check
on:
pull_request:
env:
COVERAGE_SENSITIVITY_PERCENT: 1
MAINNET_RPC: ${{ secrets.MAINNET_RPC }}
SEPOLIA_RPC: ${{ secrets.SEPOLIA_RPC }}
jobs:
base-coverage:
name: Generate base coverage
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Restore base coverage cache
id: cache-base
uses: actions/cache@v4
with:
path: .coverage-base/lcov.info
key: coverage-base-${{ github.event.pull_request.base.sha }}
- name: Run base branch coverage
if: steps.cache-base.outputs.cache-hit != 'true'
run: yarn coverage
- name: Prepare cached base lcov
if: steps.cache-base.outputs.cache-hit != 'true'
run: |
mkdir -p .coverage-base
cp lcov.info .coverage-base/lcov.info
- name: Copy artifact file
run: cp .coverage-base/lcov.info base-lcov.info
- name: Upload base lcov as artifact
uses: actions/upload-artifact@v4
with:
name: base-lcov
path: base-lcov.info
check-coverage:
name: Check PR coverage
runs-on: ubuntu-latest
needs: base-coverage
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Download base lcov artifact
uses: actions/download-artifact@v4
with:
name: base-lcov
path: .
- name: Run current branch coverage
run: yarn coverage
- name: Setup LCOV
uses: hrishikesh-kadam/setup-lcov@v1
# Updates the comment on every PR push
- name: Create a comment on the PR with the current branch coverage
id: new-coverage
if: hashFiles('lcov.info') != ''
uses: zgosalvez/github-actions-report-lcov@v4
with:
coverage-files: lcov.info
github-token: ${{ github.token }}
update-comment: true
- name: Compare previous coverage (against base branch)
run: |
if [ -f .coverage-base/lcov.info ]; then
old=$(lcov --summary .coverage-base/lcov.info 2>/dev/null | awk '/lines\.+:/ {print $2}' | tr -d '%')
else
old=0
fi
head="${{ steps.new-coverage.outputs.total-coverage }}"
[ -z "$head" ] && head=0
new=$(awk -v a="$head" -v b="${{ env.COVERAGE_SENSITIVITY_PERCENT }}" 'BEGIN{printf "%.2f", a+b}')
if awk "BEGIN {exit !($new < $old)}"; then
echo "Coverage decreased from $old to $new"; exit 1
fi