github.com/aserto-dev/calc-version@v1.1.4/Makefile (about) 1 SHELL := $(shell which bash) 2 3 ## BOF define block 4 5 # This is required in order to reference private repos 6 # this works in tandem with the following git configuration, defined below 7 # git config --global url."git@github.com:".insteadOf "https://github.com/" 8 export GOPRIVATE=github.com/aserto-dev 9 10 GIT_ON_SSH := $(git config --global url."git@github.com:".insteadOf "https://github.com/") 11 SSH_PRIVATE_KEY_FILE ?= $(HOME)/.ssh/id_rsa 12 SSH_PRIVATE_KEY ?= $(file < $(SSH_PRIVATE_KEY_FILE)) 13 14 ROOT_DIR ?= $(shell git rev-parse --show-toplevel) 15 BIN_DIR := $(ROOT_DIR)/bin 16 SRC_DIR := $(ROOT_DIR)/ 17 BINARIES := calc-version 18 19 VERSION ?= v$(shell calc-version 2>/dev/null) 20 COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null) 21 DATE ?= $(shell date "+%FT%T%z") 22 23 export VERSION 24 export SSH_PRIVATE_KEY 25 export COMMIT 26 27 LDBASE := main 28 DEV_LDFLAGS:= -ldflags "-X $(LDBASE).ver=${VERSION} -X $(LDBASE).date=${DATE} -X $(LDBASE).commit=${COMMIT}" 29 GOARCH ?= amd64 30 GOOS := $(shell go env GOOS) 31 LINTER := $(BIN_DIR)/golangci-lint 32 LINTVERSION:= v1.32.2 33 34 $(LINTER): 35 @echo -e "$(ATTN_COLOR)==> get $@ $(NO_COLOR)" 36 @curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(LINTVERSION) 37 38 $(BIN_DIR): 39 @mkdir -p $(BIN_DIR) 40 41 .PHONY: lint 42 lint: $(LINTER) 43 $(LINTER) run 44 45 .PHONY: deps 46 deps: 47 @go install . 48 49 .PHONY: dobuild 50 dobuild: 51 @echo $(DEV_LDFLAGS) 52 @GOOS=$(P) GOARCH=$(GOARCH) GO111MODULE=on go build $(DEV_LDFLAGS) -o $(T)/$(P)-$(GOARCH)/$(B)$(if $(findstring $(P),windows),".exe","") $(SRC_DIR) 53 ifneq ($(P),windows) 54 @chmod +x $(T)/$(P)-$(GOARCH)/$(B) 55 endif 56 57 .PHONY: build 58 build: $(BIN_DIR) 59 @for b in ${BINARIES}; \ 60 do \ 61 $(MAKE) dobuild B=$${b} P=${GOOS} T=${BIN_DIR}; \ 62 done 63 64 .PHONY: test 65 test: 66 @go test -count 1 -cover 67 68 .PHONY: docker-image 69 docker-image: 70 @docker build . --build-arg VERSION --build-arg SSH_PRIVATE_KEY --build-arg COMMIT -t aserto/calc-version:$(VERSION)