-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
260 lines (225 loc) · 9.91 KB
/
Makefile
File metadata and controls
260 lines (225 loc) · 9.91 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
GOFMT_FILES?=$$(find . -name '*.go')
BINARY_NAME=terraform-provider-couchbase-capella
DESTINATION=./bin/$(BINARY_NAME)
GOFLAGS=-mod=vendor
GOOPTS="-p 2"
GITTAG=$(shell git describe --tags --abbrev=0)
VERSION=$(GITTAG:v%=%)
LINKER_FLAGS=-s -w -X 'github.com/couchbasecloud/terraform-provider-couchbase-capella/version.ProviderVersion=${VERSION}'
GOLANGCI_VERSION=v1.64.8
# OpenAPI spec URL - fetched at runtime, never stored in repo
# The spec is embedded in the Couchbase docs page and extracted automatically
OPENAPI_SPEC_URL?=https://docs.couchbase.com/cloud/management-api-reference/index.html
export OPENAPI_SPEC_URL
export PATH := $(shell go env GOPATH)/bin:$(PATH)
export SHELL := env "PATH=$(PATH)" /bin/bash
default: build
ifndef $(GOPATH)
GOPATH=$(shell go env GOPATH)
endif
.PHONY: help
help: ## Show this help message
@echo "Terraform Provider Couchbase Capella - Available Commands:"
@echo ""
@grep -h -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Quick Start:"
@echo " make setup - Install all dev tools"
@echo " make check - Run all quality checks"
@echo " make test - Run unit tests"
@echo " make testacc - Run acceptance tests"
# ============================================================================
# Build
# ============================================================================
.PHONY: build
build: ## Build the provider binary
@$(MAKE) fmt
@go build -ldflags "$(LINKER_FLAGS)" -o $(DESTINATION)
# ============================================================================
# Code Quality
# ============================================================================
.PHONY: setup
setup: ## Install all dev tools
@echo "==> Installing dependencies..."
@go install github.com/client9/misspell/cmd/misspell@latest
@go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@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: check
check: ## Run all quality checks (fmt, lint, test)
@$(MAKE) setup tffmt fmt docs-lint lint-fix test
.PHONY: fmt
fmt: ## Format Go code
@echo "==> Fixing source code with gofmt and goimports..."
@gofmt -s -w $(GOFMT_FILES)
@find . -name "*.go" -exec goimports -w -local github.com/couchbasecloud/terraform-provider-couchbase-capella {} \;
.PHONY: tffmt
tffmt: ## Format Terraform files
@terraform fmt -write -recursive -diff .
.PHONY: lint-fix
lint-fix: ## Fix linter errors automatically
@echo "==> Fixing linter errors..."
@golangci-lint run --fix
.PHONY: vet
vet: ## Run go vet
@echo "==> Running go vet..."
@go vet ./... ; if [ $$? -ne 0 ]; 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: tfcheck
tfcheck: ## Check Terraform formatting
@terraform fmt -check=true -diff -recursive .
.PHONY: docs-lint
docs-lint: ## Lint documentation
@echo "==> Checking docs against linters..."
@misspell -error -source=text docs/
# ============================================================================
# Testing
# ============================================================================
TEST_FILES ?= $$(go list ./... | grep -v acceptance_tests)
TEST_FLAGS ?= -short -cover -race -coverprofile .testCoverage.txt
.PHONY: test
test: ## Run unit tests
@go test $(TEST_FILES) $(TEST_FLAGS)
.PHONY: testacc
testacc: ## Run acceptance tests (requires TF_VAR_auth_token, TF_VAR_host, TF_VAR_organization_id)
@[ "${TF_VAR_auth_token}" ] || ( echo "ERROR: export TF_VAR_auth_token before running acceptance tests"; exit 1 )
@[ "${TF_VAR_host}" ] || ( echo "ERROR: export TF_VAR_host before running acceptance tests"; exit 1 )
@[ "${TF_VAR_organization_id}" ] || ( echo "ERROR: export TF_VAR_organization_id before running acceptance tests"; exit 1 )
@TF_ACC=1 go test -timeout=180m -v ./acceptance_tests/
# ============================================================================
# Documentation
# ============================================================================
.PHONY: build-docs
build-docs: ## Generate provider documentation
@go get github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
@go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --examples-dir ./examples
# ============================================================================
# Code Generation
# ============================================================================
.PHONY: gen-api
gen-api: ## Generate OpenAPI client code
@echo "==> Generating OpenAPI client (internal/generated/api)"
@PATH="$(shell go env GOPATH)/bin:$(PATH)" go generate ./internal/generated/api
@echo "==> Done"
.PHONY: gen-enums
gen-enums: ## Generate enum validator constants from OpenAPI spec
@echo "==> Fetching OpenAPI spec from $(OPENAPI_SPEC_URL)"
@go run ./internal/generated/enums/openapi_loader
@echo "==> Generating enum constants (internal/generated/enums)"
@go run ./internal/generated/enums/generate/ > ./internal/generated/enums/enums.gen.go
@echo "==> Done"
# ============================================================================
# Release Management
# ============================================================================
.PHONY: release-changelog
release-changelog: ## Generate only the changelog (usage: make release-changelog VERSION=1.5.4)
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION not specified"; \
echo "Usage: make release-changelog VERSION=1.5.4"; \
exit 1; \
fi
$(eval PREV_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v1.5.3"))
@echo "Generating changelog from $(PREV_VERSION) to v$(VERSION)..."
@bash scripts/generate-changelog.sh v$(VERSION) $(PREV_VERSION)
@echo ""
@echo "SUCCESS: Changelog generated!"
@echo " Review CHANGELOG.md"
.PHONY: release-upgrade-guide
release-upgrade-guide: ## Generate only the upgrade guide (usage: make release-upgrade-guide VERSION=1.5.4)
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION not specified"; \
echo "Usage: make release-upgrade-guide VERSION=1.5.4"; \
exit 1; \
fi
$(eval PREV_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v1.5.3"))
@echo "Generating upgrade guide for v$(VERSION) (changes since $(PREV_VERSION))..."
@if command -v python3 &> /dev/null && python3 -c "import github" 2>&1 >/dev/null; then \
python3 scripts/generate-upgrade-guide.py $(VERSION) $(PREV_VERSION); \
else \
bash scripts/generate-upgrade-guide.sh $(VERSION) $(PREV_VERSION); \
echo " Tip: Install PyGithub for enhanced content extraction"; \
fi
@echo ""
@echo "SUCCESS: Upgrade guide generated!"
@echo " Review templates/guides/$(VERSION)-upgrade-guide.md"
@echo " Run 'make build-docs' to publish to docs/"
.PHONY: release-prep
release-prep: ## Prepare all release artifacts (usage: make release-prep VERSION=1.5.4)
@echo "==> Preparing release..."
@if [ -z "$(VERSION)" ]; then \
echo "ERROR: VERSION not specified"; \
echo "Usage: make release-prep VERSION=1.5.4"; \
echo ""; \
echo "Or use individual commands:"; \
echo " make release-changelog VERSION=1.5.4"; \
echo " make release-upgrade-guide VERSION=1.5.4"; \
exit 1; \
fi
@echo "Detecting previous version..."
$(eval PREV_VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v1.5.3"))
@echo "Previous version: $(PREV_VERSION)"
@echo "New version: v$(VERSION)"
@echo ""
@echo "[1/4] Generating changelog..."
@bash scripts/generate-changelog.sh v$(VERSION) $(PREV_VERSION)
@echo ""
@echo "[2/4] Validating PR quality..."
@if command -v python3 &> /dev/null && python3 -c "import github" 2>&1 >/dev/null; then \
python3 scripts/validate-prs.py v$(VERSION) $(PREV_VERSION) || echo " WARNING: Validation warnings found (continuing anyway)"; \
else \
echo " Skipped (install PyGithub for enhanced validation)"; \
fi
@echo ""
@echo "[3/4] Generating upgrade guide..."
@if command -v python3 &> /dev/null && python3 -c "import github" 2>&1 >/dev/null; then \
python3 scripts/generate-upgrade-guide.py $(VERSION) $(PREV_VERSION); \
else \
bash scripts/generate-upgrade-guide.sh $(VERSION) $(PREV_VERSION); \
echo " Tip: Install PyGithub for enhanced content extraction"; \
fi
@echo ""
@echo "[4/4] Building documentation..."
@$(MAKE) build-docs
@echo ""
@echo "SUCCESS: Release preparation complete!"
@echo ""
@echo "Next steps:"
@echo " 1. Review templates/guides/$(VERSION)-upgrade-guide.md"
@echo " 2. Review CHANGELOG.md"
@echo " 3. Commit: git add . && git commit -m 'Prepare release v$(VERSION)'"
@echo " 4. Tag: git tag v$(VERSION) && git push origin v$(VERSION)"
@echo " 5. GitHub Actions will create the release automatically"
@echo ""
@echo "For full checklist: make release-checklist"
.PHONY: release-checklist
release-checklist: ## Show complete release checklist
@echo "Terraform Provider Release Checklist"
@echo ""
@echo "Pre-Release:"
@echo " [ ] All PRs merged and labeled correctly"
@echo " [ ] make test - Unit tests pass"
@echo " [ ] make testacc - Acceptance tests pass"
@echo " [ ] make check - Code quality checks pass"
@echo ""
@echo "Generate Artifacts:"
@echo " [ ] make release-prep VERSION=X.Y.Z"
@echo " [ ] Review/edit templates/guides/X.Y.Z-upgrade-guide.md"
@echo " [ ] Review CHANGELOG.md"
@echo " [ ] Test examples from upgrade guide"
@echo ""
@echo "Release:"
@echo " [ ] Commit all changes"
@echo " [ ] git tag vX.Y.Z && git push origin vX.Y.Z"
@echo " [ ] Verify GitHub Actions workflow succeeds"
@echo " [ ] Verify release on GitHub releases page"
@echo " [ ] Verify published to Terraform Registry"
@echo ""
@echo "Post-Release:"
@echo " [ ] Announce in team channels"
@echo " [ ] Update related documentation"
@echo ""
@echo "For details: See RELEASE_PROCESS.md"