Leave PR comment #837
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
| # Copyright (c) Arduino s.r.l. and/or its affiliated companies | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Leave PR comment | |
| on: | |
| workflow_run: | |
| workflows: ["Package, test and upload core"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| comment-on-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifact | |
| uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11 | |
| with: | |
| workflow: package-core.yml | |
| run_id: ${{ github.event.workflow_run.id }} | |
| name: comment-request | |
| if_no_artifact_found: ignore | |
| - name: Load PR number | |
| run: | | |
| echo "PR_NUM=$(cat pr_number || true)" >> $GITHUB_ENV | |
| - name: Check PR number | |
| id: check-pr | |
| uses: carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0 | |
| if: ${{ env.PR_NUM }} | |
| with: | |
| pr: ${{ env.PR_NUM }} | |
| sha: ${{ github.event.workflow_run.head_sha }} | |
| - name: Validate PR number | |
| if: ${{ env.PR_NUM && steps.check-pr.outputs.VALID != 'true' }} | |
| run: | | |
| echo "::warning::PR #$PR_NUM is either invalid or includes changes to workflow" | |
| - name: Update PR comment | |
| if: ${{ env.PR_NUM && steps.check-pr.outputs.VALID == 'true' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| run: | | |
| BODY="$(cat comment_body || echo '# :fire: CI failure processing logs!')" | |
| # delete existing comment, if present, then add a new one | |
| gh pr comment ${PR_NUM} --delete-last --yes || true | |
| gh pr comment ${PR_NUM} --body "${BODY}" |