-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
151 lines (111 loc) · 3.98 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
MOD_ENV := GO111MODULE=on GO15VENDOREXPERIMENT=1
GO := $(MOD_ENV) go
GOPATH := $(shell go env GOPATH)
GO_NOMOD := GO111MODULE=off go
GOPATH_FIRST := $(shell echo ${GOPATH} | cut -f1 -d':')
GOBIN := $(shell [ -n "${GOBIN}" ] && echo ${GOBIN} || (echo $(GOPATH_FIRST)/bin))
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
GO_VERSION_MAJ := $(shell echo $(GO_VERSION) | cut -f1 -d'.')
GO_VERSION_MIN := $(shell echo $(GO_VERSION) | cut -f2 -d'.')
# directories with sources
SRC_DIRS = pkg internal
TEST ?= $$(go list ./... 2>/dev/null |grep -v 'vendor')
TESTARGS ?= -vet=off
GOFMT_FILES ?= $$(find $(SRC_DIRS) -name '*.go' |grep -v vendor)
WEBSITE_REPO = github.com/hashicorp/terraform-website
WIKI_REPO = $(shell echo `pwd`.wiki)
# for some unknown reason, "provisioners" are only recognized in this directory
PLUGINS_DIR = $$HOME/.terraform.d/plugins
# the deployment used for running the E2E tests
E2E_ENV := $(shell echo `pwd`)/docs/examples/dnd
export GOPATH
export GOBIN
export E2E_ENV
all: build
default: build
build: fmtcheck build-forced
$(PLUGINS_DIR):
mkdir -p $(PLUGINS_DIR)
build-forced: $(PLUGINS_DIR)
$(GO) build -v -o $(PLUGINS_DIR)/terraform-provider-kubeadm ./cmd/terraform-provider-kubeadm
$(GO) build -v -o $(PLUGINS_DIR)/terraform-provisioner-kubeadm ./cmd/terraform-provisioner-kubeadm
generate:
cd internal/assets && $(GO) generate -x
cd pkg/provider && $(GO) generate -x
cd pkg/provisioner && $(GO) generate -x
install: build-forced
.PHONY: vendor
vendor:
$(GO) mod tidy
$(GO) mod vendor
################################################
test: fmtcheck
@echo ">>> Running tests in $(TEST)..."
$(GO) test -race $(TESTARGS) $(TEST) || exit 1
# echo $(TEST) | $(MOD_ENV) xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
testacc: fmtcheck
@echo ">>> Running acceptance tests in $(TEST)..."
TF_ACC=1 $(GO) test $(TEST) $(TESTARGS) -timeout 120m
test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo ">>> ERROR: Set TEST to a specific package. For example,"; \
echo ">>> make test-compile TEST=./pkg/provisioner"; \
exit 1; \
fi
$(GO) test -c $(TEST) $(TESTARGS)
tests-e2e: ci-tests-e2e
e2e: ci-tests-e2e
e2e-cleanup: ci-tests-e2e-cleanup
e2e-destroy: ci-tests-e2e-cleanup
e2e-logs: ci-tests-e2e-logs
################################################
vet:
@echo ">>> Checking code with 'go vet'"
@$(GO) vet $$($(GO) list ./... | grep -v vendor/) ; 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
fmt:
gofmt -w $(GOFMT_FILES)
fmtcheck:
@sh -c "'$(CURDIR)/utils/gofmtcheck.sh'"
errcheck:
@sh -c "'$(CURDIR)/utils/errcheck.sh'"
################################################
# CI targets (for Travis)
ci-save-env:
# NOTE: "sudo" in travis resets the environment to "safe" values
# (loaded from "/etc/environment"), so we save our current env
# in that file
@env PATH=/snap/bin:${PATH} > /tmp/environment
@echo ">>> Current environment:"
@cat /tmp/environment
@sudo mv -f /tmp/environment /etc/environment
ci-tests-style: fmtcheck vet errcheck
ci-tests-unit: test
ci-tests-e2e: build
@make -C tests/e2e ci-tests
ci-tests-e2e-cleanup:
@make -C tests/e2e ci-cleanup E2E_CLEANUP="true"
ci-tests-e2e-logs:
@make -C tests/e2e ci-logs
ci: ci-tests
# entrypoints: ci-tests and ci-setup
ci-tests: ci-tests-unit ci-tests-style ci-tests-e2e
ci-setup:
@make -C tests/e2e ci-setup
@make ci-save-env
################################################
wiki:
@echo ">>> Copying markdown file to $(WIKI_REPO)"
@rm -rf $(WIKI_REPO)/*
@rsync -av --delete \
--exclude=.git \
--exclude=examples \
docs/ $(WIKI_REPO)/
@echo ">>> Done. You must commit changes in the wiki repo!"
################################################
rpm:
cd osc && osc build