circuitpython/.github/workflows/code_size_comment.yml
David Lechner 5608226cfd github/workflows: Cancel when branch is updated.
This adds a concurrency section to all github workflows to cancel any
in progress workflow when a branch is updated. This should cancel any
ongoing or queued workflows, e.g. when a pull request is updated.

Signed-off-by: David Lechner <david@pybricks.com>
2022-12-14 13:42:50 +11:00

76 lines
2.2 KiB
YAML

name: Code size comment
on:
workflow_run:
workflows: [Check code size]
types: [completed]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
comment:
runs-on: ubuntu-20.04
steps:
- name: 'Download artifact'
id: download-artifact
uses: actions/github-script@v6
with:
result-encoding: string
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) {
console.log('no matching artifact found');
console.log('result: "skip"');
return 'skip';
}
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));
console.log('artifact downloaded to `code-size-report.zip`');
console.log('result: "ok"');
return 'ok';
- name: 'Unzip artifact'
if: steps.download-artifact.outputs.result == 'ok'
run: unzip code-size-report.zip
- name: Post comment to pull request
if: steps.download-artifact.outputs.result == 'ok'
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')}
\`\`\`
`,
});