Skip to content

Commit abf4a26

Browse files
committed
ci: add GitHub Actions workflow for cross-platform builds
1 parent 8539724 commit abf4a26

1 file changed

Lines changed: 159 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Version tag (e.g., 0.8.4)'
11+
required: false
12+
default: ''
13+
14+
jobs:
15+
build:
16+
name: Build ${{ matrix.os }}-${{ matrix.arch }}
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
include:
21+
- os: linux
22+
arch: amd64
23+
goos: linux
24+
goarch: amd64
25+
- os: linux
26+
arch: arm64
27+
goos: linux
28+
goarch: arm64
29+
- os: darwin
30+
arch: amd64
31+
goos: darwin
32+
goarch: amd64
33+
- os: darwin
34+
arch: arm64
35+
goos: darwin
36+
goarch: arm64
37+
- os: windows
38+
arch: amd64
39+
goos: windows
40+
goarch: amd64
41+
ext: .exe
42+
- os: windows
43+
arch: arm64
44+
goos: windows
45+
goarch: arm64
46+
ext: .exe
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
52+
- name: Setup Go
53+
uses: actions/setup-go@v5
54+
with:
55+
go-version: '1.21'
56+
57+
- name: Get version
58+
id: version
59+
run: |
60+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
61+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
62+
elif [ "${{ github.ref_type }}" = "tag" ]; then
63+
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
64+
else
65+
echo "VERSION=$(cat Makefile | grep 'VERSION :=' | head -1 | cut -d'=' -f2 | tr -d ' ')" >> $GITHUB_OUTPUT
66+
fi
67+
68+
- name: Build binary
69+
env:
70+
GOOS: ${{ matrix.goos }}
71+
GOARCH: ${{ matrix.goarch }}
72+
CGO_ENABLED: 0
73+
run: |
74+
VERSION=${{ steps.version.outputs.VERSION }}
75+
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
76+
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
77+
LDFLAGS="-s -w -X main.version=${VERSION} -X main.commit=${GIT_COMMIT} -X main.date=${BUILD_TIME}"
78+
79+
BINARY_NAME="mask-ctl-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}"
80+
mkdir -p build/bin
81+
go build -ldflags "${LDFLAGS}" -o build/bin/${BINARY_NAME} ./cmd/coding-plan-mask
82+
83+
echo "BINARY_NAME=${BINARY_NAME}" >> $GITHUB_OUTPUT
84+
85+
- name: Upload artifact
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: mask-ctl-${{ matrix.os }}-${{ matrix.arch }}
89+
path: build/bin/mask-ctl-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}
90+
retention-days: 1
91+
92+
release:
93+
name: Create Release
94+
needs: build
95+
runs-on: ubuntu-latest
96+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
97+
98+
steps:
99+
- name: Checkout code
100+
uses: actions/checkout@v4
101+
102+
- name: Get version
103+
id: version
104+
run: |
105+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
106+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
107+
elif [ "${{ github.ref_type }}" = "tag" ]; then
108+
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
109+
else
110+
echo "VERSION=$(cat Makefile | grep 'VERSION :=' | head -1 | cut -d'=' -f2 | tr -d ' ')" >> $GITHUB_OUTPUT
111+
fi
112+
113+
- name: Download all artifacts
114+
uses: actions/download-artifact@v4
115+
with:
116+
path: build/bin
117+
118+
- name: List artifacts
119+
run: ls -la build/bin/
120+
121+
- name: Create SHA256 checksums
122+
run: |
123+
cd build/bin
124+
for dir in */; do
125+
cd "$dir"
126+
for f in *; do
127+
sha256sum "$f" >> ../../checksums.sha256
128+
done
129+
cd ..
130+
done
131+
cat checksums.sha256
132+
133+
- name: Create Release
134+
uses: softprops/action-gh-release@v2
135+
with:
136+
tag_name: v${{ steps.version.outputs.VERSION }}
137+
name: Release v${{ steps.version.outputs.VERSION }}
138+
body: |
139+
## Changes
140+
- Add Anthropic format compatibility mode (`use_anthropic` config)
141+
- Add terminal logging for mock models requests
142+
- Fix null values in JSON Schema for Anthropic protocol
143+
144+
## Downloads
145+
| Platform | Architecture | File |
146+
|----------|-------------|------|
147+
| Linux | amd64 | mask-ctl-linux-amd64 |
148+
| Linux | arm64 | mask-ctl-linux-arm64 |
149+
| macOS | amd64 | mask-ctl-darwin-amd64 |
150+
| macOS | arm64 | mask-ctl-darwin-arm64 |
151+
| Windows | amd64 | mask-ctl-windows-amd64.exe |
152+
| Windows | arm64 | mask-ctl-windows-arm64.exe |
153+
files: |
154+
build/bin/*/mask-ctl-*
155+
checksums.sha256
156+
draft: false
157+
prerelease: false
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)