Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
175 lines (148 loc) · 5.77 KB
/
Copy pathMakefile
File metadata and controls
175 lines (148 loc) · 5.77 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
BUILD_DIR := build
BIN_DIR := $(CURDIR)/$(BUILD_DIR)/bin
LINT_CONFIG := $(CURDIR)/.golangci.yml
# All Go modules of the workspace: every go.mod but the tool modules under
# tools/, which are not part of go.work.
# Note: the leading "./" is required for find -execdir / cd targets.
MODULES := $(shell find . -name go.mod -not -path '*/vendor/*' -not -path '*/node_modules/*' -not -path '*/build/*' -not -path './tools/*' | sort | sed 's|/go.mod||')
# Development tools: one module per tool under tools/<name>, outside the
# workspace so that their dependencies never reach a library go.mod, each
# pinned and checksum-verified by its own go.mod and go.sum.
TOOLS := golangci-lint govulncheck goveralls mockery
.PHONY: all
all: test
.PHONY: clean
clean: clean-mocks
@rm -rf $(BUILD_DIR)
@for mod in $(MODULES); do (cd "$$mod" && go clean -i ./...); done
_build:
@mkdir -p $(BUILD_DIR)
.PHONY: tools
tools: $(addprefix $(BIN_DIR)/,$(TOOLS))
$(BIN_DIR)/%: tools/%/go.mod tools/%/go.sum
@echo "==> install $*"
@GOWORK=off GOBIN=$(BIN_DIR) go install -C tools/$* tool
@touch $@
.PHONY: sync
sync:
@echo "Syncing workspace..."
@go work sync
.PHONY: build
build:
@for mod in $(MODULES); do \
echo "==> build $$mod"; \
(cd "$$mod" && go build -v ./...) || exit 1; \
done
# Mocks (.mockery.yaml): in-package mock_<interface>_test.go files, so they
# only exist in test binaries; never committed. The targets that compile
# tests generate them first; stale generated files are removed beforehand.
.PHONY: generate
generate: $(BIN_DIR)/mockery clean-mocks
@echo "Generating mocks..."
@$(BIN_DIR)/mockery --log-level=warn
.PHONY: clean-mocks
clean-mocks:
@find . -name 'mock_*_test.go' -not -path './build/*' -type f \
-exec grep -q '^// Code generated by mockery' {} \; -delete
.PHONY: test
test: _build generate
@: > $(BUILD_DIR)/coverage.out
@for mod in $(MODULES); do \
echo "==> test $$mod"; \
mod_safe=$$(echo "$$mod" | sed 's|/|_|g; s|^\._||; s|^\.$$|root|'); \
(cd "$$mod" && go test -cover -race \
-coverprofile="$(CURDIR)/$(BUILD_DIR)/$$mod_safe.cover" \
-timeout 300s ./...) || exit 1; \
done
@# Aggregate coverage excludes generated mocks, protobuf, and the
@# example programs: their main() binds a socket and blocks, so it is
@# not unit-testable and would skew the library coverage figure. The
@# examples are still built, tested, and linted above.
@grep -h -v '^mode:' $(BUILD_DIR)/*.cover 2>/dev/null \
| grep -v 'mock_' | grep -v '.pb.go' | grep -v '/example' \
> $(BUILD_DIR)/coverage.body || true
@echo 'mode: atomic' > $(BUILD_DIR)/coverage.out
@cat $(BUILD_DIR)/coverage.body >> $(BUILD_DIR)/coverage.out
@rm -f $(BUILD_DIR)/*.cover $(BUILD_DIR)/coverage.body
# The store suites on real PostgreSQL, MySQL, MariaDB and Redis servers,
# which `make test` runs on SQLite and miniredis only. The header of
# scripts/test-backends.sh lists the variables naming the servers and
# starts them locally; CI runs it in the "Store suites (real backends)"
# job, against service containers.
.PHONY: test-backends
test-backends: generate
@./scripts/test-backends.sh
# Sends build/coverage.out to Coveralls with goveralls (tools/goveralls). CI
# passes the workflow token as COVERALLS_TOKEN (goveralls' GitHub Actions
# setup).
.PHONY: coveralls
coveralls: $(BIN_DIR)/goveralls
@$(BIN_DIR)/goveralls -coverprofile=$(BUILD_DIR)/coverage.out -service=github
.PHONY: coverage
coverage: $(BUILD_DIR)/coverage.out
@go tool cover -func ./$(BUILD_DIR)/coverage.out
.PHONY: coverage-html
coverage-html: $(BUILD_DIR)/coverage.out
@go tool cover -html ./$(BUILD_DIR)/coverage.out
.PHONY: bench
bench: generate
@for mod in $(MODULES); do \
echo "==> bench $$mod"; \
(cd "$$mod" && go test -bench=. -benchmem -benchtime=5s -timeout 300s ./...) || exit 1; \
done
.PHONY: lint
lint: generate $(BIN_DIR)/golangci-lint
@go list -f '{{.Dir}}/...' -m | xargs $(BIN_DIR)/golangci-lint run --timeout=300s --config="$(LINT_CONFIG)"
# govulncheck on every module, outside the workspace (each module's own
# requirements: what a consumer resolves), tests included.
.PHONY: vuln
vuln: generate $(BIN_DIR)/govulncheck
@for mod in $(MODULES); do \
echo "==> govulncheck $$mod"; \
(cd "$$mod" && GOWORK=off $(BIN_DIR)/govulncheck -test ./...) || exit 1; \
done
# Every module on its own (scripts/check-modules.sh): one go line, go.work
# lists every module, `go work sync` is a no-op, and every module builds,
# vets and is tidy with GOWORK=off, with and without the generated mocks.
# CI runs it on every change.
.PHONY: check-modules
check-modules: $(BIN_DIR)/mockery
@./scripts/check-modules.sh
# Checks a release tag before it is pushed (docs/releasing.md):
# make release-check TAG=oauth2/v1.0.0
.PHONY: release-check
release-check: generate
@./scripts/release-check.sh "$(TAG)"
# Opt-in browser suites (Tales and Chrome, prerequisites in docs/saml-sp.md
# and e2e/oidc/run.sh): never part of `make test` nor of CI.
.PHONY: e2e
e2e: e2e-saml e2e-oidc
.PHONY: e2e-saml
e2e-saml:
@./e2e/saml/run.sh
.PHONY: e2e-oidc
e2e-oidc:
@./e2e/oidc/run.sh
# The OpenID Foundation conformance suite against oidc/provider (OP plans) and
# oidc/client (RP plans), locally: opt-in, never in CI, not a certification
# (prerequisites in internal/interop/oidcstack/conformance/run.sh).
.PHONY: conformance
conformance:
@./internal/interop/oidcstack/conformance/run.sh
# A sign-in with a real provider account (LIVE_OIDC_* variables, a person
# at the keyboard): see e2e/oidc-live/run.sh.
.PHONY: e2e-oidc-live
e2e-oidc-live:
@./e2e/oidc-live/run.sh
.PHONY: tidy
tidy: generate
@go work sync
@for mod in $(MODULES); do \
echo "==> tidy $$mod"; \
(cd "$$mod" && GOWORK=off go mod tidy) || exit 1; \
done
@for tool in $(TOOLS); do \
echo "==> tidy tools/$$tool"; \
(cd "tools/$$tool" && GOWORK=off go mod tidy) || exit 1; \
done
@go work sync