Skip to content

Commit 7131f75

Browse files
committed
feat: ci forge coverage
1 parent 3b8d801 commit 7131f75

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/forge-coverage.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
workflow_dispatch: {}
6+
7+
jobs:
8+
run-coverage:
9+
name: CI
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Load issue number
19+
uses: actions/github-script@v6
20+
id: get_issue_number
21+
with:
22+
script: |
23+
const pullRequests = await github.rest.repos.listPullRequestsAssociatedWithCommit({
24+
commit_sha: context.sha,
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
});
28+
29+
if (pullRequests.data.length > 0) {
30+
return pullRequests.data[0].number;
31+
} else {
32+
throw new Error('No associated pull request found.');
33+
}
34+
result-encoding: string
35+
36+
- name: Install dependencies
37+
run: |
38+
sudo apt-get install lcov
39+
id: lcov
40+
41+
- name: Install Foundry
42+
uses: foundry-rs/foundry-toolchain@v1
43+
with:
44+
version: nightly
45+
46+
- name: Run coverage
47+
run: FOUNDRY_PROFILE=ci forge coverage --report lcov
48+
env:
49+
RPC_MAINNET: ${{ secrets.RPC_MAINNET }}
50+
RPC_HOLESKY: ${{ secrets.RPC_HOLESKY }}
51+
52+
- name: Prune coverage report
53+
run: lcov --remove ./lcov.info -o ./lcov.info.pruned 'src/test/*' 'script/*' '*Storage.sol' --ignore-errors inconsistent
54+
55+
- name: Generate reports
56+
run: genhtml -o report ./lcov.info.pruned
57+
58+
- name: Upload coverage results
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: code-coverage-report
62+
path: report/*
63+
64+
- name: View and log coverage
65+
id: print_coverage
66+
run: |
67+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
68+
echo "comment_contents<<$EOF" >> $GITHUB_OUTPUT
69+
echo "$(lcov --list ./lcov.info.pruned --ignore-errors inconsistent)" >> $GITHUB_OUTPUT
70+
echo "$EOF" >> $GITHUB_OUTPUT
71+
- name: Log Coverage Report
72+
run: echo "${{ steps.print_coverage.outputs.comment_contents }}"

0 commit comments

Comments
 (0)