|
| 1 | +--- |
| 2 | +name: Comment output on PR |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_run: |
| 6 | + workflows: ["Vanagon Component Diff"] |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +jobs: |
| 11 | + upload: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 14 | + steps: |
| 15 | + - name: 'Download artifacts' |
| 16 | + |
| 17 | + with: |
| 18 | + script: | |
| 19 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 20 | + owner: context.repo.owner, |
| 21 | + repo: context.repo.repo, |
| 22 | + run_id: ${{github.event.workflow_run.id }}, |
| 23 | + }); |
| 24 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 25 | + return artifact.name == "artifacts" |
| 26 | + })[0]; |
| 27 | + var download = await github.actions.downloadArtifact({ |
| 28 | + owner: context.repo.owner, |
| 29 | + repo: context.repo.repo, |
| 30 | + artifact_id: matchArtifact.id, |
| 31 | + archive_format: 'zip', |
| 32 | + }); |
| 33 | + var fs = require('fs'); |
| 34 | + fs.writeFileSync('${{github.workspace}}/artifacts.zip', Buffer.from(download.data)); |
| 35 | + fs.writeFileSync('./artifactid', matchArtifact.id) |
| 36 | +
|
| 37 | + - name: 'Unzip artifacts' |
| 38 | + run: unzip artifacts.zip |
| 39 | + |
| 40 | + - name: 'Check comment limits' |
| 41 | + run: | |
| 42 | + chars=$(cat ./text | wc -m) |
| 43 | + if ((chars > 65300)); then |
| 44 | + # Trim output to 65300 characters |
| 45 | + truncate -s 65300 ./text |
| 46 | +
|
| 47 | + # Close all code blocks |
| 48 | + nr_code_keyword=$(cat ./text | grep '\`\`\`' | wc -l) |
| 49 | + if [ $((nr_code_keyword%2)) -ne 0 ];then |
| 50 | + echo >> ./text |
| 51 | + echo "\`\`\`" >> ./text |
| 52 | + fi |
| 53 | +
|
| 54 | + # Close all collapsible blocks |
| 55 | + nr_open_details=$(cat ./text | grep '<details>' | wc -l) |
| 56 | + nr_closed_details=$(cat ./text | grep '</details>' | wc -l) |
| 57 | + for i in `seq $(($nr_open_details-$nr_closed_details))`; do echo >> ./text; echo "</details>" >> ./text;done |
| 58 | +
|
| 59 | + # Output artifact info |
| 60 | + echo >> ./text |
| 61 | + echo "# ..." >> ./text |
| 62 | + echo >> ./text |
| 63 | + printf "Comment size limit reached. " >> ./text |
| 64 | + echo "Please download full artifacts from [here](https://github.com/${{ github.repository }}/suites/${{github.event.workflow_run.check_suite_id }}/artifacts/$(cat ./artifactid))." >> ./text |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: 'Add comment' |
| 68 | + uses: actions/github-script@v3 |
| 69 | + with: |
| 70 | + script: | |
| 71 | + var fs = require('fs'); |
| 72 | + var issue_number = Number(fs.readFileSync('./nr')); |
| 73 | + var issue_text = String(fs.readFileSync('./text')); |
| 74 | + await github.issues.createComment({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + issue_number: issue_number, |
| 78 | + body: issue_text |
| 79 | + }); |
0 commit comments