This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
76 lines (58 loc) · 2.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# These shell flags are REQUIRED for an early exit in case any program called by make errors!
.SHELLFLAGS=-euo pipefail -c
SHELL := /bin/bash
.PHONY: all fmt clean check build tidy docker-build docker-push goimports golangci-lint
REPO := quay.io/mtsre/mtsre-clusters-checker
TAG := $(shell git rev-parse --short HEAD)
RELEASE_TAG := $(shell git tag --points-at HEAD)
# Set the GOBIN environment variable so that dependencies will be installed
# always in the same place, regardless of the value of GOPATH
CACHE := $(PWD)/.cache
export GOBIN := $(CACHE)/bin
export PATH := $(GOBIN):$(PATH)
all: build
clean: ## Clean this directory
@rm -fr $(CACHE) $(GOBIN) bin/* dist/ || true
build: tidy ## Build binaries
@CGO_ENABLED=0 go build -a -o bin/clusters-checker main.go
release:
$(eval TAG := $(shell git tag --points-at HEAD))
@make docker-build docker-push
run: build
@bin/mtsre-clusters-checker
tidy:
@go mod tidy
@go mod verify
fmt:
@go fmt ./...
check: golangci-lint goimports
docker-build:
@docker build -t $(REPO):$(TAG) .
docker-push:
@if [ -z "$(DOCKER_CONF)" ]; then echo "Please set DOCKER_CONF. Exiting." && exit 1; fi
@docker tag $(REPO):$(TAG) $(REPO):latest
@docker --config=$(DOCKER_CONF) push $(REPO):$(TAG)
@docker --config=$(DOCKER_CONF) push $(REPO):latest
GOIMPORTS := $(GOBIN)/goimports
goimports:
@$(call go-get-tool,$(GOIMPORTS),golang.org/x/tools/cmd/goimports)
@$(GOIMPORTS) -w -l $(shell find . -type f -name "*.go" -not -path "./vendor/*")
GOLANGCI_LINT := $(GOBIN)/golangci-lint
golangci-lint:
@$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/[email protected])
@echo "Running golangci-lint..."
@$(GOLANGCI_LINT) run --timeout=10m -E unused,gosimple,staticcheck --skip-dirs-use-default --verbose
# go-get-tool will 'go get' any package $2 and install it to $1.
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)