summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2022-03-30 11:32:04 -0500
committerDamien George <damien@micropython.org>2022-11-29 11:36:28 +1100
commit1b774b373eb7fafebaa43adf9e086a690461201d (patch)
treee2acb51613f0af169c15eedc7b2d24c4c685258c
parentd5181034f2daa11199a1785e391c0fa8eb672de3 (diff)
github/workflows: Comment on code size change instead of failing CI.
This changes the code size workflow to post a comment on pull requests with the code size report. It also removes the error threshold so that the test won't fail if code size increases. Allowable code size changes are subjective, so shouldn't cause CI to fail. In addition, failing CI tests can cause other hooks like code coverage reports to be suppressed, so this fixes that problem as well. Fixes issue #8464. Signed-off-by: David Lechner <david@pybricks.com>
-rw-r--r--.github/workflows/code_size.yml16
-rw-r--r--.github/workflows/code_size_comment.yml64
2 files changed, 79 insertions, 1 deletions
diff --git a/.github/workflows/code_size.yml b/.github/workflows/code_size.yml
index 3811d9134..d4f8b195a 100644
--- a/.github/workflows/code_size.yml
+++ b/.github/workflows/code_size.yml
@@ -24,4 +24,18 @@ jobs:
- name: Build
run: source tools/ci.sh && ci_code_size_build
- name: Compute code size difference
- run: tools/metrics.py diff --error-threshold 0 ~/size0 ~/size1
+ run: tools/metrics.py diff ~/size0 ~/size1 | tee > diff
+ - name: Save PR number
+ if: github.event_name == 'pull_request'
+ env:
+ PR_NUMBER: ${{ github.event.number }}
+ run: echo $PR_NUMBER > pr_number
+ - name: Upload diff
+ if: github.event_name == 'pull_request'
+ uses: actions/upload-artifact@v3
+ with:
+ name: code-size-report
+ path: |
+ diff
+ pr_number
+ retention-days: 1
diff --git a/.github/workflows/code_size_comment.yml b/.github/workflows/code_size_comment.yml
new file mode 100644
index 000000000..100e82f82
--- /dev/null
+++ b/.github/workflows/code_size_comment.yml
@@ -0,0 +1,64 @@
+name: Code size comment
+
+on:
+ workflow_run:
+ workflows: [Check code size]
+ types: [completed]
+
+jobs:
+ comment:
+ runs-on: ubuntu-20.04
+ steps:
+ - name: 'Download artifact'
+ id: download-artifact
+ uses: actions/github-script@v6
+ with:
+ script: |
+ const fs = require('fs');
+
+ const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ run_id: context.payload.workflow_run.id,
+ });
+
+ const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
+ return artifact.name == "code-size-report"
+ });
+
+ if (matchArtifact.length === 0) {
+ return false;
+ }
+
+ const download = await github.rest.actions.downloadArtifact({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ artifact_id: matchArtifact[0].id,
+ archive_format: 'zip',
+ });
+
+ fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/code-size-report.zip`, Buffer.from(download.data));
+
+ return true;
+ - name: 'Unzip artifact'
+ if: steps.download-artifact.outputs.result
+ run: unzip code-size-report.zip
+ - name: Post comment to pull request
+ if: steps.download-artifact.outputs.result
+ uses: actions/github-script@v6
+ with:
+ github-token: ${{secrets.GITHUB_TOKEN}}
+ script: |
+ const fs = require('fs');
+
+ github.rest.issues.createComment({
+ issue_number: Number(fs.readFileSync('pr_number')),
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: `Code size report:
+
+ \`\`\`
+ ${fs.readFileSync('diff')}
+ \`\`\`
+ `,
+ });