-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
79 lines (60 loc) · 2.41 KB
/
Makefile
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
MODULE_NAME=testcontainers-registry
VENDOR_DIR = vendor
GOLANGCI_LINT_VERSION ?= v1.60.1
GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
goModules := $(shell find . -name 'go.mod' | xargs dirname | tail -n +2)
lintGoModules := $(subst -.,-module,$(subst /,-,$(addprefix lint-,$(goModules))))
updateGoModules := $(subst -.,-module,$(subst /,-,$(addprefix update-,$(goModules))))
tidyGoModules := $(subst -.,-module,$(subst /,-,$(addprefix tidy-,$(goModules))))
testGoModules := $(subst -.,-integration,$(subst /,-,$(addprefix test-,$(goModules))))
.PHONY: $(VENDOR_DIR)
$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
@$(GO) mod vendor
@$(GO) mod tidy
.PHONY: lint
lint: $(GOLANGCI_LINT) $(VENDOR_DIR) $(lintGoModules)
@$(GOLANGCI_LINT) run -c .golangci.yaml
.PHONY: $(lintGoModules)
$(lintGoModules): $(GOLANGCI_LINT)
$(eval GO_MODULE := "$(subst lint/module,.,$(subst -,/,$(subst lint-module-,,$@)))")
@echo ">> module: $(GO_MODULE)"
@cd "$(GO_MODULE)"; $(GOLANGCI_LINT) run
.PHONY: $(updateGoModules)
$(updateGoModules):
$(eval GO_MODULE := "$(subst update/module,.,$(subst -,/,$(subst update-module-,,$@)))")
@echo ">> module: $(GO_MODULE)"
@cd "$(GO_MODULE)"; $(GO) get -u ./...
.PHONY: update
update: $(updateGoModules)
.PHONY: tidy
tidy: $(tidyGoModules)
@echo ">> tidy"
@$(GO) mod tidy
.PHONY: $(tidyGoModules)
$(tidyGoModules):
$(eval GO_MODULE := "$(subst tidy/module,.,$(subst -,/,$(subst tidy-module-,,$@)))")
@echo ">> tidy module: $(GO_MODULE)"
@cd "$(GO_MODULE)"; $(GO) mod tidy
.PHONY: test
test: test-integration $(testGoModules)
## Run integration tests
.PHONY: test-integration
test-integration:
@echo ">> unit test"
@$(GO) test -v -gcflags=-l -coverprofile=features.coverprofile -covermode=atomic -race ./...
.PHONY: $(testGoModules)
$(testGoModules):
$(eval GO_MODULE := "$(subst test-integration-,,$@)")
@echo ">> integration test: $(GO_MODULE)"
@cd "$(GO_MODULE)"; $(GO) test -gcflags=-l -coverprofile=features.coverprofile -v ./...
@echo
.PHONY: $(GITHUB_OUTPUT)
$(GITHUB_OUTPUT):
@echo "MODULE_NAME=$(MODULE_NAME)" >> "$@"
@echo "GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION)" >> "$@"
$(GOLANGCI_LINT):
@echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin "$(GOLANGCI_LINT_VERSION)"
@mv ./bin/golangci-lint $(GOLANGCI_LINT)