-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
127 lines (108 loc) · 4.23 KB
/
Copy pathMakefile
File metadata and controls
127 lines (108 loc) · 4.23 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
SHELL := /bin/sh
.ONESHELL:
.SHELLFLAGS := -eu -c
GO ?= go
GO_MODULE ?= env GOWORK=off $(GO)
GOFMT ?= gofmt
PKGS ?= ./...
EXAMPLE_PKGS ?= $(shell $(GO_MODULE) list ./examples/...)
COVER_PKGS ?= $(shell $(GO_MODULE) list $(PKGS) | grep -v '/examples/')
GOFILES := $(filter-out $(shell git ls-files --deleted -- '*.go'),$(shell git ls-files -- '*.go'))
GOVULNCHECK_VERSION ?= v1.7.0
COMPOSITION_EXAMPLE_DIR := examples/kit-series-composition
RELEASE_CHECK_DIR := tools/releasecheck
# Keep build cache inside the repo so local runs are reproducible and do not
# depend on a writable global cache path.
export GOCACHE ?= $(CURDIR)/.cache/go-build
.DEFAULT_GOAL := help
.PHONY: \
help \
fmt \
fmt-check \
vet \
test \
test-race \
build-examples \
coverage \
root-deps-check \
tidy \
tidy-check \
govulncheck \
verify \
clean
help: ## Show available targets.
@printf "Available targets:\n"
awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z0-9_.-]+:.*##/ {printf " %-16s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
fmt: ## Format tracked Go source files.
@echo "==> formatting"
$(GOFMT) -w $(GOFILES)
fmt-check: ## Verify tracked Go source files are formatted.
@echo "==> checking formatting"
out="$$( $(GOFMT) -l $(GOFILES) )"
if [ -n "$$out" ]; then
echo "The following files are not formatted:"
echo "$$out"
exit 1
fi
vet: ## Run go vet on all packages.
@echo "==> vet"
$(GO_MODULE) vet $(PKGS)
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) vet ./...
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) vet ./...
test: ## Run tests for all packages.
@echo "==> test"
$(GO_MODULE) test $(PKGS)
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) test ./...
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) test ./...
test-race: ## Run tests with the race detector enabled.
@echo "==> test race"
$(GO_MODULE) test -race $(PKGS)
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) test -race ./...
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) test -race ./...
build-examples: ## Build all runnable examples without writing binaries.
@echo "==> building examples"
$(GO_MODULE) test -run '^$$' $(EXAMPLE_PKGS)
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) test -run '^$$' ./...
coverage: ## Run library package tests with coverage output written to coverage.out.
@echo "==> coverage"
$(GO_MODULE) test -coverprofile=coverage.out $(COVER_PKGS)
$(GO_MODULE) tool cover -func=coverage.out | tail -1
root-deps-check: ## Verify the root package and published module dependency boundaries.
@echo "==> checking root dependency boundary"
raw_deps="$$( $(GO_MODULE) list -deps -f '{{if not .Standard}}{{.ImportPath}}{{end}}' . )"
deps="$$( printf '%s\n' "$$raw_deps" | sed '/^$$/d' | sort )"
expected="$$( printf '%s\n' \
'github.com/jaredjakacky/clientkit' \
'github.com/jaredjakacky/opskit' )"
if [ "$$deps" != "$$expected" ]; then
echo "Unexpected non-standard-library packages in the root build:"
printf '%s\n' "$$deps"
exit 1
fi
modules="$$( $(GO_MODULE) list -m -f '{{.Path}}' all )"
forbidden="$$( printf '%s\n' "$$modules" | grep -E '^github\.com/jaredjakacky/(configkit|dependkit|servekit|workerkit)(/|$$)' || true )"
if [ -n "$$forbidden" ]; then
echo "Clientkit's published root module graph must not include sibling domain kits:"
printf '%s\n' "$$forbidden"
exit 1
fi
tidy: ## Synchronize module files for all verified modules.
@echo "==> tidy"
$(GO_MODULE) mod tidy
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) mod tidy
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) mod tidy
tidy-check: ## Verify go.mod/go.sum are already tidy.
@echo "==> checking tidy"
$(GO_MODULE) mod tidy -diff
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) mod tidy -diff
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) mod tidy -diff
govulncheck: ## Run the pinned govulncheck tool against all verified modules.
@echo "==> govulncheck"
$(GO_MODULE) run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) $(PKGS)
$(GO_MODULE) -C $(COMPOSITION_EXAMPLE_DIR) run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) ./...
$(GO_MODULE) -C $(RELEASE_CHECK_DIR) run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) ./...
verify: fmt-check root-deps-check vet test build-examples tidy-check ## Run the local verification suite.
@echo "==> verification passed"
clean: ## Remove local build outputs and caches.
@echo "==> clean"
rm -rf .cache coverage.out