-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (72 loc) · 3.56 KB
/
Copy pathMakefile
File metadata and controls
92 lines (72 loc) · 3.56 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
# agentbox developer tasks.
#
# Every target no-ops cleanly when its language's sources are absent, so
# `make check` is green on an empty tree and lights up one language at a time
# as the repo fills in. A missing *tool* also skips — except under STRICT=1
# (what CI runs), where it is a hard failure so the pipeline can never go
# green by silently not linting or testing.
.DEFAULT_GOAL := check
SHELL := bash
SH_FILES := $(shell find ansible packer -type f \( -name '*.sh' -o -path '*/bin/*' \) 2>/dev/null)
# $(call missing_tool,<name>) — skip locally, fail under STRICT=1.
ifdef STRICT
missing_tool = { echo "missing tool: $(1)" >&2; exit 1; }
else
missing_tool = echo "skip ($(1) not installed)"
endif
.PHONY: check fmt lint test \
go-lint go-test sh-lint sh-test iac-lint \
go-fmt sh-fmt iac-fmt
## check: lint + test everything present (default)
check: lint test
## fmt: auto-format every language present
fmt: go-fmt sh-fmt iac-fmt
## lint: lint every language present
lint: go-lint sh-lint iac-lint
## test: run tests
test: go-test sh-test
# ---- Go ----
go-fmt:
@if [ ! -f go.mod ]; then echo "skip go-fmt (no go.mod)"; \
elif command -v gofumpt >/dev/null 2>&1; then gofumpt -w .; \
else $(call missing_tool,gofumpt); fi
go-lint:
@if [ -f go.mod ]; then golangci-lint run ./... && golangci-lint fmt --diff; else echo "skip go-lint (no go.mod)"; fi
go-test:
@if [ -f go.mod ]; then go test -race ./...; else echo "skip go-test (no go.mod)"; fi
# ---- Bash ----
sh-fmt:
@if [ -z "$(SH_FILES)" ]; then echo "skip sh-fmt (no scripts)"; \
elif command -v shfmt >/dev/null 2>&1; then shfmt -w -i 4 -ci $(SH_FILES); \
else $(call missing_tool,shfmt); fi
sh-lint:
@if [ -n "$(SH_FILES)" ]; then shellcheck $(SH_FILES) && shfmt -d -i 4 -ci $(SH_FILES); else echo "skip sh-lint (no scripts)"; fi
# ---- bats ----
sh-test:
@if [ ! -d packer/tests ]; then echo "skip bats (no tests)"; \
elif command -v bats >/dev/null 2>&1; then bats packer/tests; \
else $(call missing_tool,bats); fi
# ---- Infrastructure as code ----
iac-fmt:
@if [ ! -d terraform ]; then echo "skip terraform fmt (no terraform/)"; \
elif command -v terraform >/dev/null 2>&1; then terraform -chdir=terraform fmt -recursive; \
else $(call missing_tool,terraform); fi
@if [ ! -d packer ]; then echo "skip packer fmt (no packer/)"; \
elif command -v packer >/dev/null 2>&1; then packer fmt packer; \
else $(call missing_tool,packer); fi
iac-lint:
@if [ ! -d terraform ]; then echo "skip terraform fmt-check (no terraform/)"; \
elif command -v terraform >/dev/null 2>&1; then terraform -chdir=terraform fmt -check -recursive; \
else $(call missing_tool,terraform); fi
@if [ ! -d terraform ]; then echo "skip terraform validate (no terraform/)"; \
elif command -v terraform >/dev/null 2>&1; then terraform -chdir=terraform init -backend=false -input=false >/dev/null && terraform -chdir=terraform validate; \
else $(call missing_tool,terraform); fi
@if [ ! -d terraform ]; then echo "skip tflint (no terraform/)"; \
elif command -v tflint >/dev/null 2>&1; then tflint --chdir=terraform; \
else $(call missing_tool,tflint); fi
@if [ ! -d ansible ]; then echo "skip ansible-lint (no ansible/)"; \
elif command -v ansible-lint >/dev/null 2>&1; then ANSIBLE_ROLES_PATH=ansible/roles ansible-lint ansible; \
else $(call missing_tool,ansible-lint); fi
@if [ ! -d packer ]; then echo "skip packer validate (no packer/)"; \
elif command -v packer >/dev/null 2>&1; then packer init packer && HCLOUD_TOKEN=$${HCLOUD_TOKEN:-dummy} packer validate -var 'source_hash=validate' packer; \
else $(call missing_tool,packer); fi