Skip to content

Commit 6e2cb41

Browse files
committed
Add GitHub Actions workflows for CI and release pipelines
- Implemented a CI workflow to run build, tests, and validation on push and pull request events. - Added a release workflow to build binaries for multiple platforms/architectures and publish them as GitHub releases.
1 parent bbecde3 commit 6e2cb41

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master, "**" ]
6+
pull_request:
7+
branches: [ main, master, "**" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: '1.21'
23+
check-latest: true
24+
25+
- name: Cache Go modules
26+
uses: actions/cache@v4
27+
with:
28+
path: |
29+
~/.cache/go-build
30+
~/go/pkg/mod
31+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32+
restore-keys: |
33+
${{ runner.os }}-go-
34+
35+
- name: Ensure go.mod is tidy
36+
run: |
37+
go mod tidy
38+
git diff --exit-code -- go.mod go.sum
39+
40+
- name: Build library layer
41+
run: go build ./internal
42+
43+
- name: Build CLI
44+
run: go build .
45+
46+
- name: Unit tests (internal only)
47+
run: go test -v ./internal

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-and-release:
13+
name: Build ${{ matrix.goos }}-${{ matrix.goarch }}
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
goos: [linux, darwin]
19+
goarch: [amd64, arm64]
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Go
25+
uses: actions/setup-go@v5
26+
with:
27+
go-version: '1.21'
28+
check-latest: true
29+
30+
- name: Cache Go modules
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.cache/go-build
35+
~/go/pkg/mod
36+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-go-
39+
40+
- name: Build binary
41+
env:
42+
CGO_ENABLED: 0
43+
GOOS: ${{ matrix.goos }}
44+
GOARCH: ${{ matrix.goarch }}
45+
run: |
46+
mkdir -p dist
47+
BIN_NAME=pumadevctl
48+
OUT=dist/${BIN_NAME}_${GOOS}_${GOARCH}
49+
go build -trimpath -ldflags "-s -w" -o "$OUT" .
50+
tar -C dist -czf "${OUT}.tar.gz" "${BIN_NAME}_${GOOS}_${GOARCH}"
51+
52+
- name: Create GitHub Release (if not exists)
53+
id: create_release
54+
uses: softprops/action-gh-release@v2
55+
with:
56+
draft: false
57+
prerelease: false
58+
name: ${{ github.ref_name }}
59+
tag_name: ${{ github.ref_name }}
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Upload assets
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
files: |
67+
dist/pumadevctl_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)