Skip to content

Commit

Permalink
feat: ci forge coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
0xClandestine committed Jan 7, 2025
1 parent 865b490 commit ac9d34b
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/forge-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Coverage

on:
push:
workflow_dispatch: {}

jobs:
run-coverage:
name: CI
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Load issue number
uses: actions/github-script@v6
id: get_issue_number
with:
script: |
const pullRequests = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
});
if (pullRequests.data.length > 0) {
return pullRequests.data[0].number;
} else {
throw new Error('No associated pull request found.');
}
result-encoding: string

- name: Install dependencies
run: |
sudo apt-get install lcov
id: lcov

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run coverage
run: FOUNDRY_PROFILE=ci forge coverage --report lcov
env:
RPC_MAINNET: ${{ secrets.RPC_MAINNET }}
RPC_HOLESKY: ${{ secrets.RPC_HOLESKY }}

- name: Prune coverage report
run: lcov --remove ./lcov.info -o ./lcov.info.pruned 'src/test/*' 'script/*' '*Storage.sol' --ignore-errors inconsistent

- name: Generate reports
run: genhtml -o report ./lcov.info.pruned

- name: Upload coverage results
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: report/*

- name: View and log coverage
id: print_coverage
run: |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "comment_contents<<$EOF" >> $GITHUB_OUTPUT
echo "$(lcov --list ./lcov.info.pruned --ignore-errors inconsistent)" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Log Coverage Report
run: echo "${{ steps.print_coverage.outputs.comment_contents }}"

0 comments on commit ac9d34b

Please sign in to comment.