Skip to content

Commit addb7e1

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 addb7e1

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
id: upload_artifact
36+
uses: actions/upload-artifact@v4
37+
if: success()
38+
with:
39+
name: cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
40+
path: cmk.linux.x86-64.pr${{ github.event.pull_request.number }}
41+
if-no-files-found: error
42+
retention-days: 10
43+
44+
- name: Find existing PR comment
45+
id: find_comment
46+
if: always()
47+
uses: peter-evans/find-comment@v3
48+
with:
49+
issue-number: ${{ github.event.pull_request.number }}
50+
comment-author: 'github-actions[bot]'
51+
body-includes: '<!-- cmk-build-artifact-comment -->'
52+
53+
- name: Create/update comment
54+
if: always()
55+
uses: peter-evans/create-or-update-comment@v4
56+
with:
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
issue-number: ${{ github.event.pull_request.number }}
59+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
60+
body: |
61+
<!-- cmk-build-artifact-comment -->
62+
${{ job.status == 'success' && '✅ Build complete' || '❌ Build failed' }} for PR #${{ github.event.pull_request.number }}.
63+
64+
${{ job.status == 'success'
65+
&& format('🔗 [Download the cmk binary for linux.x86-64 (expires in 10 days)]({0})', steps.upload_artifact.outputs.artifact-url)
66+
|| format('See the [workflow run](https://github.com/{0}/actions/runs/{1}) for details.', github.repository, github.run_id) }}
67+
edit-mode: replace

0 commit comments

Comments
 (0)