-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing task that comments with coverage report
- Loading branch information
Showing
3 changed files
with
101 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,54 @@ | ||
const { getOctokit, context } = require("@actions/github"); | ||
const { EOL } = require('os'); | ||
const githubToken = process.env.GITHUB_TOKEN; | ||
const octokit = githubToken && getOctokit(githubToken); | ||
|
||
const OWNER = 'immutable'; | ||
const REPO = 'zkevm-bridge-contracts'; | ||
const REPORT_TITLE = `# 📃CI Report${EOL}`; | ||
const pr = context.payload.number; | ||
|
||
const getExistingReportComment = async () => getExistingComment(REPORT_TITLE); | ||
|
||
const getExistingComment = async (head) => { | ||
const { data: comments } = await octokit.rest.issues.listComments({ | ||
owner: OWNER, | ||
repo: REPO, | ||
issue_number: pr, | ||
}); | ||
return comments.find(comment => comment.body.includes(head)); | ||
} | ||
|
||
const createComment = (report) => { | ||
return octokit.rest.issues.createComment({ | ||
owner: OWNER, | ||
repo: REPO, | ||
issue_number: pr, | ||
body: report | ||
}); | ||
} | ||
|
||
const updateComment = (id, report) => { | ||
return octokit.rest.issues.updateComment({ | ||
owner: OWNER, | ||
repo: REPO, | ||
comment_id: id, | ||
body: report | ||
}); | ||
} | ||
|
||
exports.updateComment = async (target, report) => { | ||
const comment = await getExistingReportComment(); | ||
if (comment) { | ||
const targetRegex = new RegExp(`(\\<details><summary><strong>${target}:)([\\s\\S]+?)(table\\>\\n<\\/details\\>)`); | ||
let newComment; | ||
if (targetRegex.test(comment.body)) { | ||
newComment = comment.body.replace(targetRegex, report); | ||
} else { | ||
newComment = comment.body + report; | ||
} | ||
await updateComment(comment.id, newComment); | ||
} else { | ||
await createComment(REPORT_TITLE + report); | ||
} | ||
} |
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,44 @@ | ||
name: Coverage Report | ||
|
||
on: [push] | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- 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 | ||
run: | | ||
echo "::set-output name=coverage::$(forge coverage --report summary > coverage.out)" | ||
id: coverage | ||
|
||
- name: Publish report | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const { updateComment } = require("../utils/github"); | ||
const report = | ||
await updateComment(${{ steps.coverage.outputs.coverage }}); | ||
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