Support forge coverage
in CI
#7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: coverage | |
on: | |
pull_request: | |
jobs: | |
forge-coverage-comment: | |
name: Forge coverage and comment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Install Foundry | |
uses: foundry-rs/foundry-toolchain@v1 | |
with: | |
version: nightly | |
# install dependency | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: 'yarn' | |
- run: yarn | |
- name: Run forge coverage | |
id: coverage-debug | |
run: forge coverage --ir-minimum --fuzz-runs 1 | |
# ignore test, script and total line | |
- name: Run forge coverage | |
id: coverage | |
run: | | |
{ | |
echo 'COVERAGE<<EOF' | |
forge coverage --ir-minimum | grep '^|' | grep -Ev 'test/|script/|Total' | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
# 41898282 is github-actions bot id: https://github.com/marketplace/actions/bot-details | |
- name: Comment forge coverage report on PR | |
id: comment | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const {data: comments} = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}) | |
const botComment = comments.find(comment => comment.user.id === 41898282) | |
const coverageReport = `${{ steps.coverage.outputs.COVERAGE }}`; | |
if (botComment) { | |
github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body: coverageReport | |
}) | |
} else { | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: coverageReport | |
}); | |
} |