forked from chrismellard/kuberhealthy-terraform-drift-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (80 loc) · 3.68 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Make does not offer a recursive wildcard function, so here's one:
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
SHELL := /bin/bash
NAME = kuberhealthy-terraform-drift-check
BINARY_NAME = kh-tf-drift
GO := GO111MODULE=on go
GO_NOMOD :=GO111MODULE=off go
MAIN_SRC_FILE=main.go
export REV := $(shell git rev-parse --short HEAD 2> /dev/null || echo 'unknown')
ORG := jenkins-x-plugins
ORG_REPO := $(ORG)/$(NAME)
export ROOT_PACKAGE := github.com/$(ORG_REPO)
export GO_VERSION := 1.15
GO_DEPENDENCIES := $(call rwildcard,pkg/,*.go) $(call rwildcard,cmd/,*.go)
export BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown')
export BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
CGO_ENABLED = 0
# set dev version unless VERSION is explicitly set via environment
export VERSION ?= $(shell echo "$$(git for-each-ref refs/tags/ --count=1 --sort=-version:refname --format='%(refname:short)' 2>/dev/null)-dev+$(REV)" | sed 's/^v//')
# Full build flags used when building binaries. Not used for test compilation/execution.
BUILDFLAGS := -ldflags \
" -X $(ROOT_PACKAGE)/pkg/version.Version=$(VERSION)\
-X $(ROOT_PACKAGE)/pkg/version.Revision='$(REV)'\
-X $(ROOT_PACKAGE)/pkg/version.Branch='$(BRANCH)'\
-X $(ROOT_PACKAGE)/pkg/version.BuildDate='$(BUILD_DATE)'\
-X $(ROOT_PACKAGE)/pkg/version.GoVersion='$(GO_VERSION)'"
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: release
release: clean linux test
.PHONY: clean
clean: ## Clean the generated artifacts
rm -rf build release dist
.PHONY: goreleaser
goreleaser:
step-go-releaser --organisation=$(ORG) --revision=$(REV) --branch=$(BRANCH) --build-date=$(BUILD_DATE) --go-version=$(GO_VERSION) --root-package=$(ROOT_PACKAGE) --version=$(VERSION)
get-fmt-deps: ## Install test dependencies
$(GO_NOMOD) get golang.org/x/tools/cmd/goimports
.PHONY: fmt
fmt: importfmt ## Format the code
$(eval FORMATTED = $(shell $(GO) fmt ./...))
@if [ "$(FORMATTED)" == "" ]; \
then \
echo "All Go files properly formatted"; \
else \
echo "Fixed formatting for: $(FORMATTED)"; \
fi
.PHONY: importfmt
importfmt: get-fmt-deps
@echo "Formatting the imports..."
goimports -w $(GO_DEPENDENCIES)
.PHONY: lint
lint: ## Lint the code
./hack/gofmt.sh
./hack/linter.sh
./hack/generate.sh
.PHONY: all
all: fmt lint
.PHONY: test
test: ## Run tests with the "unit" build tag
KUBECONFIG=/cluster/connections/not/allowed $(GO) test --tags=unit -failfast -short ./...
.PHONY: build
build: $(GO_DEPENDENCIES) clean ## Build jx-labs binary for current OS
$(GO) build $(BUILDFLAGS) -o build/$(BINARY_NAME) $(MAIN_SRC_FILE)
linux: ## Build for Linux
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/linux/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/linux/$(BINARY_NAME)
arm: ## Build for ARM
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=arm $(GO) build $(BUILDFLAGS) -o build/arm/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/arm/$(BINARY_NAME)
win: ## Build for Windows
CGO_ENABLED=$(CGO_ENABLED) GOOS=windows GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/win/$(BINARY_NAME)-windows-amd64.exe $(MAIN_SRC_FILE)
darwin: ## Build for OSX
CGO_ENABLED=$(CGO_ENABLED) GOOS=darwin GOARCH=amd64 $(GO) build $(BUILDFLAGS) -o build/darwin/$(BINARY_NAME) $(MAIN_SRC_FILE)
chmod +x build/darwin/$(BINARY_NAME)