|
| 1 | +name: PR comment (mypy_primer) |
| 2 | + |
| 3 | +on: # zizmor: ignore[dangerous-triggers] |
| 4 | + workflow_run: |
| 5 | + workflows: [Run mypy_primer] |
| 6 | + types: [completed] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + workflow_run_id: |
| 10 | + description: The mypy_primer workflow that triggers the workflow run |
| 11 | + required: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + comment: |
| 15 | + runs-on: ubuntu-24.04 |
| 16 | + permissions: |
| 17 | + pull-requests: write |
| 18 | + steps: |
| 19 | + - uses: dawidd6/action-download-artifact@v8 |
| 20 | + name: Download PR number |
| 21 | + with: |
| 22 | + name: pr-number |
| 23 | + run_id: ${{ github.event.workflow_run.id || github.event.inputs.workflow_run_id }} |
| 24 | + if_no_artifact_found: ignore |
| 25 | + allow_forks: true |
| 26 | + |
| 27 | + - name: Parse pull request number |
| 28 | + id: pr-number |
| 29 | + run: | |
| 30 | + if [[ -f pr-number ]] |
| 31 | + then |
| 32 | + echo "pr-number=$(<pr-number)" >> "$GITHUB_OUTPUT" |
| 33 | + fi |
| 34 | +
|
| 35 | + - uses: dawidd6/action-download-artifact@v8 |
| 36 | + name: "Download mypy_primer results" |
| 37 | + id: download-mypy_primer_diff |
| 38 | + if: steps.pr-number.outputs.pr-number |
| 39 | + with: |
| 40 | + name: mypy_primer_diff |
| 41 | + workflow: mypy_primer.yaml |
| 42 | + pr: ${{ steps.pr-number.outputs.pr-number }} |
| 43 | + path: pr/mypy_primer_diff |
| 44 | + workflow_conclusion: completed |
| 45 | + if_no_artifact_found: ignore |
| 46 | + allow_forks: true |
| 47 | + |
| 48 | + - name: Generate comment content |
| 49 | + id: generate-comment |
| 50 | + if: steps.download-mypy_primer_diff.outputs.found_artifact == 'true' |
| 51 | + run: | |
| 52 | + # Guard against malicious mypy_primer results that symlink to a secret |
| 53 | + # file on this runner |
| 54 | + if [[ -L pr/mypy_primer_diff/mypy_primer.diff ]] |
| 55 | + then |
| 56 | + echo "Error: mypy_primer.diff cannot be a symlink" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + # Note this identifier is used to find the comment to update on |
| 61 | + # subsequent runs |
| 62 | + echo '<!-- generated-comment mypy_primer -->' >> comment.txt |
| 63 | +
|
| 64 | + echo '## `mypy_primer` results' >> comment.txt |
| 65 | + echo '```diff' >> comment.txt |
| 66 | + cat pr/mypy_primer_diff/mypy_primer.diff >> comment.txt |
| 67 | + echo '```' >> comment.txt |
| 68 | +
|
| 69 | + echo 'comment<<EOF' >> "$GITHUB_OUTPUT" |
| 70 | + cat comment.txt >> "$GITHUB_OUTPUT" |
| 71 | + echo 'EOF' >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: Find existing comment |
| 74 | + uses: peter-evans/find-comment@v3 |
| 75 | + if: steps.generate-comment.outcome == 'success' |
| 76 | + id: find-comment |
| 77 | + with: |
| 78 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 79 | + comment-author: "github-actions[bot]" |
| 80 | + body-includes: "<!-- generated-comment mypy_primer -->" |
| 81 | + |
| 82 | + - name: Create or update comment |
| 83 | + if: steps.find-comment.outcome == 'success' |
| 84 | + uses: peter-evans/create-or-update-comment@v4 |
| 85 | + with: |
| 86 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 87 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 88 | + body-path: comment.txt |
| 89 | + edit-mode: replace |
0 commit comments