Write file #43
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: code coverage | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
comment-forge-coverage: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install foundry | |
uses: foundry-rs/foundry-toolchain@v1 | |
with: | |
version: nightly | |
- name: Run Forge build | |
run: | | |
forge --version | |
forge build --sizes | |
id: build | |
- name: Run forge coverage | |
id: coverage | |
run: | | |
{ | |
echo 'COVERAGE<<EOF' | |
forge coverage | grep -v 'test/' | tail -n +6 | |
echo EOF | |
} >> "$GITHUB_OUTPUT" | |
- name: Check coverage is updated | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const output = `${{ steps.coverage.outputs.COVERAGE }}`; | |
const file = fs.readFileSync("coverage.txt", "utf8").trim(); | |
const currentCoverageFile = `${file}`.trim(); | |
if (output != currentCoverageFile) { | |
core.setFailed('Code coverage not updated. Run: forge coverage | grep -v 'test/' | tail -n +6 > coverage.txt'); | |
} | |
- name: Comment on PR | |
id: comment | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const output = `${{ steps.coverage.outputs.COVERAGE }}`; | |
const commentBody = `Forge code coverage:\n${output}\n`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: commentBody | |
}); |