Skip to content

feat: add code size and test coverage reporting to ci #2

feat: add code size and test coverage reporting to ci

feat: add code size and test coverage reporting to ci #2

Workflow file for this run

name: PR report
on:
pull_request:
branches:
- develop
jobs:
comment-pr-report:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: ./.github/workflows/setup-ci
- name: Run forge coverage
id: coverage
run: |
{
echo 'COVERAGE<<EOF'
forge coverage | grep '^|'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Get new contract sizes
id: newsizes
run: |
{
echo 'NEWSIZES<<EOF'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|'
echo EOF
} >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v3
with:
ref: develop
submodules: recursive
- name: Get old contract sizes
id: oldsizes
run: |
{
echo 'OLDSIZES<<EOF'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Get sizes diff
id: diffsizes
run: |
{
echo 'DIFFSIZES<<EOF'
echo "${{ steps.newsizes.outputs.NEWSIZES }}" > newsizes.txt
echo "${{ steps.oldsizes.outputs.OLDSIZES }}" > oldsizes.txt
diff -U 99999999 oldsizes.txt newsizes.txt | grep -e '^ |' -e '^+|' -e '^-|' || true
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Comment on PR
id: comment
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {data: comments} = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => comment.user.id === 41898282)
const coverageOutput = `${{ steps.coverage.outputs.COVERAGE }}`;
const sizeDiffOutput = `${{ steps.diffsizes.outputs.DIFFSIZES }}`;
const newSizesOuput = `${{ steps.newsizes.outputs.NEWSIZES }}`;
const sizesContent = (sizeDiffOutput.trim().length === 0) ? newSizesOuput : sizeDiffOutput;
const commentBody = `Contract sizes:\n\`\`\`diff\n${sizesContent}\n\`\`\`\nCode coverage:\n${coverageOutput}\n`;
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
}