Skip to content

quality_gate_comment_pr #1328

quality_gate_comment_pr

quality_gate_comment_pr #1328

name: quality_gate_comment_pr
on:
workflow_run:
workflows: ["quality_gate"]
types:
- completed
permissions:
pull-requests: write
env:
REPORT_1_ARTIFACT: qualityGateReports_file1
REPORT_2_ARTIFACT: qualityGateReports_file2
REPORT_CONCATENATED: qualityGateReports_concat
PR_NUM_ARTIFACT: qualityGateReports_pr
COMMENT_AUTHOR: 'github-actions[bot]'
COMMENT_TAG: '<!--- This comment was added by: qualityGateCommentPR.yml -->'
jobs:
quality_gate_comment_pr:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
#
# Find artifacts
#
- name: 'Download the artifacts'
uses: actions/github-script@v7
with:
script: |
var ARTIFACT_NAMES = [
'${{ env.REPORT_1_ARTIFACT }}',
'${{ env.REPORT_2_ARTIFACT }}',
'${{ env.PR_NUM_ARTIFACT }}'
];
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 {
core.setFailed('Unable to find artifact: ' + artName);
return false;
}
}
await Promise.all(ARTIFACT_NAMES.map((artName) => downloadArt(artName)));
#
# Unzip artifacts
#
- name: Unzip report 1
run: |
unzip -p ${{ env.REPORT_1_ARTIFACT }}.zip > ./${{ env.REPORT_1_ARTIFACT }}
- name: Unzip report 2
run: |
unzip -p ${{ env.REPORT_2_ARTIFACT }}.zip > ./${{ env.REPORT_2_ARTIFACT }}
- name: Unzip PR number
run: |
unzip -p ${{ env.PR_NUM_ARTIFACT }}.zip > ./${{ env.PR_NUM_ARTIFACT }}
#
#
#
#
- name: Read PR number from ${{ env.PR_NUM_ARTIFACT }}
uses: actions/github-script@v7
id: readPrNumber
with:
script: |
return Number(require('fs').readFileSync('./${{ env.PR_NUM_ARTIFACT }}').toString());
#
#
#
- name: Concatenate reports
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const SEPARATOR = "\n\n---\n";
const contentArr = [
fs.readFileSync('./${{ env.REPORT_1_ARTIFACT }}'),
fs.readFileSync('./${{ env.REPORT_2_ARTIFACT }}'),
];
const concatenated = contentArr.join(SEPARATOR);
const commentContent = concatenated + '\n' + '${{ env.COMMENT_TAG }}';
fs.writeFileSync('./${{ env.REPORT_CONCATENATED }}', commentContent);
#
# Update comment: track-bundle-size
#
- id: prevCommentId
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ steps.readPrNumber.outputs.result }}
comment-author: '${{env.COMMENT_AUTHOR}}'
body-includes: '${{env.COMMENT_TAG}}'
- uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.prevCommentId.outputs.comment-id }}
issue-number: ${{ steps.readPrNumber.outputs.result }}
body-path: ${{ env.REPORT_CONCATENATED }}
edit-mode: replace