-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
121 lines (99 loc) · 3.37 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
.PHONY: all-release build clean fmt fmt-go fmt-terraform lint lint-go lint-terraform release test vendor vendor-status vet
ARCH ?= amd64
PLATFORM ?= linux
ALL_PLATFORMS := darwin linux windows
BIN := terraform-provider-vultr
PKG := github.com/squat/$(BIN)
BUILD_IMAGE ?= golang:1.10.0-alpine
TEST ?= $$(go list ./... | grep -v 'vendor/')
GOFMT_FILES ?= $$(find . -name '*.go' | grep -v vendor)
SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
TERRAFORMFMT_FILES ?= examples
TESTARGS ?=
TAG := $(shell git describe --abbrev=0 --tags HEAD 2>/dev/null)
COMMIT := $(shell git rev-parse HEAD)
VERSION := $(COMMIT)
ifneq ($(TAG),)
ifeq ($(COMMIT), $(shell git rev-list -n1 $(TAG)))
VERSION := $(TAG)
endif
endif
DIRTY := $(shell test -z "$$(git diff --shortstat 2>/dev/null)" || echo -dirty)
VERSION := $(VERSION)$(DIRTY)
default: build
build:
go install
all-release: $(addprefix release-, $(ALL_PLATFORMS))
release-%:
@$(MAKE) --no-print-directory ARCH=$(ARCH) PLATFORM=$* release
release: bin/$(BIN)_$(VERSION)_$(PLATFORM)_$(ARCH).tar.gz.asc
bin/$(PLATFORM)/$(ARCH):
@mkdir -p bin/$(PLATFORM)/$(ARCH)
bin/$(BIN)_$(VERSION)_$(PLATFORM)_$(ARCH).tar.gz.asc: bin/$(BIN)_$(VERSION)_$(PLATFORM)_$(ARCH).tar.gz
@cd bin && gpg --armor --detach-sign $(<F)
bin/$(BIN)_$(VERSION)_$(PLATFORM)_$(ARCH).tar.gz: bin/$(PLATFORM)/$(ARCH)/$(BIN)_$(VERSION)
@tar -czf $@ -C $(<D) $(<F)
bin/$(PLATFORM)/$(ARCH)/$(BIN)_$(VERSION): $(SRC) glide.yaml bin/$(PLATFORM)/$(ARCH)
@echo "building: $@"
@docker run --rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/go/src/$(PKG) \
-v $$(pwd)/bin/$(PLATFORM)/$(ARCH):/go/bin \
-w /go/src/$(PKG) \
$(BUILD_IMAGE) \
/bin/sh -c " \
GOARCH=$(ARCH) \
GOOS=$(PLATFORM) \
CGO_ENABLED=0 \
go build -o /go/bin/$(BIN)_$(VERSION) \
"
fmt: fmt-go fmt-terraform
fmt-go:
gofmt -w -s $(GOFMT_FILES)
fmt-terraform:
terraform fmt $(TERRAFORMFMT_FILES)
lint: lint-go lint-terraform
lint-go:
@echo 'golint $(TEST)'
@lint_res=$$(golint $(TEST)); if [ -n "$$lint_res" ]; then \
echo ""; \
echo "Golint found style issues. Please check the reported issues"; \
echo "and fix them if necessary before submitting the code for review:"; \
echo "$$lint_res"; \
exit 1; \
fi
@echo 'gofmt -d -s $(GOFMT_FILES)'
@fmt_res=$$(gofmt -d -s $(GOFMT_FILES)); if [ -n "$$fmt_res" ]; then \
echo ""; \
echo "Gofmt found style issues. Please check the reported issues"; \
echo "and fix them if necessary before submitting the code for review:"; \
echo "$$fmt_res"; \
exit 1; \
fi
lint-terraform:
@echo "terraform fmt --check=true $(TERRAFORMFMT_FILES)"
@lint_res=$$(terraform fmt --check=true $(TERRAFORMFMT_FILES)); if [ -n "$$lint_res" ]; then \
echo ""; \
echo "Terraform fmt found style issues. Please check the reported issues"; \
echo "and fix them if necessary before submitting the code for review:"; \
echo "$$lint_res"; \
exit 1; \
fi
test: vet lint
go test -i $(TEST) || exit 1
go test $(TESTARGS) -timeout=30s -parallel=4 $(TEST)
vendor:
@glide install -v
@glide-vc --only-code --no-tests
vendor-status:
@glide list
vet:
@echo 'go vet $(TEST)'
@go vet $(TEST); if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi
clean:
@rm -rf bin