diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 4b3c77111f5..723381a57a8 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -267,7 +267,6 @@ jobs: id: get_version run: | echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - echo $TAG - name: Publish release run: | @@ -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 diff --git a/.gitignore b/.gitignore index 385abcaaec2..50c0bf9d316 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.so *.dylib bin +_dist # Test binary, build with `go test -c` *.test diff --git a/Makefile b/Makefile index c4e7f64d2f6..9fcac687b43 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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