Skip to content

Commit dbdb48d

Browse files
jedudenclaude
andauthored
Add automated release workflow for multi-platform builds (#118)
* feat: add binary release workflow on tag push Build cross-platform binaries (linux/darwin amd64+arm64, windows amd64) and publish them as a GitHub release with checksums when a v* tag is pushed. https://claude.ai/code/session_01NmKfB4AJrZNBk2mjckmgjK * fix: address zizmor security findings in release workflow Scope contents:write permission to the release job only (not workflow-level) and disable default Go module caching in the build job. https://claude.ai/code/session_01NmKfB4AJrZNBk2mjckmgjK * fix: address review comments on release workflow - Inject tag version into binary via -X main.version ldflags - Add version variable to main.go with fallback to BuildInfo - Use GITHUB_TOKEN instead of GH_TOKEN for softprops action - Remove unused TAG env var https://claude.ai/code/session_01NmKfB4AJrZNBk2mjckmgjK --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2e1ba6b commit dbdb48d

2 files changed

Lines changed: 80 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
strategy:
14+
matrix:
15+
include:
16+
- goos: linux
17+
goarch: amd64
18+
- goos: linux
19+
goarch: arm64
20+
- goos: darwin
21+
goarch: amd64
22+
- goos: darwin
23+
goarch: arm64
24+
- goos: windows
25+
goarch: amd64
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
persist-credentials: false
31+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
32+
with:
33+
go-version-file: go.mod
34+
cache: false
35+
- name: Build
36+
env:
37+
GOOS: ${{ matrix.goos }}
38+
GOARCH: ${{ matrix.goarch }}
39+
VERSION: ${{ github.ref_name }}
40+
run: |
41+
ext=""
42+
if [ "$GOOS" = "windows" ]; then ext=".exe"; fi
43+
bin="mdsmith-${GOOS}-${GOARCH}${ext}"
44+
go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o "$bin" ./cmd/mdsmith
45+
echo "bin=$bin" >> "$GITHUB_ENV"
46+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
47+
with:
48+
name: mdsmith-${{ matrix.goos }}-${{ matrix.goarch }}
49+
path: ${{ env.bin }}
50+
51+
release:
52+
needs: build
53+
runs-on: ubuntu-latest
54+
permissions:
55+
contents: write
56+
steps:
57+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
58+
with:
59+
merge-multiple: true
60+
- name: Create checksums
61+
run: sha256sum mdsmith-* > checksums.txt
62+
- name: Create release
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8 # v2.3.2
66+
with:
67+
generate_release_notes: true
68+
files: |
69+
mdsmith-*
70+
checksums.txt

cmd/mdsmith/main.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,18 @@ func run() int {
120120
}
121121
}
122122

123+
// version is set via ldflags at build time (e.g. -X main.version=v1.0.0).
124+
var version string
125+
123126
func printVersion() {
124-
version := "(devel)"
125-
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
126-
version = info.Main.Version
127+
v := version
128+
if v == "" {
129+
v = "(devel)"
130+
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
131+
v = info.Main.Version
132+
}
127133
}
128-
fmt.Printf("mdsmith %s\n", version)
134+
fmt.Printf("mdsmith %s\n", v)
129135
}
130136

131137
// runCheck implements the "check" subcommand: lint files.

0 commit comments

Comments
 (0)