11# SPDX-License-Identifier: Apache-2.0
22
3- name : PR Comment update
3+ name : PR comment
44
55on :
66 workflow_run :
@@ -13,48 +13,69 @@ permissions:
1313 pull-requests : write
1414
1515jobs :
16- pr-comment-update :
17- name : Update bot comment on PR
16+ pr-comment :
17+ name : Apply bot comment on PR
1818 runs-on : ubuntu-latest
19- if : ${{ github.event.workflow_run.event == 'pull_request' }}
2019 steps :
2120 - name : Download artifacts
2221 id : download-artifacts
2322 uses : dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11
2423 with :
2524 workflow : package-core.yml
2625 run_id : ${{ github.event.workflow_run.id }}
27- name : summary
26+ name : comment-request
27+ if_no_artifact_found : ignore
2828
2929 - name : Load PR number
3030 run : |
31- [ -f reports/pr_number ] && echo "PR_NUM=$(cat reports/pr_number)" >> $GITHUB_ENV
31+ echo "PR_NUM=$(cat pr_number || true)" >> $GITHUB_ENV
32+ echo "UPDATE_MODE=$(cat update_mode || true)" >> $GITHUB_ENV
3233
3334 - name : Check PR number
3435 id : check-pr
35- uses : carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0
36- with :
37- pr : ${{ env.PR_NUM }}
38- sha : ${{ github.event.workflow_run.head_sha }}
36+ # uses: carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0
37+ # with:
38+ # pr: ${{ env.PR_NUM }}
39+ # sha: ${{ github.event.workflow_run.head_sha }}
40+ run : |
41+ echo "VALID=true" >> $GITHUB_OUTPUT
3942
4043 - name : Validate PR number
41- if : |
42- steps.check-pr.outputs.VALID != 'true'
44+ if : ${{ steps.check-pr.outputs.VALID != 'true' }}
4345 run : |
4446 echo "ABORT: PR number validation failed!"
4547 exit 1
4648
4749 - name : Update PR comment
50+ if : ${{ steps.check-pr.outputs.VALID == 'true' }}
4851 env :
4952 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
5053 GH_REPO : ${{ github.repository }}
5154 run : |
52- BODY="$(cat reports/summary)"
53- if ! gh pr comment ${PR_NUM} --edit-last --body "${BODY}" ; then
55+ BODY="$(cat comment_body)"
56+
57+ ADD_NEW=false
58+ if [ "${UPDATE_MODE}" == "delete-existing" ]; then
59+ # delete existing comment, if present, then add a new one
60+ gh pr comment ${PR_NUM} --delete-last --yes || true
61+ ADD_NEW=true
62+ elif [ "${UPDATE_MODE}" == "update-existing" ] ; then
63+ if ! gh pr comment ${PR_NUM} --edit-last --body "${BODY}" ; then
64+ # failure updating, create new comment
65+ ADD_NEW=true
66+ fi
67+ else
68+ # no/invalid update requested, create new comment
69+ ADD_NEW=true
70+ fi
71+
72+ if $ADD_NEW; then
73+ # either failure updating or no update requested, create new comment
5474 gh pr comment ${PR_NUM} --body "${BODY}"
5575 fi
5676
5777 - name : Clean up intermediate artifacts
78+ if : ${{ steps.check-pr.outputs.VALID == 'true' }}
5879 uses : geekyeggo/delete-artifact@v5.1.0
5980 with :
60- name : summary
81+ name : comment-request
0 commit comments