-
Notifications
You must be signed in to change notification settings - Fork 178
/
GNUmakefile
191 lines (153 loc) · 6.54 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
ifdef ACCTEST_PACKAGES
# remove newlines and blanks coming from GH Actions
ACCTEST_PACKAGES := $(strip $(subst $(newline),, $(ACCTEST_PACKAGES)))
else
ACCTEST_PACKAGES := "./..."
endif
ACCTEST_REGEX_RUN?=^TestAcc
ACCTEST_TIMEOUT?=300m
PARALLEL_GO_TEST?=50
BINARY_NAME=terraform-provider-mongodbatlas
DESTINATION=./bin/$(BINARY_NAME)
GOFLAGS=-mod=vendor
GITTAG=$(shell git describe --always --tags)
VERSION=$(GITTAG:v%=%)
LINKER_FLAGS=-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=${VERSION}'
GOLANGCI_VERSION=v1.62.2 # Also update golangci-lint GH action in code-health.yml when updating this version
export PATH := $(shell go env GOPATH)/bin:$(PATH)
export SHELL := env PATH=$(PATH) /bin/bash
default: build
.PHONY: help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: fmt fmtcheck
go build -ldflags "$(LINKER_FLAGS)" -o $(DESTINATION)
.PHONY: install
install: fmtcheck
go install -ldflags="$(LINKER_FLAGS)"
.PHONY: test
test: fmtcheck
go test ./... -timeout=30s -parallel=4 -race
.PHONY: testacc
testacc: fmtcheck
@$(eval VERSION=acc)
TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)"
.PHONY: testaccgov
testaccgov: fmtcheck
@$(eval VERSION=acc)
TF_ACC=1 go test ./... -run 'TestAccProjectRSGovProject_CreateWithProjectOwner' -v -parallel 1 "$(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags=$(LINKER_FLAGS) "
.PHONY: fmt
fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w .
.PHONY: fmtcheck
fmtcheck: ## Currently required by tf-deploy compile
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
.PHONY: lint-fix
lint-fix:
@echo "==> Fixing linters errors..."
fieldalignment -json -fix ./...
golangci-lint run --fix
.PHONY: lint
lint:
@echo "==> Checking source code against linters..."
golangci-lint run
.PHONY: tools
tools: ## Install dev tools
@echo "==> Installing dependencies..."
go telemetry off # disable sending telemetry data, more info: https://go.dev/doc/telemetry
go install github.com/icholy/gomajor@latest
go install github.com/terraform-linters/[email protected]
go install github.com/rhysd/actionlint/cmd/actionlint@latest
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest
go install github.com/hashicorp/terraform-plugin-codegen-framework/cmd/tfplugingen-framework@latest
go install github.com/hashicorp/go-changelog/cmd/changelog-build@latest
go install github.com/hashicorp/go-changelog/cmd/changelog-entry@latest
go install golang.org/x/tools/cmd/goimports@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)
.PHONY: docs
docs:
@echo "Use this site to preview markdown rendering: https://registry.terraform.io/tools/doc-preview"
.PHONY: tflint
tflint: fmtcheck
tflint -f compact --recursive --minimum-failure-severity=warning
.PHONY: tf-validate
tf-validate: fmtcheck
scripts/tf-validate.sh
.PHONY: link-git-hooks
link-git-hooks: ## Install git hooks
@echo "==> Installing all git hooks..."
find .git/hooks -type l -exec rm {} \;
find .githooks -type f -exec ln -sf ../../{} .git/hooks/ \;
.PHONY: update-atlas-sdk
update-atlas-sdk: ## Update the atlas-sdk dependency
./scripts/update-sdk.sh
# e.g. run: make scaffold resource_name=streamInstance type=resource
# - type argument can have the values: `resource`, `data-source`, `plural-data-source`.
# details on usage can be found in contributing/development-best-practices.md under "Scaffolding initial Code and File Structure"
.PHONY: scaffold
scaffold:
@go run ./tools/scaffold/*.go $(resource_name) $(type)
@echo "Reminder: configure the new $(type) in provider.go"
# e.g. run: make scaffold-schemas resource_name=streamInstance
# details on usage can be found in contributing/development-best-practices.md under "Generating Schema and Model Definitions - Using schema generation HashiCorp tooling"
.PHONY: scaffold-schemas
scaffold-schemas:
@scripts/schema-scaffold.sh $(resource_name)
# e.g. run: make generate-schema resource_name=search_deployment
# resource_name is optional, if not provided all configured resources will be generated
# details on usage can be found in contributing/development-best-practices.md under "Generating Schema and Model Definitions - Using internal tool"
.PHONY: generate-schema
generate-schema:
@go run ./tools/codegen/main.go $(resource_name)
.PHONY: generate-doc
# e.g. run: make generate-doc resource_name=search_deployment
# generate the resource documentation via tfplugindocs
generate-doc:
@scripts/generate-doc.sh ${resource_name}
# generate the resource documentation via tfplugindocs for all resources that have templates
.PHONY: generate-docs-all
generate-docs-all:
@scripts/generate-docs-all.sh
.PHONY: update-tf-compatibility-matrix
update-tf-compatibility-matrix: ## Update Terraform Compatibility Matrix documentation
./scripts/update-tf-compatibility-matrix.sh
.PHONY: update-tf-version-in-repository
update-tf-version-in-repository: ## Update Terraform versions
./scripts/update-tf-version-in-repository.sh
.PHONY: update-changelog-unreleased-section
update-changelog-unreleased-section:
./scripts/update-changelog-unreleased-section.sh
.PHONY: generate-changelog-entry
generate-changelog-entry:
./scripts/generate-changelog-entry.sh
.PHONY: check-changelog-entry-file
check-changelog-entry-file:
go run ./tools/check-changelog-entry-file/*.go
.PHONY: jira-release-version
jira-release-version:
go run ./tools/jira-release-version/*.go
.PHONY: enable-advancedclustertpf
enable-advancedclustertpf:
make change-lines filename=./internal/config/advanced_cluster_v2_schema.go find="allowAdvancedClusterV2Schema = false" new="allowAdvancedClusterV2Schema = true"
.PHONY: delete-lines ${filename} ${delete}
delete-lines:
rm -f file.tmp
grep -v "${delete}" "${filename}" > file.tmp
mv file.tmp ${filename}
goimports -w ${filename}
.PHONY: add-lines ${filename} ${find} ${add}
add-lines:
rm -f file.tmp
sed 's/${find}/${find}${add}/' "${filename}" > "file.tmp"
mv file.tmp ${filename}
goimports -w ${filename}
.PHONY: change-lines ${filename} ${find} ${new}
change-lines:
rm -f file.tmp
sed 's/${find}/${new}/' "${filename}" > "file.tmp"
mv file.tmp ${filename}
goimports -w ${filename}