|
| 1 | +name: PR comment (typing_conformance) |
| 2 | + |
| 3 | +on: # zizmor: ignore[dangerous-triggers] |
| 4 | + workflow_run: |
| 5 | + workflows: [Run typing conformance] |
| 6 | + types: [completed] |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + workflow_run_id: |
| 10 | + description: The typing_conformance 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@20319c5641d495c8a52e688b7dc5fada6c3a9fbc # 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@20319c5641d495c8a52e688b7dc5fada6c3a9fbc # v8 |
| 36 | + name: "Download typing_conformance results" |
| 37 | + id: download-typing_conformance_diff |
| 38 | + if: steps.pr-number.outputs.pr-number |
| 39 | + with: |
| 40 | + name: typing_conformance_diagnostics_diff |
| 41 | + workflow: typing_conformance.yaml |
| 42 | + pr: ${{ steps.pr-number.outputs.pr-number }} |
| 43 | + path: pr/typing_conformance_diagnostics_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-typing_conformance_diff.outputs.found_artifact == 'true' }} |
| 51 | + run: | |
| 52 | + # Guard against malicious typing_conformance results that symlink to a secret |
| 53 | + # file on this runner |
| 54 | + if [[ -L pr/typing_conformance_diagnostics_diff/typing_conformance_diagnostics.diff ]] |
| 55 | + then |
| 56 | + echo "Error: typing_conformance_diagnostics.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 typing_conformance_diagnostics_diff -->' >> comment.txt |
| 63 | +
|
| 64 | + echo '## Diagnostic diff on typing conformance tests' >> comment.txt |
| 65 | + if [ -s "pr/typing_conformance_diagnostics_diff/typing_conformance_diagnostics.diff" ]; then |
| 66 | + echo '<details>' >> comment.txt |
| 67 | + echo '<summary>Changes were detected when running ty on typing conformance tests</summary>' >> comment.txt |
| 68 | + echo '' >> comment.txt |
| 69 | + echo '```diff' >> comment.txt |
| 70 | + cat pr/typing_conformance_diagnostics_diff/typing_conformance_diagnostics.diff >> comment.txt |
| 71 | + echo '```' >> comment.txt |
| 72 | + echo '</details>' >> comment.txt |
| 73 | + else |
| 74 | + echo 'No changes detected when running ty on typing conformance tests ✅' >> comment.txt |
| 75 | + fi |
| 76 | +
|
| 77 | + echo 'comment<<EOF' >> "$GITHUB_OUTPUT" |
| 78 | + cat comment.txt >> "$GITHUB_OUTPUT" |
| 79 | + echo 'EOF' >> "$GITHUB_OUTPUT" |
| 80 | +
|
| 81 | + - name: Find existing comment |
| 82 | + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 |
| 83 | + if: steps.generate-comment.outcome == 'success' |
| 84 | + id: find-comment |
| 85 | + with: |
| 86 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 87 | + comment-author: "github-actions[bot]" |
| 88 | + body-includes: "<!-- generated-comment typing_conformance_diagnostics_diff -->" |
| 89 | + |
| 90 | + - name: Create or update comment |
| 91 | + if: steps.find-comment.outcome == 'success' |
| 92 | + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4 |
| 93 | + with: |
| 94 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 95 | + issue-number: ${{ steps.pr-number.outputs.pr-number }} |
| 96 | + body-path: comment.txt |
| 97 | + edit-mode: replace |
0 commit comments