Skip to content

Commit b91ba08

Browse files
authored
ci: Add Terragrunt-style Go binary release workflow (#99)
* ci: Add Terragrunt-style Go binary release workflow Replace GoReleaser with a manual build/archive/upload pipeline matching Terragrunt's release pattern. Adds a reusable build-go.yml workflow that matrix-builds 6 targets and a release-go.yml that creates archives, generates SHA256SUMS, and uploads assets to an existing GitHub release. * feat: remove the binaries Signed-off-by: Diogenes Fernandes <diofeher@gmail.com> --------- Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
1 parent b1c0eae commit b91ba08

3 files changed

Lines changed: 269 additions & 0 deletions

File tree

.github/workflows/build-go.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Build Go
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
name: Build (${{ matrix.os }}/${{ matrix.arch }})
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
include:
13+
- os: darwin
14+
arch: amd64
15+
- os: darwin
16+
arch: arm64
17+
- os: linux
18+
arch: amd64
19+
- os: linux
20+
arch: arm64
21+
- os: windows
22+
arch: amd64
23+
- os: windows
24+
arch: arm64
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
29+
30+
- name: Set up mise
31+
uses: jdx/mise-action@c37c93293d6b742fc901e1406b8f764f6fb19dac # v2
32+
with:
33+
version: 2025.6.8
34+
experimental: true
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- id: go-cache-paths
39+
run: |
40+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
41+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
42+
43+
- name: Go Build Cache
44+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
45+
with:
46+
path: ${{ steps.go-cache-paths.outputs.go-build }}
47+
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}-${{ matrix.os }}-${{ matrix.arch }}
48+
restore-keys: |
49+
${{ runner.os }}-go-build-
50+
51+
- name: Go Mod Cache
52+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
53+
with:
54+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
55+
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
56+
restore-keys: |
57+
${{ runner.os }}-go-mod-
58+
59+
- name: Build
60+
env:
61+
GOOS: ${{ matrix.os }}
62+
GOARCH: ${{ matrix.arch }}
63+
CGO_ENABLED: "0"
64+
run: |
65+
OUTPUT="terragrunt-ls_${GOOS}_${GOARCH}"
66+
if [[ "${GOOS}" == "windows" ]]; then
67+
OUTPUT="${OUTPUT}.exe"
68+
fi
69+
go build -o "${OUTPUT}" -trimpath -ldflags "-s -w" .
70+
71+
- name: Verify static linking
72+
env:
73+
GOOS: ${{ matrix.os }}
74+
GOARCH: ${{ matrix.arch }}
75+
run: |
76+
OUTPUT="terragrunt-ls_${GOOS}_${GOARCH}"
77+
if [[ "${GOOS}" == "windows" ]]; then
78+
OUTPUT="${OUTPUT}.exe"
79+
fi
80+
81+
FILE_INFO=$(file "$OUTPUT")
82+
echo "$FILE_INFO"
83+
84+
case "$GOOS" in
85+
linux)
86+
echo "$FILE_INFO" | grep -q "statically linked"
87+
echo "Linux binary is statically linked"
88+
;;
89+
darwin)
90+
echo "$FILE_INFO" | grep -q "Mach-O.*executable"
91+
echo "macOS binary is Mach-O executable"
92+
;;
93+
windows)
94+
echo "$FILE_INFO" | grep -q "PE32.*executable.*Windows"
95+
echo "Windows binary is PE32 executable"
96+
;;
97+
esac
98+
99+
- name: Upload binary artifact
100+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
101+
with:
102+
name: terragrunt-ls_${{ matrix.os }}_${{ matrix.arch }}
103+
path: terragrunt-ls_${{ matrix.os }}_${{ matrix.arch }}*

.github/workflows/release-go.yml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Release Go
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Tag to release (e.g., v0.1.0)'
11+
required: true
12+
type: string
13+
clobber:
14+
description: 'Overwrite existing release assets (--clobber)'
15+
required: false
16+
type: boolean
17+
default: false
18+
push:
19+
tags: ['v*']
20+
21+
jobs:
22+
build:
23+
name: Build All Binaries
24+
uses: ./.github/workflows/build-go.yml
25+
secrets: inherit
26+
27+
upload-assets:
28+
name: Upload Release Assets
29+
needs: build
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: write
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
37+
38+
- name: Get version
39+
id: version
40+
env:
41+
INPUT_TAG: ${{ inputs.tag }}
42+
EVENT_NAME: ${{ github.event_name }}
43+
run: |
44+
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
45+
VERSION="$INPUT_TAG"
46+
else
47+
VERSION="${GITHUB_REF#refs/tags/}"
48+
fi
49+
50+
if [[ -z "$VERSION" ]]; then
51+
echo "ERROR: Could not determine version" >&2
52+
exit 1
53+
fi
54+
55+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
56+
echo "Release version: $VERSION"
57+
58+
- name: Check if release exists
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
VERSION: ${{ steps.version.outputs.version }}
62+
run: |
63+
if ! gh release view "$VERSION" > /dev/null 2>&1; then
64+
echo "ERROR: Release not found for tag $VERSION" >&2
65+
echo "Create a GitHub release for this tag before running the workflow." >&2
66+
exit 1
67+
fi
68+
echo "Found existing release for $VERSION"
69+
70+
- name: Download all binary artifacts
71+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
72+
with:
73+
path: bin/
74+
merge-multiple: true
75+
76+
- name: Verify binaries downloaded
77+
run: |
78+
echo "Downloaded binaries:"
79+
ls -lahrt bin/
80+
BINARY_COUNT=$(find bin/ -type f | wc -l)
81+
echo "Total binaries: $BINARY_COUNT"
82+
if [[ "$BINARY_COUNT" -lt 6 ]]; then
83+
echo "ERROR: Expected at least 6 binaries, found $BINARY_COUNT" >&2
84+
exit 1
85+
fi
86+
87+
- name: Set execution permissions
88+
run: chmod +x bin/terragrunt-ls_darwin_* bin/terragrunt-ls_linux_*
89+
90+
- name: Create archives
91+
run: |
92+
cd bin
93+
for binary in terragrunt-ls_*; do
94+
if [[ "$binary" == *.zip ]] || [[ "$binary" == *.tar.gz ]]; then
95+
continue
96+
fi
97+
zip "${binary}.zip" "$binary"
98+
tar -czf "${binary}.tar.gz" "$binary"
99+
echo "Created archives for $binary"
100+
done
101+
102+
- name: Generate SHA256SUMS
103+
run: |
104+
cd bin
105+
sha256sum *.zip *.tar.gz > SHA256SUMS
106+
echo "SHA256SUMS:"
107+
cat SHA256SUMS
108+
109+
- name: Upload assets to release
110+
env:
111+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
VERSION: ${{ steps.version.outputs.version }}
113+
CLOBBER: ${{ github.event_name == 'workflow_dispatch' && inputs.clobber || 'false' }}
114+
run: |
115+
CLOBBER_FLAG=""
116+
if [[ "$CLOBBER" == "true" ]]; then
117+
CLOBBER_FLAG="--clobber"
118+
echo "Overwrite mode enabled"
119+
fi
120+
121+
echo "Uploading assets to release $VERSION..."
122+
cd bin
123+
for file in *.zip *.tar.gz SHA256SUMS; do
124+
echo "Uploading $file..."
125+
gh release upload "$VERSION" "$file" $CLOBBER_FLAG
126+
done
127+
echo "All assets uploaded"
128+
129+
- name: Verify assets uploaded
130+
env:
131+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
VERSION: ${{ steps.version.outputs.version }}
133+
run: |
134+
ASSETS=$(gh release view "$VERSION" --json 'assets' --jq '.assets[].name')
135+
echo "Release assets:"
136+
echo "$ASSETS"
137+
138+
EXPECTED_FILES=(
139+
"SHA256SUMS"
140+
)
141+
142+
for platform in darwin_amd64 darwin_arm64 linux_amd64 linux_arm64 windows_amd64 windows_arm64; do
143+
bin="terragrunt-ls_${platform}"
144+
if [[ "$platform" == windows_* ]]; then
145+
bin="${bin}.exe"
146+
fi
147+
EXPECTED_FILES+=("${bin}.zip" "${bin}.tar.gz")
148+
done
149+
150+
MISSING=0
151+
for expected in "${EXPECTED_FILES[@]}"; do
152+
if echo "$ASSETS" | grep -q "^${expected}$"; then
153+
echo "$expected present"
154+
else
155+
echo "MISSING: $expected" >&2
156+
MISSING=1
157+
fi
158+
done
159+
160+
if [[ "$MISSING" -eq 1 ]]; then
161+
echo "ERROR: Some expected assets are missing from the release" >&2
162+
exit 1
163+
fi
164+
165+
echo "All expected assets verified"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
terragrunt-ls
2+
dist/
23

34
# Put temporary fixtures here.
45
tmp-fixtures

0 commit comments

Comments
 (0)