Skip to content

Commit 6057cc4

Browse files
committed
fix: Add static binaries to release
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent a97a89a commit 6057cc4

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

.github/workflows/release-automation.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,34 @@ jobs:
3232
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3333
with:
3434
fetch-tags: true
35-
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
36-
with:
37-
go-version: ${{ env.GO_VERSION }}
38-
cache: false
3935
- name: 'Echo RELEASE_TAG ENV'
4036
run: echo ${{ env.RELEASE_TAG }}
4137
- name: Setup variables and release directories
4238
run: |
4339
export release_tag=${{ env.RELEASE_TAG }}
4440
export release_version=${release_tag/v/} # Remove v from tag name
4541
echo "DYNAMIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64.tar.gz" >> $GITHUB_ENV
42+
echo "STATIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64-static.tar.gz" >> $GITHUB_ENV
4643
4744
mkdir release
4845
- name: Install Go licenses
4946
run: go install github.com/google/go-licenses@latest
5047
- name: Create Third Party Licences File
5148
run: make licenses
49+
- name: setup static dependecies
50+
run: sudo apt-get install glibc-static libstdc++-static
5251
- name: Create release binaries
5352
run: make RELEASE_TAG=${{ env.RELEASE_TAG }} release
5453
- name: Verify Release version
5554
run: |
56-
mkdir output
57-
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output
58-
BINARY_VERSION=$(./output/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
55+
mkdir -p output/static output/dynamic
56+
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output/dynamic
57+
tar -xzf release/${{ env.STATIC_BINARY_NAME }} -C ./output/static
58+
DYNAMIC_BINARY_VERSION=$(./output/dynamic/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
59+
STATIC_BINARY_VERSION=$(./output/static/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
5960
export release_tag=${{ env.RELEASE_TAG }}
6061
export release_version=${release_tag/v/}
61-
if ["$BINARY_VERSION" != "$release_version"]; then
62+
if ["$STATIC_BINARY_VERSION" != "$release_version"] || ["$DYNAMIC_BINARY_VERSION" != "$release_version"]; then
6263
echo "Version mismatch"
6364
exit 1
6465
fi
@@ -95,6 +96,6 @@ jobs:
9596
tag_name: ${{ needs.generate-artifacts.outputs.release_tag }}
9697
prerelease: false
9798
generate_release_notes: false
98-
files: |
99+
files: |-
99100
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}
100101
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}.sha256sum

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ build:
1818
$(eval PACKAGE := github.com/runfinch/finch-daemon)
1919
$(eval VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags))
2020
$(eval GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi))
21+
ifneq ($(STATIC),)
22+
$(eval GO_BUILDTAGS := osusergo netgo)
23+
$(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) -extldflags '-static'")
24+
@echo "Building Static Binary"
25+
else
26+
@echo "Building Dynamic Binary"
2127
$(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT)")
22-
GOOS=linux go build -ldflags $(LDFLAGS) -v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
28+
endif
29+
GOOS=linux go build $(if $(GO_BUILDTAGS), -tags "$(GO_BUILDTAGS)") -ldflags $(LDFLAGS) $(if $(STATIC), ) -v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
2330

2431
.PHONY: linux
2532
linux:
@@ -105,4 +112,4 @@ run-e2e-tests: linux
105112
.PHONY: release
106113
release: linux
107114
@echo "$@"
108-
@$(FINCH_DAEMON_PROJECT_ROOT)/scripts/create-releases.sh $(RELEASE_TAG)
115+
@$(FINCH_DAEMON_PROJECT_ROOT)/scripts/create-releases.sh $(RELEASE_TAG)

scripts/create-releases.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fi
5454

5555
release_version=${1/v/} # Remove v from tag name
5656
dynamic_binary_name=finch-daemon-${release_version}-linux-${ARCH}.tar.gz
57+
static_binary_name=finch-daemon-${release_version}-linux-${ARCH}-static.tar.gz
5758

5859
make build
5960
cp "$LICENSE_FILE" "${OUT_DIR}"
@@ -62,6 +63,14 @@ tar -czvf "$RELEASE_DIR"/"$dynamic_binary_name" -- *
6263
popd
6364
rm -rf "{$OUT_DIR:?}"/*
6465

66+
STATIC=1 make build
67+
cp "$LICENSE_FILE" "${OUT_DIR}"
68+
pushd "$OUT_DIR"
69+
tar -czvf "$RELEASE_DIR"/"$static_binary_name" -- *
70+
popd
71+
rm -rf "{$OUT_DIR:?}"/*
72+
6573
pushd "$RELEASE_DIR"
6674
sha256sum "$dynamic_binary_name" > "$RELEASE_DIR"/"$dynamic_binary_name".sha256sum
67-
popd
75+
sha256sum "$static_binary_name" > "$RELEASE_DIR"/"$static_binary_name".sha256sum
76+
popd

scripts/verify-release-artifacts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ release_tag=$1
4444
release_version=${release_tag/v/}
4545

4646
pushd "$release_dir" || exit 1
47-
tarballs=("finch-daemon-${release_version}-linux-${arch}.tar.gz")
47+
tarballs=("finch-daemon-${release_version}-linux-${arch}.tar.gz" "finch-daemon-${release_version}-linux-${arch}-static.tar.gz")
4848
expected_contents=("finch-daemon" "THIRD_PARTY_LICENSES")
4949
release_is_valid=true
5050

0 commit comments

Comments
 (0)