-
Notifications
You must be signed in to change notification settings - Fork 14
/
GNUmakefile
172 lines (143 loc) · 5.91 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Tooling versions
GOLANGCILINTVERSION?=1.52.2
GOIMPORTSVERSION?=v0.1.2
GOXVERSION?=v1.0.1
GOTESTSUMVERSION?=v1.6.4
TEST?=$$(go list ./... |grep -v 'vendor' | grep -v 'integration')
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=lacework
DIR=~/.terraform.d/plugins
CIARTIFACTS?=ci-artifacts
GOJUNITOUT?=tf-provider-go-junit.xml
GO_CLIENT_VERSION=master
COVERAGEOUT?=coverage.out
GOFLAGS=-mod=vendor
CGO_ENABLED?=0
PACKAGENAME?=terraform-provider-lacework
VERSION=$(shell cat VERSION)
BINARY_PATH="registry.terraform.io/lacework/lacework/99.0.0/$$(go env GOOS)_$$(go env GOARCH)/terraform-provider-lacework_v99.0.0"
export GOFLAGS CGO_ENABLED
.PHONY: help
help:
@echo "-------------------------------------------------------------------"
@echo "Lacework terraform-provider-lacework Makefile helper:"
@echo ""
@grep -Fh "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\\$$//' | sed -E 's/^([^:]*):.*##(.*)/ \1 -\2/'
@echo "-------------------------------------------------------------------"
default: build
.PHONY: ci
ci: lint test fmtcheck imports-check ## *CI ONLY* Runs tests on CI pipeline
.PHONY: prepare
prepare: install-tools go-vendor ## Initialize the go environment
.PHONY: release
release: build-cross-platform ## *CI ONLY* Prepares a release of the Terraform provider
scripts/release.sh prepare
.PHONY: deps
deps: go-deps go-vendor ## Update dependencies and run go-vendor
.PHONY: alldeps
go-deps: ## Update dependencies, provider UPDATE_DEP env variable to update just a single dependency
@go get -u "$(UPDATE_DEP)"
PHONY: go-vendor
go-vendor: ## Runs go mod tidy, vendor and verify to cleanup, copy and verify dependencies
go mod tidy
go mod vendor
go mod verify
.PHONY: build
build: fmtcheck ## Runs fmtcheck and go install
go install
.PHONY: build-cross-platform
build-cross-platform: ## Compiles the Terraform-Provider-Lacework for all supported platforms
gox -output="bin/$(PACKAGENAME)_$(VERSION)_{{.OS}}_{{.Arch}}" \
-os="linux windows freebsd" \
-osarch="darwin/amd64 darwin/arm64 linux/arm linux/arm64 freebsd/arm freebsd/arm64" \
-arch="amd64 386" \
github.com/lacework/$(PACKAGENAME)
.PHONY: install
install: write-terraform-rc fmtcheck ## Updates the terraformrc to point to the BINARY_PATH. Installs the provider to the BINARY_PATH
mkdir -vp $(DIR)
go build -o $(DIR)/$(BINARY_PATH)
.PHONY: uninstall
uninstall: remove-terraform-rc ## Removes installed provider package from BINARY_PATH
@rm -rvf "$(HOME)/.terraform.d/plugins/registry.terraform.io/lacework/lacework"
@rm -vf $(DIR)/$(PACKAGENAME)
.PHONY: integration-test
integration-test: clean-test install ## Runs clean-test and install, then runs all integration tests
gotestsum -f testname -- -v ./integration -run=$(regex)
.PHONY: test-go-junit-ci
test-go-junit-ci: clean-test install ## Runs clean-test and install, then runs all integration tests and output as junit xml format
mkdir -p $(CIARTIFACTS)
go test -v ./integration 2>&1 | go-junit-report > "$(CIARTIFACTS)/$(GOJUNITOUT)"
.PHONY: test
test: fmtcheck ## Runs fmtcheck then runs all unit tests
gotestsum -f testname -- -v -cover -coverprofile=$(COVERAGEOUT) $(TEST)
.PHONY: lint
lint: ## Runs go linter
golangci-lint run
.PHONY: testacc
testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
.PHONY: vet
vet: ## Runs go vet
@echo "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
.PHONY: fmt
fmt: ## Runs go formatter
gofmt -w $(GOFMT_FILES)
.PHONY: fmtcheck
fmtcheck: ## Runs formatting check
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
.PHONY: errcheck
errcheck: ## Runs error checking
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"
.PHONY: test-compile
test-compile: ## Compile tests
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)
.PHONY: website
website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.PHONY: website-test
website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.PHONY: install-tools
install-tools: ## Install go indirect dependencies
ifeq (, $(shell which golangci-lint))
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v$(GOLANGCILINTVERSION)
endif
ifeq (, $(shell which goimports))
GOFLAGS=-mod=readonly go install golang.org/x/tools/cmd/goimports@$(GOIMPORTSVERSION)
endif
ifeq (, $(shell which gox))
GOFLAGS=-mod=readonly go install github.com/mitchellh/gox@$(GOXVERSION)
endif
ifeq (, $(shell which gotestsum))
GOFLAGS=-mod=readonly go install gotest.tools/gotestsum@$(GOTESTSUMVERSION)
endif
.PHONY: write-terraform-rc
write-terraform-rc: ## Write to terraformrc file to mirror lacework/lacework to BINARY_PATH
scripts/mirror-provider.sh
.PHONY: remove-terraform-rc
remove-terraform-rc: ## Remove the terraformrc file
@rm -vf "$(HOME)/.terraformrc"
.PHONY: clean-test
clean-test: ## Find and remove any .terraform directories or tfstate files
find . -name ".terraform*" -type f -exec rm -rf {} \;
find . -name "terraform.tfstate*" -type f -exec rm -rf {} \;