Skip to content

track_bundle_size_comment_pr #984

track_bundle_size_comment_pr

track_bundle_size_comment_pr #984

name: track_bundle_size_comment_pr
on:
workflow_run:
workflows: ["track_bundle_size"]
types:
- completed
permissions:
pull-requests: write
jobs:
track_bundle_size_comment_pr:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: 'Download trackBundleSize.md and prNumber.txt'
uses: actions/github-script@v6
with:
script: |
const ART_1 = "trackBundleSize.md";
const ART_2 = "prNumber.txt";
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
async function downloadArt(artName) {
var fs = require('fs');
var matchArtifact = artifacts.data.artifacts.find((artifact) => {
return artName === artifact.name;
});
if (matchArtifact) {
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/' + artName + '.zip', Buffer.from(download.data));
return true;
} else {
return false;
}
}
const [a1found, a2found] = await Promise.all([
downloadArt(ART_1),
downloadArt(ART_2),
]);
if (!a1found) {
core.setFailed('Unable to find artifact: ' + ART_1);
} else if (!a2found) {
core.setFailed('Unable to find artifact: ' + ART_2);
}
- run: unzip trackBundleSize.md.zip
- run: unzip prNumber.txt.zip
- name: 'Extract prNumber.txt'
uses: actions/github-script@v6
id: extractPrNumber
with:
script: |
return Number(require('fs').readFileSync('./prNumber.txt'));
- name: 'Find Prev. Comment'
uses: peter-evans/find-comment@v2
id: findPrevComment
with:
issue-number: ${{ steps.extractPrNumber.outputs.result }}
comment-author: 'github-actions[bot]'
body-includes: 'Generated by: track-bundle-size'
- name: Add comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.findPrevComment.outputs.comment-id }}
issue-number: ${{ steps.extractPrNumber.outputs.result }}
body-path: ./trackBundleSize.md
edit-mode: replace