|
| 1 | +name: Build cmk on PR |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + if: ${{ github.repository == 'shwstppr/cloudstack-cloudmonkey' }} |
| 14 | + runs-on: ubuntu-24.04 |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Go |
| 21 | + uses: actions/setup-go@v5 |
| 22 | + with: |
| 23 | + go-version: '1.22' |
| 24 | + |
| 25 | + - name: Get PR number (for push events) |
| 26 | + id: get_pr_number |
| 27 | + if: github.event_name == 'push' |
| 28 | + run: | |
| 29 | + PR_NUMBER=$(gh pr list --head "$GITHUB_REF_NAME" --json number -q '.[0].number' || echo "") |
| 30 | + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + |
| 34 | + - name: Set PR number variable (for all cases) |
| 35 | + id: set_vars |
| 36 | + run: | |
| 37 | + echo "pr_number=${{ github.event.pull_request.number || env.PR_NUMBER }}" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Build cmk binary |
| 40 | + id: build_cmk |
| 41 | + run: go build -v -o cmk ./cmk.go |
| 42 | + |
| 43 | + - name: Rename binary |
| 44 | + if: success() |
| 45 | + run: | |
| 46 | + mv cmk cmk.linux.x86-64.pr${{ steps.set_vars.outputs.pr_number }} |
| 47 | +
|
| 48 | + - name: Upload cmk binary |
| 49 | + uses: actions/upload-artifact@v4 |
| 50 | + if: steps.set_vars.outputs.pr_number != '' && success() |
| 51 | + with: |
| 52 | + name: cmk.linux.x86-64.pr${{ steps.set_vars.outputs.pr_number }} |
| 53 | + path: cmk.linux.x86-64.pr${{ steps.set_vars.outputs.pr_number }} |
| 54 | + if-no-files-found: error |
| 55 | + |
| 56 | + - name: Find existing PR comment |
| 57 | + id: find_comment |
| 58 | + if: always() && steps.set_vars.outputs.pr_number != '' |
| 59 | + uses: peter-evans/find-comment@v3 |
| 60 | + with: |
| 61 | + issue-number: ${{ steps.set_vars.outputs.pr_number }} |
| 62 | + comment-author: 'github-actions[bot]' |
| 63 | + body-includes: '<!-- cmk-build-artifact-comment -->' |
| 64 | + |
| 65 | + - name: Create/update comment |
| 66 | + uses: peter-evans/create-or-update-comment@v4 |
| 67 | + if: always() && steps.set_vars.outputs.pr_number != '' |
| 68 | + with: |
| 69 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + issue-number: ${{ steps.set_vars.outputs.pr_number }} |
| 71 | + comment-id: ${{ steps.find_comment.outputs.comment-id }} |
| 72 | + body: | |
| 73 | + <!-- cmk-build-artifact-comment --> |
| 74 | + ${{ job.status == 'success' && '✅ Build complete' || '❌ Build failed' }} for PR #${{ steps.set_vars.outputs.pr_number }}. |
| 75 | + ${{ job.status == 'success' |
| 76 | + && format('🔗 [Download the cmk binary for Linux x86-64](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id) |
| 77 | + || format('See the [workflow run](https://github.com/{0}/actions/runs/{1}) for details.', github.repository, github.run_id) }} |
| 78 | + edit-mode: replace |
0 commit comments