CUR_SHA=$(shell git log -n1 --pretty='%h') CUR_BRANCH=$(shell git branch --show-current) VERSION=$(shell git describe --exact-match --tags $(CUR_SHA) 2>/dev/null || echo $(CUR_BRANCH)-$(CUR_SHA)) CTN:=$(shell which podman 2>&1 1>/dev/null && echo "podman" || echo "docker") PREFIX=~/.local GO=container OUT=katenary BLD_CMD=go build -ldflags="-X 'main.Version=$(VERSION)'" -o $(OUT) ./cmd/katenary/*.go GOOS=linux GOARCH=amd64 BUILD_IMAGE=docker.io/golang:1.18-alpine .PHONY: help clean build .ONESHELL: help: @cat < Build in host using go" else @echo "=> Build in container using" $(CTN) endif echo $(BLD_CMD) ifeq ($(GO),local) $(BLD_CMD) else ifeq ($(CTN),podman) @podman run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \ --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --userns keep-id -it $(BUILD_IMAGE) $(BLD_CMD) else @docker run -e CGO_ENABLED=0 -e GOOS=$(GOOS) -e GOARCH=$(GOARCH) \ --rm -v $(PWD):/go/src/katenary:z -w /go/src/katenary --user $(shell id -u):$(shell id -g) -e HOME=/tmp -it $(BUILD_IMAGE) $(BLD_CMD) endif echo "=> Stripping if possible" strip $(OUT) 2>/dev/null || echo "=> No strip available" install: build cp katenary $(PREFIX)/bin/katenary uninstall: rm -f $(PREFIX)/bin/katenary clean: rm -rf katenary dist/* release.id tests: test test: @echo -e "\033[1;33mTesting katenary $(VERSION)...\033[0m" go test -v ./... .ONESHELL: push-release: build-all @rm -f release.id # read personal access token from .git-credentials TOKEN=$(shell cat .credentials) # create a new release based on current tag and get the release id @curl -sSL -X POST \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token $$TOKEN" \ -d "{\"tag_name\": \"$(VERSION)\", \"target_commitish\": \"\", \"name\": \"$(VERSION)\", \"draft\": true, \"prerelease\": true}" \ https://api.github.com/repos/metal3d/katenary/releases | jq -r '.id' > release.id @echo "Release id: $$(cat release.id) created" @echo "Uploading assets..." # push all dist binary as assets to the release @for i in $$(find dist -type f -name "katenary*"); do curl -sSL -H "Authorization: token $$TOKEN" \ -H "Accept: application/vnd.github.v3+json" \ -H "Content-Type: application/octet-stream" \ --data-binary @$$i \ https://uploads.github.com/repos/metal3d/katenary/releases/$$(cat release.id)/assets?name=$$(basename $$i) done @rm -f release.id