Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add static binaries to release #63

Merged
merged 6 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .github/workflows/release-automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: "WyriHaximus/github-action-get-previous-tag@04e8485ecb6487243907e330d522ff60f02283ce" # v1.4.0
generate-artifacts:
needs: get-latest-tag
runs-on: ubuntu-latest
coderbirju marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
env:
# Set during setup.
RELEASE_TAG: ${{ needs.get-latest-tag.outputs.tag }}
Expand All @@ -43,22 +43,29 @@ jobs:
export release_tag=${{ env.RELEASE_TAG }}
export release_version=${release_tag/v/} # Remove v from tag name
echo "DYNAMIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64.tar.gz" >> $GITHUB_ENV
echo "STATIC_BINARY_NAME=finch-daemon-${release_version}-linux-amd64-static.tar.gz" >> $GITHUB_ENV

mkdir release
- name: Install Go licenses
run: go install github.com/google/go-licenses@latest
- name: Create Third Party Licences File
run: make licenses
- name: setup static dependecies
run: |
sudo apt-get update
sudo apt-get install libc6-dev -f
- name: Create release binaries
run: make RELEASE_TAG=${{ env.RELEASE_TAG }} release
- name: Verify Release version
run: |
mkdir output
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output
BINARY_VERSION=$(./output/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
mkdir -p output/static output/dynamic
tar -xzf release/${{ env.DYNAMIC_BINARY_NAME }} -C ./output/dynamic
tar -xzf release/${{ env.STATIC_BINARY_NAME }} -C ./output/static
DYNAMIC_BINARY_VERSION=$(./output/dynamic/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
STATIC_BINARY_VERSION=$(./output/static/finch-daemon --version | grep -oP '\d+\.\d+\.\d+')
export release_tag=${{ env.RELEASE_TAG }}
export release_version=${release_tag/v/}
if ["$BINARY_VERSION" != "$release_version"]; then
if ["$STATIC_BINARY_VERSION" != "$release_version"] || ["$DYNAMIC_BINARY_VERSION" != "$release_version"]; then
echo "Version mismatch"
exit 1
fi
Expand Down Expand Up @@ -98,3 +105,5 @@ jobs:
files: |
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}
${{ needs.generate-artifacts.outputs.dynamic_binary_name }}.sha256sum
${{ needs.generate-artifacts.outputs.static_binary_name }}
${{ needs.generate-artifacts.outputs.static_binary_name }}.sha256sum
23 changes: 18 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,30 @@ BINDIR ?= $(PREFIX)/bin

BINARY = $(addprefix bin/,finch-daemon)

PACKAGE := github.com/runfinch/finch-daemon
VERSION := $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags)
GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)

ifndef GODEBUG
EXTRA_LDFLAGS += -s -w
endif

LDFLAGS_BASE := -X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) $(EXTRA_LDFLAGS)

.PHONY: build
build:
$(eval PACKAGE := github.com/runfinch/finch-daemon)
$(eval VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags))
$(eval GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi))
$(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT) $(EXTRA_LDFLAGS)")
GOOS=linux go build -ldflags $(LDFLAGS) -v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
ifeq ($(STATIC),)
@echo "Building Dynamic Binary"
CGO_ENABLED=1 GOOS=linux go build \
-ldflags "$(LDFLAGS_BASE)" \
-v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
else
@echo "Building Static Binary"
CGO_ENABLED=0 GOOS=linux go build \
-tags netgo \
-ldflags "$(LDFLAGS_BASE) -extldflags '-static'" \
-v -o $(BINARY) $(PACKAGE)/cmd/finch-daemon
endif

clean:
@rm -f $(BINARIES)
Expand Down
9 changes: 9 additions & 0 deletions scripts/create-releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fi

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

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

STATIC=1 make build
cp "$LICENSE_FILE" "${OUT_DIR}"
pushd "$OUT_DIR"
tar -czvf "$RELEASE_DIR"/"$static_binary_name" -- *
popd
rm -rf "{$OUT_DIR:?}"/*

pushd "$RELEASE_DIR"
sha256sum "$dynamic_binary_name" > "$RELEASE_DIR"/"$dynamic_binary_name".sha256sum
sha256sum "$static_binary_name" > "$RELEASE_DIR"/"$static_binary_name".sha256sum
popd
2 changes: 1 addition & 1 deletion scripts/verify-release-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ release_tag=$1
release_version=${release_tag/v/}

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

Expand Down
Loading