2828 go-version : ' 1.22'
2929
3030 - name : Build cmk binary
31+ id : build_step # Add an ID to the build step to check its status
3132 run : go build -v -o cmk ./cmk.go
3233
3334 - name : Rename binary with platform and PR number
@@ -42,22 +43,28 @@ jobs:
4243 path : cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
4344 if-no-files-found : error
4445
45- - name : Get PR number from Push event
46- id : get_pr_number
47- if : ${{ github.event_name == 'push' }} # Only run this on push events
48- run : |
49- echo "::set-output name=pr_number::$(gh pr view --json number -q .number || echo "")"
50- env :
51- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
52-
53- - name : Comment on PR with artifact link
46+ - name : Create or update PR comment (Success)
47+ if : ${{ success() && github.event_name == 'pull_request' }} # Only run on PR event and if build succeeds
5448 uses : peter-evans/create-or-update-comment@v4
49+ id : pr_comment # Give this step an ID to access its outputs
5550 with :
5651 token : ${{ secrets.GITHUB_TOKEN }}
57- issue-number : ${{ github.event_name == 'pull_request' && github. event.pull_request.number || steps.get_pr_number.outputs.pr_number }}
52+ issue-number : ${{ github.event.pull_request.number }}
5853 body : |
5954 <!-- cmk-build-artifact -->
60- ✅ Build complete for PR #${{ github.event_name == 'pull_request' && github. event.pull_request.number || steps.get_pr_number.outputs.pr_number }}
55+ ✅ Build complete for PR #${{ github.event.pull_request.number }}
6156 🔗 [Download the cmk binary](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
6257 edit-mode : replace
6358
59+ - name : Update PR comment (Failure)
60+ if : ${{ failure() && github.event_name == 'pull_request' }} # Only run on PR event and if build fails
61+ uses : peter-evans/create-or-update-comment@v4
62+ with :
63+ token : ${{ secrets.GITHUB_TOKEN }}
64+ issue-number : ${{ github.event.pull_request.number }}
65+ body : |
66+ <!-- cmk-build-artifact -->
67+ ❌ Build failed for PR #${{ github.event.pull_request.number }}
68+ See the [workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
69+ edit-mode : replace # Replaces the previous comment
70+
0 commit comments