Skip to content

Commit 45f1202

Browse files
committed
feat(ci): publish multi-arch binaries on GitHub releases
1 parent e7073a0 commit 45f1202

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Publish Release Binaries
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: Release tag to publish (for example wootty-v0.2.2 or v0.2.2)
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
publish-binaries:
16+
name: Build and Attach Multi-Arch Binaries
17+
if: github.ref_name == 'main'
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Prepare metadata
22+
id: prepare
23+
env:
24+
INPUT_TAG: ${{ github.event.inputs.tag || '' }}
25+
run: |
26+
set -euo pipefail
27+
28+
tag="${INPUT_TAG}"
29+
tag="${tag#refs/tags/}"
30+
31+
if [[ -z "$tag" ]]; then
32+
echo "Missing release tag. Provide workflow_dispatch input 'tag'."
33+
exit 1
34+
fi
35+
36+
release_tag="$tag"
37+
semver_tag="$tag"
38+
if [[ "$release_tag" != wootty-* && "$release_tag" == v* ]]; then
39+
release_tag="wootty-$release_tag"
40+
fi
41+
if [[ "$release_tag" == wootty-v* ]]; then
42+
semver_tag="${release_tag#wootty-}"
43+
fi
44+
45+
version_no_v="$semver_tag"
46+
if [[ "$version_no_v" == v* ]]; then
47+
version_no_v="${version_no_v#v}"
48+
fi
49+
50+
echo "release_tag=$release_tag" >>"$GITHUB_OUTPUT"
51+
echo "checkout_ref=refs/tags/$release_tag" >>"$GITHUB_OUTPUT"
52+
echo "version_tag=$semver_tag" >>"$GITHUB_OUTPUT"
53+
echo "version_no_v=$version_no_v" >>"$GITHUB_OUTPUT"
54+
55+
- name: Checkout release tag
56+
uses: actions/checkout@v6
57+
with:
58+
ref: ${{ steps.prepare.outputs.checkout_ref }}
59+
60+
- name: Set up Go
61+
uses: actions/setup-go@v6
62+
with:
63+
go-version-file: apps/server/go.mod
64+
cache-dependency-path: apps/server/go.sum
65+
66+
- name: Build archives
67+
run: |
68+
set -euo pipefail
69+
70+
mkdir -p dist
71+
VERSION="${{ steps.prepare.outputs.version_no_v }}"
72+
73+
targets=(
74+
"linux amd64"
75+
"linux arm64"
76+
"darwin amd64"
77+
"darwin arm64"
78+
"windows amd64"
79+
"windows arm64"
80+
)
81+
82+
for target in "${targets[@]}"; do
83+
read -r goos goarch <<<"$target"
84+
85+
out_dir="dist/woottyd_${VERSION}_${goos}_${goarch}"
86+
archive_base="woottyd_${VERSION}_${goos}_${goarch}"
87+
mkdir -p "$out_dir"
88+
89+
bin_name="woottyd"
90+
archive_ext=".tar.gz"
91+
if [[ "$goos" == "windows" ]]; then
92+
bin_name="woottyd.exe"
93+
archive_ext=".zip"
94+
fi
95+
96+
CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" \
97+
go build -trimpath -ldflags="-s -w" \
98+
-o "$out_dir/$bin_name" ./apps/server/cmd/woottyd
99+
100+
cp README.md LICENSE "$out_dir/"
101+
102+
if [[ "$archive_ext" == ".zip" ]]; then
103+
(
104+
cd "$out_dir"
105+
zip -q "../${archive_base}${archive_ext}" "$bin_name" README.md LICENSE
106+
)
107+
else
108+
tar -C "$out_dir" -czf "dist/${archive_base}${archive_ext}" "$bin_name" README.md LICENSE
109+
fi
110+
done
111+
112+
(
113+
cd dist
114+
sha256sum woottyd_* > woottyd_checksums.txt
115+
)
116+
117+
- name: Upload release assets
118+
env:
119+
GH_TOKEN: ${{ github.token }}
120+
run: |
121+
set -euo pipefail
122+
shopt -s nullglob
123+
assets=(dist/woottyd_*.tar.gz dist/woottyd_*.zip dist/woottyd_checksums.txt)
124+
gh release upload "${{ steps.prepare.outputs.release_tag }}" "${assets[@]}" --repo "${{ github.repository }}" --clobber

.github/workflows/release-please.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ jobs:
4141
-f tag="${{ needs.release-please.outputs.tag_name }}"
4242
env:
4343
GH_TOKEN: ${{ github.token }}
44+
45+
publish-binaries:
46+
name: Dispatch Binary Publish
47+
runs-on: ubuntu-latest
48+
needs: release-please
49+
if: ${{ needs.release-please.outputs.release_created == 'true' }}
50+
steps:
51+
- name: Trigger publish-binaries workflow for released tag
52+
run: |
53+
gh workflow run publish-binaries.yml \
54+
--repo "${{ github.repository }}" \
55+
--ref main \
56+
-f tag="${{ needs.release-please.outputs.tag_name }}"
57+
env:
58+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)