Skip to content

Commit

Permalink
Introducing task that comments with coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-imx committed Nov 13, 2023
1 parent 95ddd11 commit e33bafa
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/utils/github.js
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);
}
}
44 changes: 44 additions & 0 deletions .github/workflows/coverage.yml
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 }});
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ broadcast/DeployRootContracts.s.sol/2500/
broadcast/DeployChildContracts.s.sol/2501/

node_modules/

# MacOS
.DS_Store

0 comments on commit e33bafa

Please sign in to comment.