-
Notifications
You must be signed in to change notification settings - Fork 47
/
GNUmakefile
80 lines (63 loc) · 2.25 KB
/
GNUmakefile
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
TEST?=./...
# Project variables
NAME := terraform-provider-confluentcloud
# Build variables
BUILD_DIR := bin
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo "v0.0.0-$(COMMIT_HASH)")
# Go variables
GOCMD := GO111MODULE=on go
GOBUILD ?= CGO_ENABLED=0 $(GOCMD) build
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOFILES ?= $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: all
all: clean test lint build
.PHONY: checkfmt
checkfmt: RESULT = $(shell goimports -l $(GOFILES) | tee >(if [ "$$(wc -l)" = 0 ]; then echo "OK"; fi))
checkfmt: SHELL := /usr/bin/env bash
checkfmt: ## Check formatting of all go files
@ echo "$(RESULT)"
@ if [ "$(RESULT)" != "OK" ]; then exit 1; fi
.PHONY: fmt
fmt: ## Format all go files
@ $(MAKE) --no-print-directory log-$@
goimports -w $(GOFILES)
.PHONY: lint
lint: ## Run linter
@ $(MAKE) --no-print-directory log-$@
GO111MODULE=on golangci-lint run ./...
.PHONY: clean
clean: ## Clean workspace
@ $(MAKE) --no-print-directory log-$@
rm -rf ./$(BUILD_DIR)
.PHONY: build
build: clean ## Build binary for current OS/ARCH
@ $(MAKE) --no-print-directory log-$@
$(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(NAME)
.PHONY: build-all
build-all: GOOS = linux darwin
build-all: GOARCH = amd64
build-all: clean ## Build binary for all OS/ARCH
@ $(MAKE) --no-print-directory log-$
@ ./scripts/build/build-all-osarch.sh "$(BUILD_DIR)" "$(NAME)" "$(VERSION)" "$(GOOS)" "$(GOARCH)"
.PHONY: test
test:
$(GOCMD) test ./...
.PHONY: testacc
testacc:
TF_LOG=debug TF_ACC=1 $(GOCMD) test $(TEST) -v $(TESTARGS) -timeout 120m
.PHONY: gox
gox:
GO111MODULE=off go get -u github.com/mitchellh/gox
.PHONY: goimports
goimports:
GO111MODULE=off go get -u golang.org/x/tools/cmd/goimports
.PHONY: golangci
golangci:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)
.PHONY: tools
tools: ## Install required tools
@ $(MAKE) --no-print-directory log-$@
@ $(MAKE) --no-print-directory goimports golangci gox
log-%:
@ grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m==> %s\033[0m\n", $$2}'