-
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.
Merge pull request #33 from immutable/jp/coverage-report-workflow
Coverage workflow
- Loading branch information
Showing
9 changed files
with
16,147 additions
and
373 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,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' |
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,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); | ||
})(); | ||
|
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,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 |
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,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); | ||
} | ||
} |
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 @@ | ||
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 "test/" | grep -v "| Total" > ./coverage.out | ||
id: coverage | ||
|
||
- name: Debug coverage report | ||
run: | | ||
cat ./coverage.out | ||
- name: Publish report | ||
uses: ./.github/actions/coverage | ||
with: | ||
coverage: ./coverage.out | ||
target: 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
Oops, something went wrong.