-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add code coverage * use update comment * add rpc for integ
- Loading branch information
1 parent
0c15cca
commit 6838110
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
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" | ||
env: | ||
FOUNDRY_RPC_URL: '${{ secrets.RPC_URL }}' | ||
|
||
- name: Check coverage is updated | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const fs = require('fs'); | ||
const file = "coverage.txt" | ||
if(!fs.existsSync(file)) { | ||
console.log("Nothing to check"); | ||
return | ||
} | ||
const currentCoverage = fs.readFileSync(file, "utf8").trim(); | ||
const newCoverage = (`${{ steps.coverage.outputs.COVERAGE }}`).trim(); | ||
if (newCoverage != currentCoverage) { | ||
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 {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 output = `${{ steps.coverage.outputs.COVERAGE }}`; | ||
const commentBody = `Forge code coverage:\n${output}\n`; | ||
if (botComment) { | ||
github.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: botComment.id, | ||
body: commentBody | ||
}) | ||
} else { | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: commentBody | ||
}); | ||
} |