forked from gitlabhq/terraform-provider-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
113 lines (82 loc) · 4.17 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
default: reviewable
reviewable: build fmt generate test ## Run before committing.
GOBIN = $(shell pwd)/bin
PROVIDER_SRC_DIR := ./internal/provider
build: ## Build the provider binary.
go mod tidy
GOBIN=$(GOBIN) go install
generate: tool-tfplugindocs ## Generate files to be checked in.
@# Setting empty environment variables to work around issue: https://github.com/hashicorp/terraform-plugin-docs/issues/12
@# Setting the PATH so that tfplugindocs uses the same terraform binary as other targets here, and to resolve a "Error: Incompatible provider version" error on M1 macs.
GITLAB_TOKEN="" PATH="$(GOBIN):$(PATH)" $(GOBIN)/tfplugindocs generate
ifdef RUN
TESTARGS += -test.run $(RUN)
endif
test: ## Run unit tests.
go test $(TESTARGS) $(PROVIDER_SRC_DIR)
TFPROVIDERLINTX_CHECKS = -XAT001=false -XR003=false -XS002=false
fmt: tool-golangci-lint tool-tfproviderlintx tool-terraform tool-shfmt ## Format files and fix issues.
gofmt -w -s .
$(GOBIN)/golangci-lint run --fix
$(GOBIN)/tfproviderlintx $(TFPROVIDERLINTX_CHECKS) --fix ./...
$(GOBIN)/terraform fmt -recursive -list ./examples
$(GOBIN)/shfmt -l -s -w ./examples
lint-golangci: tool-golangci-lint ## Run golangci-lint linter (same as fmt but without modifying files).
$(GOBIN)/golangci-lint run
lint-tfprovider: tool-tfproviderlintx ## Run tfproviderlintx linter (same as fmt but without modifying files).
$(GOBIN)/tfproviderlintx $(TFPROVIDERLINTX_CHECKS) ./...
lint-examples-tf: tool-terraform ## Run terraform linter on examples (same as fmt but without modifying files).
$(GOBIN)/terraform fmt -recursive -check ./examples
lint-examples-sh: tool-shfmt ## Run shell linter on examples (same as fmt but without modifying files).
$(GOBIN)/shfmt -l -s -d ./examples
lint-generated: generate ## Check that "make generate" was called. Note this only works if the git workspace is clean.
@echo "Checking git status"
@[ -z "$(shell git status --short)" ] || { \
echo "Error: Files should have been generated:"; \
git status --short; echo "Diff:"; \
git --no-pager diff HEAD; \
echo "Run \"make generate\" and try again"; \
exit 1; \
}
lint-custom: ## Run custom checks and validations that do not fit into an existing lint framework.
@./scripts/lint-custom.sh
apicovered: tool-apicovered ## Run an analysis tool to estimate the GitLab API coverage.
@$(GOBIN)/apicovered ./gitlab
apiunused: tool-apiunused ## Run an analysis tool to output unused parts of the go-gitlab package.
@$(GOBIN)/apiunused ./gitlab
SERVICE ?= gitlab-ce
GITLAB_TOKEN ?= ACCTEST1234567890123
GITLAB_BASE_URL ?= http://127.0.0.1:8080/api/v4
testacc-up: | certs ## Launch a GitLab instance.
docker-compose up -d $(SERVICE)
./scripts/await-healthy.sh
testacc-down: ## Teardown a GitLab instance.
docker-compose down --volumes
testacc: ## Run acceptance tests against a GitLab instance.
TF_ACC=1 GITLAB_TOKEN=$(GITLAB_TOKEN) GITLAB_BASE_URL=$(GITLAB_BASE_URL) go test -v $(PROVIDER_SRC_DIR) $(TESTARGS) -timeout 40m
certs: ## Generate certs for the GitLab container registry
mkdir -p certs
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout certs/gitlab-registry.key -out certs/gitlab-registry.crt -subj "/CN=gitlab-registry.com" -addext "subjectAltName=DNS:IP:127.0.0.1"
# TOOLS
# Tool dependencies are installed into a project-local /bin folder.
tool-golangci-lint:
@$(call install-tool, github.com/golangci/golangci-lint/cmd/golangci-lint)
tool-tfproviderlintx:
@$(call install-tool, github.com/bflad/tfproviderlint/cmd/tfproviderlintx)
tool-tfplugindocs:
@$(call install-tool, github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs)
tool-shfmt:
@$(call install-tool, mvdan.cc/sh/v3/cmd/shfmt)
tool-apicovered:
@$(call install-tool, ./cmd/apicovered)
tool-apiunused:
@$(call install-tool, ./cmd/apiunused)
define install-tool
cd tools && GOBIN=$(GOBIN) go install $(1)
endef
TERRAFORM_VERSION = v1.1.4
tool-terraform:
@# See https://github.com/hashicorp/terraform/issues/30356
@[ -f $(GOBIN)/terraform ] || { mkdir -p tmp; cd tmp; rm -rf terraform; git clone --branch $(TERRAFORM_VERSION) --depth 1 https://github.com/hashicorp/terraform.git; cd terraform; GOBIN=$(GOBIN) go install; cd ..; rm -rf terraform; }
clean: testacc-down
@rm -rf certs/