comment-pr #1575
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: comment-pr | |
| on: | |
| workflow_run: | |
| workflows: ["sv-tests-ci"] | |
| types: | |
| - completed | |
| jobs: | |
| Comment: | |
| permissions: | |
| pull-requests: write | |
| name: Comment | |
| runs-on: [ubuntu-latest] | |
| if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Download artifacts | |
| id: get-artifacts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: ${{ github.event.workflow_run.id }}, | |
| }); | |
| var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "tests_summary" | |
| })[0]; | |
| var download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| core.setOutput('artifact_id', matchArtifact.id); | |
| var fs = require('fs'); | |
| fs.writeFileSync('${{github.workspace}}/tests_summary.zip', Buffer.from(download.data)); | |
| - name: Unpack artifacts | |
| run: | | |
| unzip tests_summary.zip | |
| cat ./tests_summary.md | |
| - name: Generate and append artifacts link | |
| run: | | |
| ARTIFACT_ID=${{ steps.get-artifacts.outputs.artifact_id}} | |
| ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/$ARTIFACT_ID" | |
| MD_URL="[Download an archive containing all the details]($ARTIFACT_URL)" | |
| echo -e "\n\n$MD_URL" >> tests_summary.md | |
| - name: Show summary | |
| run: | | |
| cat tests_summary.md > $GITHUB_STEP_SUMMARY | |
| - name: Prepare comment | |
| id: get-comment-body | |
| run: | | |
| { | |
| echo "body<<EOF" | |
| cat tests_summary.md | |
| echo EOF | |
| } >> $GITHUB_OUTPUT | |
| - name: Get PR number | |
| id: get-pr-number | |
| run: | | |
| num=$(cat ./issue_num) | |
| echo "num=$num" >> $GITHUB_OUTPUT | |
| - name: Post comment | |
| uses: KeisukeYamashita/create-comment@v1 | |
| with: | |
| number: ${{ steps.get-pr-number.outputs.num }} | |
| check-only-first-line: "true" | |
| unique: "true" | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| comment: ${{ steps.get-comment-body.outputs.body }} |