Skip to content

Commit 09f1a9a

Browse files
committed
github-action: add pr builder for easier testing
Adds a Github action to build binary for Linux x86-64 for easier testing of PRs. A comment will be added in the PR. Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 79f09fb commit 09f1a9a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.github/workflows/build-pr-cmk.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.22'
23+
24+
- name: Build cmk binary
25+
id: build_cmk
26+
run: go build -v -o cmk ./cmk.go
27+
continue-on-error: true
28+
29+
- name: Rename binary
30+
if: success()
31+
run: |
32+
mv cmk cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
33+
34+
- name: Upload cmk binary
35+
uses: actions/upload-artifact@v4
36+
if: success()
37+
with:
38+
name: cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
39+
path: cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
40+
if-no-files-found: error
41+
42+
- name: Find existing PR comment
43+
id: find_comment
44+
if: always()
45+
uses: peter-evans/find-comment@v3
46+
with:
47+
issue-number: ${{ github.event.pull_request.number }}
48+
comment-author: 'github-actions[bot]'
49+
body-includes: '<!-- cmk-build-artifact-comment -->'
50+
51+
- name: Create/update comment
52+
if: always()
53+
uses: peter-evans/create-or-update-comment@v4
54+
with:
55+
token: ${{ secrets.GITHUB_TOKEN }}
56+
issue-number: ${{ github.event.pull_request.number }}
57+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
58+
body: |
59+
<!-- cmk-build-artifact-comment -->
60+
${{ job.status == 'success' && '✅ Build complete' || '❌ Build failed' }} for PR #${{ github.event.pull_request.number }}.
61+
62+
${{ job.status == 'success'
63+
&& format('🔗 [Download the cmk.linux.x86-64.pr{2} binary](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id, github.event.pull_request.number)
64+
|| format('See the [workflow run](https://github.com/{0}/actions/runs/{1}) for details.', github.repository, github.run_id) }}
65+
edit-mode: replace

0 commit comments

Comments
 (0)