-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (167 loc) · 7.09 KB
/
Copy pathMakefile
File metadata and controls
204 lines (167 loc) · 7.09 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
# Build variables
SHELL := /usr/bin/env bash
VERSION ?= $(shell cat $(CURDIR)/VERSION)
BINARY ?= terraform-provider-oxide_$(VERSION)
BINARY_LOCATION ?= bin/$(BINARY)
OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
OS_ARCH ?= $(OS)_$(ARCH)
RELEASE_VERSION ?= $(shell cat $(CURDIR)/VERSION | sed s/-dev//g)
export GOBIN ?= $(shell pwd)/bin
# Terraform currently does not have a binary for Illumos.
# The one for Solaris works fine with Illumos, so we'll need
# to make sure we install the plugin in the solaris directory.
ifeq ($(OS), illumos)
OS_ARCH = solaris_$(ARCH)
endif
# Acceptance test variables
TEST_ACC_COUNT ?= 1
TEST_ACC ?= github.com/oxidecomputer/terraform-provider-oxide/internal/...
TEST_ACC_NAME ?= TestAcc
TEST_ACC_PARALLEL = 6
TEST_ACC_OMICRON_BRANCH ?=
TEST_ACC_SIM_HOST ?= http://localhost:12220
TEST_ACC_DOCKER_COMPOSE_FLAGS = --project-directory ./acctest --file ./acctest/docker-compose.yaml
# Unit test variables
TEST_ARGS ?= -timeout 10m -race -cover
TEST_PACKAGE ?= ./internal/...
# Helpers
GO_TOOL = go tool -modfile=tools/go.mod
### Build targets
## Builds the source code and saves the binary to bin/.
.PHONY: build
build:
@ echo "-> Building binary in $(BINARY_LOCATION)"
@ go build -o $(BINARY_LOCATION) .
## Builds the source code and installs the binary to the GOBIN path.
.PHONY: install
install:
@ echo "-> Installing plugin"
@ go install .
@ [ ! -f $(HOME)/.terraformrc ] && echo 'Missing $(HOME)/.terraformrc file. Refer to CONTRIBUTING.md for more information.' || true
## Run unit tests. Use TEST_ARGS to set `go test` CLI arguments, and TEST_UNIT_DIR to set packages to be tested
.PHONY: test
test:
@ echo "-> Running unit tests for $(BINARY)"
@ $(GO_TOOL) gotestsum \
--format=testname --hide-summary=skipped --rerun-fails=3 --packages=$(TEST_PACKAGE) $(TEST_GOTESTSUM_ARGS) \
-- $(TEST_PACKAGE) $(TEST_ARGS) $(TESTUNITARGS) -run '$(TEST_NAME)'
.PHONY: docs
docs:
@ $(GO_TOOL) tfplugindocs generate
.PHONY: check-docs
check-docs:
@ $(GO_TOOL) tfplugindocs generate
@ if ! git diff --exit-code docs; then echo 'Generated docs have changed. Re-generate with `make docs`.'; fi
## Lints all of the source files
.PHONY: lint
lint: golangci-lint tfproviderdocs terrafmt tfproviderlint check-docs # configfmt
.PHONY: tfproviderlint
tfproviderlint:
@ echo "-> Running Terraform static analysis linter"
@ $(GO_TOOL) tfproviderlint ./...
.PHONY: tfproviderdocs
tfproviderdocs:
@ echo "-> Running terraform provider documentation linter"
@ $(GO_TOOL) tfproviderdocs check -provider-name $(BINARY) .
.PHONY: golangci-lint
golangci-lint:
@ echo "-> Running Go linters"
@ $(GO_TOOL) golangci-lint run
.PHONY: fmt
fmt: golangci-fmt terrafmt-fmt docs
.PHONY: golangci-fmt
golangci-fmt:
@ echo "-> Formatting Go code"
@ $(GO_TOOL) golangci-lint fmt
@ $(GO_TOOL) golangci-lint run --enable-only=goheader --fix
.PHONY: terrafmt
terrafmt:
@ echo "-> Running terraform docs codeblocks linter"
@ find ./docs -type f -name "*.md" -exec $(GO_TOOL) terrafmt diff -f {} \;
.PHONY: terrafmt-fmt
terrafmt-fmt:
@ echo "-> Running terraform docs codeblocks linter"
@ find ./docs -type f -name "*.md" -exec $(GO_TOOL) terrafmt fmt -f {} \;
configfmt:
@ echo "-> Running terraform linters on .tf files"
@ terraform fmt -write=false -recursive -check
.PHONY: fmt-md
fmt-md: ## Formats markdown files with prettier.
@ echo "-> Formatting markdown files"
@ npx prettier --write "**/*.md"
.PHONY: testacc-sim
## Starts a simulated omicron environment suitable to run the acceptance test suite.
testacc-sim: testacc-sim-docker testacc-sim-setup
.PHONY: testacc-sim-down
## Stops the containers of the simulated acceptance test suite environment.
testacc-sim-down:
@ docker compose $(TEST_ACC_DOCKER_COMPOSE_FLAGS) down
.PHONY: testacc-sim-docker
## Starts the containers for the simulated acceptance test suite environment.
testacc-sim-docker: export TEST_ACC_DOCKER_TAG = $(shell ./acctest/omicron-version.sh $(TEST_ACC_OMICRON_BRANCH))
testacc-sim-docker:
@ ./acctest/ensure-image.sh $(TEST_ACC_DOCKER_TAG)
@ docker compose $(TEST_ACC_DOCKER_COMPOSE_FLAGS) up --wait --wait-timeout 1500
.PHONY: testacc-sim-token
## Generates an auth token for the simulated acceptance test suite environment.
testacc-sim-token:
@ uv run ./acctest/auth.py --host $(TEST_ACC_SIM_HOST) > ./acctest/oxide-token
.PHONY: testacc-sim-oxide-cli
## Installs the version of the oxide CLI matching the current omicron version.
testacc-sim-oxide-cli:
@ ./acctest/ensure-oxide-cli.sh
.PHONY: testacc-sim-setup
## Configures the simulated acceptance test suite environment.
testacc-sim-setup: testacc-sim-token testacc-sim-oxide-cli
@ PATH=$(GOBIN):$$PATH OXIDE_TOKEN=$(shell cat ./acctest/oxide-token) OXIDE_HOST=$(TEST_ACC_SIM_HOST) ./scripts/acc-test-setup.sh
.PHONY: testacc
## Runs the Terraform acceptance tests. Use TEST_ACC_NAME, TEST_ACC_ARGS, TEST_ACC_GOTESTSUM_ARGS, TEST_ACC_COUNT and TEST_ACC_PARALLEL for acceptance testing settings.
# acctest/terraformrc neutralizes any dev_overrides in ~/.terraformrc so the
# ExternalProviders pins used by state-upgrade tests resolve from the registry.
testacc: export TF_CLI_CONFIG_FILE = $(CURDIR)/acctest/terraformrc
testacc:
@ echo "-> Running terraform acceptance tests"
@ TF_ACC=1 $(GO_TOOL) gotestsum \
--format=testname --rerun-fails=3 --packages=$(TEST_ACC) $(TEST_ACC_GOTESTSUM_ARGS) \
-- $(TEST_ACC) -v -count $(TEST_ACC_COUNT) -parallel $(TEST_ACC_PARALLEL) $(TEST_ACC_ARGS) -timeout 20m -run $(TEST_ACC_NAME)
.PHONY: testacc-local
## Runs the Terraform acceptance tests locally using the simulated acceptance test suite environment.
## Use TEST_ACC_NAME, TEST_ACC_ARGS, TEST_ACC_COUNT and TEST_ACC_PARALLEL for acceptance testing settings.
testacc-local: export OXIDE_HOST=$(TEST_ACC_SIM_HOST)
testacc-local: export OXIDE_TOKEN=$(shell cat ./acctest/oxide-token)
testacc-local: testacc
.PHONY: local-api
## Use local Go SDK.
local-api:
@ echo "Initializing go.work"
@ go work init 2> /dev/null || true
@ go work use . ../oxide.go
.PHONY: unset-local-api
## Stop using local Go SDK.
unset-local-api:
rm -f go.work go.work.sum
.PHONY: changelog
## Creates a changelog prior to a release
changelog: tools-private
@ echo "-> Creating changelog"
@ $(GOBIN)/whatsit changelog create --repository oxidecomputer/terraform-provider-oxide -n $(RELEASE_VERSION) -c ./.changelog/$(RELEASE_VERSION).toml
.PHONY: tag
tag: ## Create a new git tag to prepare to build a release.
git tag v$(RELEASE_VERSION)
@echo "Run 'git push origin v$(RELEASE_VERSION)' to push your new tag to GitHub and trigger a release."
.PHONY: sdk-version
## Sets Oxide Go SDK to a specified version
sdk-version:
@ echo "-> Setting Oxide Go SDK to oxide.go@$(SDK_V)"
@ go get github.com/oxidecomputer/oxide.go@$(SDK_V)
@ go mod tidy
# whatsit is a Rust tool used for changelog generation, installed via cargo.
VERSION_WHATSIT:=053446d
tools-private: $(GOBIN)/whatsit
$(GOBIN):
@ mkdir -p $(GOBIN)
# TODO: actually release a version of whatsit to use the tag flag
$(GOBIN)/whatsit: | $(GOBIN)
@ echo "-> Installing whatsit..."
@ cargo install --git ssh://git@github.com/oxidecomputer/whatsit.git#$(VERSION_WHATSIT) --branch main --root ./