|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +name: Leave PR comment |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_run: |
| 7 | + workflows: ["Package, test and upload core"] |
| 8 | + types: |
| 9 | + - completed |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + comment-on-pr: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Download artifact |
| 20 | + uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11 |
| 21 | + with: |
| 22 | + workflow: package-core.yml |
| 23 | + run_id: ${{ github.event.workflow_run.id }} |
| 24 | + name: comment-request |
| 25 | + if_no_artifact_found: ignore |
| 26 | + |
| 27 | + - name: Load PR number |
| 28 | + run: | |
| 29 | + echo "PR_NUM=$(cat pr_number || true)" >> $GITHUB_ENV |
| 30 | +
|
| 31 | + - name: Check PR number |
| 32 | + id: check-pr |
| 33 | + uses: carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0 |
| 34 | + with: |
| 35 | + pr: ${{ env.PR_NUM }} |
| 36 | + sha: ${{ github.event.workflow_run.head_sha }} |
| 37 | + |
| 38 | + - name: Validate PR number |
| 39 | + if: ${{ steps.check-pr.outputs.VALID != 'true' }} |
| 40 | + run: | |
| 41 | + echo "ABORT: PR number validation failed!" |
| 42 | + exit 1 |
| 43 | +
|
| 44 | + - name: Update PR comment |
| 45 | + if: ${{ steps.check-pr.outputs.VALID == 'true' }} |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + GH_REPO: ${{ github.repository }} |
| 49 | + run: | |
| 50 | + BODY="$(cat comment_body || echo '# :fire: CI failure processing logs!')" |
| 51 | +
|
| 52 | + # delete existing comment, if present, then add a new one |
| 53 | + gh pr comment ${PR_NUM} --delete-last --yes || true |
| 54 | + gh pr comment ${PR_NUM} --body "${BODY}" |
| 55 | +
|
| 56 | + - name: Clean up intermediate artifacts |
| 57 | + if: ${{ steps.check-pr.outputs.VALID == 'true' }} |
| 58 | + uses: geekyeggo/delete-artifact@v5.1.0 |
| 59 | + with: |
| 60 | + name: comment-request |
0 commit comments