-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (139 loc) · 5.17 KB
/
Makefile
File metadata and controls
174 lines (139 loc) · 5.17 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
# Common targets
.PHONY: all check format format-whitespace check-whitespace check-format test lint fix
# Cross-platform sed in-place edit
SED_INPLACE := $(shell if [ "$$(uname)" = "Darwin" ]; then echo "sed -i ''"; else echo "sed -i"; fi)
# Phased targets for make -j safe parallel execution.
# Each $(MAKE) line runs its targets in parallel; lines run sequentially.
all:
$(MAKE) requirements.txt generate-ansible generate-pkl
$(MAKE) format
$(MAKE) fix
$(MAKE) test check-semgrep check-bazel-go-files check-org-lint-tests
check:
$(MAKE) requirements.txt check-generated
$(MAKE) check-format test lint check-semgrep check-bazel-go-files check-org-lint-tests
format: format-whitespace
goimports -w .
bazel run //:format
format-whitespace:
@for f in $$(rg -l '\s$$' -g '*.md' -g '*.org' 2>/dev/null || true); do \
$(SED_INPLACE) 's/[[:space:]]*$$//' "$$f"; \
done
check-whitespace:
@FILES=$$(rg -l '\s$$' -g '*.md' -g '*.org' 2>/dev/null || true); \
if [ -n "$$FILES" ]; then echo "Trailing whitespace found in:"; echo "$$FILES"; exit 1; fi
check-format: check-whitespace
goimports -l .
bazel test --test_summary=terse //tools/format:format_test
test:
bazel test --test_summary=terse //...
lint: lint-golangci lint-ruff lint-shellcheck check-spacemacs
# Target fix is best-effort autofix for lint issues. If autofix is not
# available, it still runs lint checks.
fix: fix-golangci fix-ruff lint-shellcheck check-spacemacs
# Go targets
.PHONY: lint-golangci fix-golangci verify-golangci-config check-bazel-go-files
lint-golangci: verify-golangci-config
GOPACKAGESDRIVER= golangci-lint run ./...
oserrorsgodernize ./...
fix-golangci: verify-golangci-config
GOPACKAGESDRIVER= golangci-lint run --fix ./...
oserrorsgodernize --fix ./...
verify-golangci-config:
@CURRENT_HASH=$$(shasum -a 256 .golangci.yml | cut -d' ' -f1); \
if [ ! -f .golangci.yml.hash ] || [ "$$(cat .golangci.yml.hash)" != "$$CURRENT_HASH" ]; then \
echo "Verifying golangci-lint config..."; \
golangci-lint config verify && echo "$$CURRENT_HASH" > .golangci.yml.hash; \
fi
check-bazel-go-files:
@./check-bazel-src-files.sh go
# Python targets
.PHONY: lint-ruff fix-ruff
lint-ruff:
ruff check
fix-ruff:
ruff check --fix
requirements.txt: requirements.in
pip install pip-tools
pip-compile --upgrade --output-file=requirements.txt requirements.in
# Shell targets
.PHONY: lint-shellcheck
lint-shellcheck:
shellcheck -x $$(git ls-files "*.sh")
# Emacs/Spacemacs targets
.PHONY: check-spacemacs check-org-lint-tests
check-spacemacs:
$(MAKE) -C spacemacs check
check-org-lint-tests:
./tools/org-lint/check-org-lint-tests.sh
# Code generation targets
.PHONY: generate-ansible generate-pkl check-generated
# Paths where generators produce output
GENERATED_PATHS := devtools/setup-dev/ansible devtools/gh-nudge/internal/config/pkl
generate-ansible:
$(MAKE) -C devtools/setup-dev/ansible
generate-pkl:
$(MAKE) -C devtools/gh-nudge generate-pkl
check-generated: generate-ansible generate-pkl
@STATUS=0; \
if ! git diff --quiet -- $(GENERATED_PATHS); then \
STALE=$$(git diff --cached --name-only -- $(GENERATED_PATHS)); \
if [ -n "$$STALE" ]; then \
echo "Error: Staged generated files are out of date. Regenerated output differs from staged content."; \
echo "Run 'make all' and re-stage the generated files:"; \
git diff --name-only -- $(GENERATED_PATHS); \
STATUS=1; \
else \
echo "Warning: Generated files differ from index but none are staged for this commit."; \
echo "If your commit includes source changes that affect code generation, stage the generated files:"; \
git diff --name-only -- $(GENERATED_PATHS); \
fi; \
fi; \
UNTRACKED=$$(git ls-files --others --exclude-standard -- $(GENERATED_PATHS)); \
if [ -n "$$UNTRACKED" ]; then \
echo "Error: Untracked generated files found. Stage or remove them:"; \
echo "$$UNTRACKED"; \
STATUS=1; \
fi; \
exit $$STATUS
# Coverage targets
.PHONY: coverage coverage-report coverage-html clean-coverage
coverage:
@echo "Generating coverage report..."
@mkdir -p coverage
bazel coverage --combined_report=lcov //...
@OUTPUT_PATH=$$(bazel info output_path); \
COVERAGE_FILE="$$OUTPUT_PATH/_coverage/_coverage_report.dat"; \
if [ -f "$$COVERAGE_FILE" ]; then \
echo "Filtering test files and vendor code..."; \
lcov --ignore-errors unused --remove "$$COVERAGE_FILE" \
'*_test.go' \
'*/vendor/*' \
'*/external/*' \
'*/testdata/*' \
-o lcov.info; \
echo "Coverage report generated: lcov.info"; \
else \
echo "Error: Coverage file not found at $$COVERAGE_FILE"; \
exit 1; \
fi
coverage-report: coverage
@echo "Coverage summary:"
@lcov --list lcov.info
coverage-html: coverage
@echo "Generating HTML coverage report..."
@genhtml --branch-coverage --output-directory coverage/html lcov.info
@echo "HTML coverage report generated in coverage/html/"
@echo "Open coverage/html/index.html in your browser to view the report"
clean-coverage:
@echo "Cleaning coverage files..."
@rm -rf lcov.info coverage
@echo "Coverage files cleaned"
# Semgrep targets
.PHONY: check-semgrep
check-semgrep:
@if command -v semgrep >/dev/null 2>&1; then \
semgrep scan --error --config auto --config .semgrep; \
else \
echo "Skipping semgrep: not installed"; \
fi