Skip to content

Commit

Permalink
Publish Gator CLI binaries in release (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
sozercan authored Nov 4, 2021
1 parent c36e3d8 commit 87cb662
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
39 changes: 38 additions & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ jobs:
id: get_version
run: |
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo $TAG
- name: Publish release
run: |
Expand Down Expand Up @@ -305,11 +304,49 @@ jobs:
run: |
make e2e-verify-release IMG=${{ env.IMAGE_REPO }}:${TAG} USE_LOCAL_IMG=false
- name: Build gator-cli
run: |
build() {
export GOOS="$(echo ${1} | cut -d '-' -f 1)"
export GOARCH="$(echo ${1} | cut -d '-' -f 2)"
# in case of windows, we need to append .exe to the file name
EXTENSION="$(echo ${1} | cut -d '-' -f 3)"
EXTENSION=${EXTENSION/exe/.exe}
FILENAME=${GITHUB_WORKSPACE}/_dist/gator-${TAG}-${GOOS}-${GOARCH}
# build the binary
make bin/gator-${GOOS}-${GOARCH}${EXTENSION}
# rename the binary to gator
tmp_dir=$(mktemp -d)
cp bin/gator-${GOOS}-${GOARCH}${EXTENSION} ${tmp_dir}/gator${EXTENSION}
pushd ${tmp_dir}
if [[ ${EXTENSION} == ".exe" ]]; then
zip ${FILENAME}.zip gator*.exe
else
tar -czf ${FILENAME}.tar.gz gator*
fi
popd
}
mkdir -p _dist
for os_arch_extension in $PLATFORMS; do
build ${os_arch_extension} &
done
wait
pushd _dist
# consolidate tar and zip's sha256sum into a single file
find . -type f -name '*.tar.gz' -o -name '*.zip' | sort | xargs sha256sum >> sha256sums.txt
popd
env:
PLATFORMS: "linux-amd64 linux-arm64 darwin-amd64 darwin-arm64 windows-amd64-exe"

- name: Create GitHub release
uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
_dist/sha256sums.txt
_dist/*.tar.gz
_dist/*.zip
- name: Publish Helm chart
uses: stefanprodan/helm-gh-pages@v1.4.1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*.so
*.dylib
bin
_dist

# Test binary, build with `go test -c`
*.test
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ GOLANGCI_LINT_VERSION := v1.42.1
# Detects the location of the user golangci-lint cache.
GOLANGCI_LINT_CACHE := $(shell pwd)/.tmp/golangci-lint

ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BIN_DIR := $(abspath $(ROOT_DIR)/bin)

BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh)
BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh)
Expand Down Expand Up @@ -377,3 +380,15 @@ __tooling-image:
vendor:
go mod vendor
go mod tidy

.PHONY: gator
gator: bin/gator-$(GOOS)-$(GOARCH)$(EXTENSION)
mv bin/gator-$(GOOS)-$(GOARCH)$(EXTENSION) bin/gator

EXTENSION.linux :=
EXTENSION.darwin :=
EXTENSION.windows := .exe
EXTENSION := $(EXTENSION.$(GOOS))

bin/gator-$(GOOS)-$(GOARCH)$(EXTENSION):
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(BIN_DIR)/gator-$(GOOS)-$(GOARCH)$(EXTENSION) -ldflags $(LDFLAGS) ./cmd/gator

0 comments on commit 87cb662

Please sign in to comment.