Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (76 loc) · 3.51 KB
/
Copy pathMakefile
File metadata and controls
91 lines (76 loc) · 3.51 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
# `make check` is what CI runs on every pull request: the CI_go steps (each one
# is a target here, and CI_go calls these same targets), the internal-names
# check of CI_leak_guard over every tracked file, and CI_contract's fixture
# comparison when you point it at a patch-it checkout. Run it before you open a PR.
#
# make check everything below, in CI's order
# make check PATCH_IT=../patch-it also compare contract/fixtures/ with patch-it's
# make plugins-json regenerate docs/plugins.json from the registry and docs/plugins.md
#
# The `::error` lines are GitHub annotations; locally they're plain messages.
GO ?= go
PYTHON ?= python3
# Packages allowed outside the standard library: this module and the approved
# dependencies. Adding a dependency means adding it here, in review.
MODULE := github.com/patch-it-dev/patch-it-plugins
ALLOWED := ^($(MODULE)(/|$$)|gopkg\.in/yaml\.v3$$)
.PHONY: check tidy build fmt vet imports nethttp test todos leak-guard contract plugins-json
check: tidy build fmt vet imports nethttp test todos leak-guard contract
@echo "make check: all passed"
# go.mod and go.sum are tidy.
tidy:
$(GO) mod tidy
@git diff --exit-code -- go.mod go.sum || { echo "::error file=go.mod::go.mod/go.sum are not tidy. Run 'go mod tidy' and commit the result."; exit 1; }
build:
$(GO) build ./...
fmt:
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
for f in $$unformatted; do echo "::error file=$$f::not gofmt-formatted. Run 'gofmt -w $$f'."; done; \
exit 1; \
fi
vet:
$(GO) vet ./...
# An allowlist, so a plugin can't pull in a database driver, a cloud SDK or
# anything private.
imports:
@others=$$($(GO) list -deps -test -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... | sed 's/ \[.*//' | sort -u | grep -vE '$(ALLOWED)' || true); \
if [ -n "$$others" ]; then \
echo "::error::imports outside the allowlist (Makefile, ALLOWED):"; echo "$$others"; exit 1; \
fi
# Plugins fetch through env.Get / kit, never on their own.
nethttp:
@bad=$$($(GO) list -f '{{.ImportPath}} {{join .Imports " "}}' ./... \
| grep -E '(^| )net/http( |$$)' | cut -d' ' -f1 \
| grep -vE '^$(MODULE)/(fetch|kit|adapter)(/|$$)' || true); \
if [ -n "$$bad" ]; then \
echo "::error::these packages import net/http; fetch through env.Get or kit instead:"; echo "$$bad"; exit 1; \
fi
# -race: the fetcher and the tests' HTTP servers run on other goroutines.
# Includes the check that docs/plugins.json is up to date (internal/pluginlist).
test:
$(GO) test -race -count=1 ./...
# A provider started with new-plugin is done when nothing it wrote still says
# TODO(new-plugin).
TODO_DIRS := plugins adapter retire sdkguide migrate providers docs/plugins.md
todos:
@left=$$(grep -rl 'TODO(new-plugin)' $(TODO_DIRS) || true); \
if [ -n "$$left" ]; then \
for f in $$left; do echo "::error file=$$f::TODO(new-plugin) left: fill it in (grep -n 'TODO(new-plugin)' $$f)."; done; \
exit 1; \
fi
# CI_leak_guard checks only what a PR adds (plus gitleaks); this checks every
# tracked file.
leak-guard:
$(PYTHON) scripts/leak_guard.py --all
# CI_contract: contract/fixtures/ hold the same events as patch-it's fixtures/.
# Needs a patch-it checkout; skipped without one, as CI_contract skips while
# patch-it can't be read anonymously.
contract:
@if [ -n "$(PATCH_IT)" ]; then \
$(PYTHON) scripts/check_contract.py "$(PATCH_IT)/fixtures"; \
else \
echo "contract: skipped (make check PATCH_IT=<a patch-it checkout> compares contract/fixtures/)"; \
fi
plugins-json:
$(GO) run ./cmd/list-plugins