-
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.
Introduced a workflow to calculate the test coverage of the codebase …
…and post it as a comment in the PR.
- Loading branch information
Showing
9 changed files
with
16,139 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,47 @@ | ||
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) { | ||
await updateComment(comment.id, REPORT_TITLE + report); | ||
} 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,50 @@ | ||
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 | ||
|
||
- name: Run Forge coverage | ||
run: | | ||
forge coverage --report summary > ./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.