-
Notifications
You must be signed in to change notification settings - Fork 961
Expand file tree
/
Copy pathGNUmakefile
More file actions
113 lines (90 loc) · 4.07 KB
/
GNUmakefile
File metadata and controls
113 lines (90 loc) · 4.07 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
SWEEP?=repositories,teams
PKG_NAME=github
TEST?=./$(PKG_NAME)/...
WEBSITE_REPO=github.com/hashicorp/terraform-website
COVERAGEARGS?=-race -coverprofile=coverage.txt -covermode=atomic
BIN="$$(pwd -P)"/bin
# VARIABLE REFERENCE:
#
# Test-specific variables:
# T=<pattern> - Test name pattern (e.g., TestAccGithubRepository)
# COV=true - Enable coverage
#
#
# Examples:
# make test T=TestMigrate # Run only schema migration unit tests
# make test COV=true # Run all unit tests with coverage
# make testacc T=TestAccGithubRepositories\$$ COV=true # Run only acceptance tests for a specific Test name with coverage
ifneq ($(origin T), undefined)
RUNARGS = -run='$(T)'
endif
ifneq ($(origin COV), undefined)
RUNARGS += $(COVERAGEARGS)
endif
default: build
bin/golangci-lint:
@echo "==> Installing golangci-lint..."
mkdir -p $(BIN)
GOBIN=$(BIN) go install github.com/golangci/golangci-lint/v2/cmd/[email protected]
tools_go_files = $(shell find tools \( -name '*.go' -or -name '*.mod' -or -name '*.sum' \) -and -not -name '*_test.go' -maxdepth 4)
bin/custom-gcl: bin/golangci-lint $(tools_go_files)
@echo "==> Building custom-gcl..."
@$(BIN)/golangci-lint custom --name custom-gcl --destination $(BIN)
tools: bin/custom-gcl go.sum
go.sum: go.mod $(shell find github -name '*.go')
@go mod tidy
build: lintcheck
CGO_ENABLED=0 go build -ldflags="-s -w" ./...
fmt: tools
@echo "==> Fixing source code formatting..."
$(BIN)/custom-gcl fmt ./... ./tools/...
lint: tools
@echo "==> Checking source code against linters and fixing..."
$(BIN)/custom-gcl run --fix ./...
lintcheck: tools
@branch=$$(git rev-parse --abbrev-ref HEAD); \
printf "==> Checking source code against linters on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
$(BIN)/custom-gcl run ./...
.golangci.new.yml: .golangci.yml .golangci.strict.yml
@yq eval-all 'select(fileIndex == 0) *+ select(fileIndex == 1)' .golangci.yml .golangci.strict.yml > .golangci.new.yml
lintcheck-new: tools .golangci.new.yml
@branch=$$(git rev-parse --abbrev-ref HEAD); \
printf "==> Checking changed source code against linters on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
$(BIN)/custom-gcl run ./... --new-from-merge-base main --config .golangci.new.yml
lintcheck-strict: tools .golangci.new.yml
@branch=$$(git rev-parse --abbrev-ref HEAD); \
printf "==> Checking source code against strict linters on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
$(BIN)/custom-gcl run ./... --config .golangci.new.yml
test:
@branch=$$(git rev-parse --abbrev-ref HEAD); \
printf "==> Running unit tests on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
CGO_ENABLED=0 go test $(TEST) \
-timeout=30s \
-parallel=4 \
-v \
-skip '^TestAcc' \
$(RUNARGS) $(TESTARGS) \
-count 1;
test-tools:
@echo "==> Running tools tests..."
$(MAKE) test -C tools/tfproviderlint
testacc:
@branch=$$(git rev-parse --abbrev-ref HEAD); \
printf "==> Running acceptance tests on branch: \033[1m%s\033[0m...\n" "🌿 $$branch 🌿"
TF_ACC=1 CGO_ENABLED=0 go test $(TEST) -v -run '^TestAcc' $(RUNARGS) $(TESTARGS) -timeout 120m -count=1
sweep:
@echo "WARNING: This will destroy infrastructure. Use only in development accounts."
go test $(TEST) -v -sweep=$(SWEEP) $(SWEEPARGS)
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)
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: build test testacc fmt lint lintcheck lintcheck-new lintcheck-strict tools test-tools website website-test sweep