Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage workflow #33

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/actions/coverage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: 'Publish coverage report'
description: 'Create or update PR comment with coverage report'

inputs:
coverage:
description: The coverage report to publish
required: true

runs:
using: 'node16'
main: 'index.js'
16 changes: 16 additions & 0 deletions .github/actions/coverage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const core = require('@actions/core');
const fs = require('fs');

const inputs = {
coverage: core.getInput('coverage'),
target: core.getInput('target'),
};


(async () => {
const { updateComment } = require("../../utils/github");

const data = fs.readFileSync(inputs.coverage, { encoding: 'utf8', flag: 'r' });
await updateComment(inputs.target, data);
})();

21 changes: 21 additions & 0 deletions .github/actions/node-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: "Cache Node modules"
description: "Cache Node modules"

runs:
using: "composite"
steps:
- name: Restore node modules from cache
id: cache-nodemodules
uses: actions/cache/restore@v3
with:
# cache whole node_modules instead of ./npm, means `npm ci` will be skipped if cache hit, https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/
path: ./node_modules
key: ${{ runner.os }}-nodemodules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-nodemodules-

- name: Install dependencies
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
shell: bash
run: yarn install --ignore-scripts
48 changes: 48 additions & 0 deletions .github/utils/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 REPORT_SUFFIX = `${EOL}For a full HTML report run: \`forge coverage --report lcov && genhtml --ignore-errors category --branch-coverage --output-dir coverage lcov.info\``
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) {
await updateComment(comment.id, REPORT_TITLE + report + REPORT_SUFFIX );
} else {
await createComment(REPORT_TITLE + report + REPORT_SUFFIX);
}
}
54 changes: 54 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Coverage Report

on:
pull_request:

env:
FOUNDRY_PROFILE: ci
GITHUB_TOKEN: ${{ secrets.PLATFORM_SA_GITHUB_TOKEN }}

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Restore node modules from cache
uses: ./.github/actions/node-cache

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

# `forge coverage` doesn't have an `exclude-path` flag.
# See open issue: https://github.com/foundry-rs/foundry/issues/2988
# We manually exclude output for the src/test directory, as well as
# the 'Total' row which would be askew with out the full data set.
- name: Run Forge coverage
run: |
forge coverage --report summary | grep -v "src/test" | grep -v "| Total" > ./coverage.out
jp-imx marked this conversation as resolved.
Show resolved Hide resolved
id: coverage

- name: Debug coverage report
run: |
cat ./coverage.out

- name: Publish report
uses: ./.github/actions/coverage
with:
coverage: ./coverage.out
target: 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
Loading
Loading