forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNUmakefile
More file actions
114 lines (88 loc) · 3.85 KB
/
GNUmakefile
File metadata and controls
114 lines (88 loc) · 3.85 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
SWEEP?=repositories,teams
PKG_NAME=github
TEST?=./$(PKG_NAME)/...
COVERAGEARGS?=-race -coverprofile=coverage.txt -covermode=atomic
RUMDL_ARGS?=--output-format text
# 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
tools:
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
build: lintcheck
CGO_ENABLED=0 go build -ldflags="-s -w" ./...
fmt:
@echo "==> Fixing source code formatting..."
golangci-lint fmt ./...
# Merges the rules in .golangci.yml and .golangci.strict.yml into a new file .golangci.new.yml, which is used for checking only new code.
# This allows us to start enforcing new linting rules on new code without having to fix all existing issues in the codebase at once.
# Only executes if either of the source files has changed, to avoid unnecessary work.
.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
lint:
@echo "==> Checking source code against linters and fixing..."
golangci-lint run --fix ./...
lintcheck:
@echo "==> Checking source code against linters..."
golangci-lint run ./...
# Checks all code against the strict rules. This is expected to fail until all issues have been fixed, but it allows us to track progress on fixing the issues and ensures that no new issues are introduced.
lintcheck-strict: .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 🌿"
golangci-lint run ./... --config .golangci.new.yml
lintcheck-new: .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 🌿"
golangci-lint run ./... --new-from-merge-base main --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;
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)
generatedocs:
@cd tools; go generate ./...
validatedocs:
@cd tools; go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs validate --provider-dir ..
fmtdocs:
@rumdl fmt ./docs
lintdocs: validatedocs
@rumdl check $(RUMDL_ARGS) ./docs
checkdocs: generatedocs
@git diff --quiet ||\
{ echo "New file modification detected in the Git working tree. Please check in before commit."; git --no-pager diff --name-only | uniq | awk '{print " - " $$0}'; \
if [ "${CI}" = true ]; then\
exit 1;\
fi;}
yamlfmt:
@yamlfmt -continue_on_error .
mdfmt:
@rumdl fmt .
mdlint:
@rumdl check $(RUMDL_ARGS) .
.PHONY: build test testacc fmt lint lintcheck lintcheck-strict lintcheck-new tools sweep generatedocs validatedocs fmtdocs lintdocs checkdocs yamlfmt mdfmt mdlint