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

Publish Gator CLI binaries in release #1636

Merged
merged 4 commits into from
Nov 4, 2021
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
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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A way to make this simpler: skip the pushd, popd and move the rm command into a trap. Like so:

tmp_dir=$(mktemp -d)
trap 'rm -rf -- "${tmp_dir}"' EXIT

All that aside... Isn't this environment ephemeral? Perhaps we don't need to clean up at all?

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