-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (117 loc) · 4.99 KB
/
Makefile
File metadata and controls
132 lines (117 loc) · 4.99 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
.ONESHELL:
DEBUG ?= false
VERBOSE ?= false
ifeq ($(DEBUG),true)
MAKEFLAGS += --debug=v
else ifneq ($(VERBOSE),true)
MAKEFLAGS += --silent
endif
PRECOMMIT ?= pre-commit
ifneq ($(shell command -v prek >/dev/null 2>&1 && echo y),)
PRECOMMIT := prek
ifneq ($(filter true,$(DEBUG) $(VERBOSE)),)
$(info Using prek for pre-commit checks)
ifeq ($(DEBUG),true)
PRECOMMIT := $(PRECOMMIT) -v
endif
endif
endif
# Terminal formatting (tput with fallbacks to ANSI codes)
_COLOR := $(shell tput sgr0 2>/dev/null || printf '\033[0m')
BOLD := $(shell tput bold 2>/dev/null || printf '\033[1m')
CYAN := $(shell tput setaf 6 2>/dev/null || printf '\033[0;36m')
GREEN := $(shell tput setaf 2 2>/dev/null || printf '\033[0;32m')
RED := $(shell tput setaf 1 2>/dev/null || printf '\033[0;31m')
YELLOW := $(shell tput setaf 3 2>/dev/null || printf '\033[0;33m')
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help message
@echo "$(BOLD)Available targets:$(_COLOR)"
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "; max = 0} \
{if (length($$1) > max) max = length($$1)} \
{targets[NR] = $$0} \
END {for (i = 1; i <= NR; i++) { \
split(targets[i], arr, FS); \
printf "$(CYAN)%-*s$(_COLOR) %s\n", max + 2, arr[1], arr[2]}}'
@echo
@echo "$(BOLD)Environment variables:$(_COLOR)"
@echo " $(YELLOW)DEBUG$(_COLOR) = true|false Set to true to enable debug output (default: false)"
@echo " $(YELLOW)VERBOSE$(_COLOR) = true|false Set to true to enable verbose output (default: false)"
.PHONY: develop
WITH_HOOKS ?= true
develop: ## Set up the project for development (WITH_HOOKS={true|false}, default=true)
@git config --local blame.ignoreRevsFile .git-blame-ignore-revs
@set -e; \
if command -v git-lfs >/dev/null 2>&1; then \
git lfs install --local --skip-repo || true; \
fi; \
current_branch=$$(git branch --show-current); \
stash_was_needed=0; \
cleanup() { \
exit_code=$$?; \
if [ "$$current_branch" != "$$(git branch --show-current)" ]; then \
echo "$(YELLOW)Warning: Still on $$(git branch --show-current). Attempting to return to $$current_branch...$(_COLOR)"; \
if git switch "$$current_branch" 2>/dev/null; then \
echo "Successfully returned to $$current_branch"; \
else \
echo "$(YELLOW)Could not return to $$current_branch. You are on $$(git branch --show-current).$(_COLOR)"; \
fi; \
fi; \
if [ $$stash_was_needed -eq 1 ] && git stash list | head -1 | grep -q "Auto stash by make develop"; then \
echo "$(YELLOW)Note: Your stashed changes are still available. Run 'git stash pop' to restore them.$(_COLOR)"; \
fi; \
exit $$exit_code; \
}; \
trap cleanup EXIT; \
if ! git diff --quiet || ! git diff --cached --quiet; then \
git stash push -m "Auto stash by make develop"; \
stash_was_needed=1; \
fi; \
git switch main && git pull; \
if command -v git-lfs >/dev/null 2>&1; then \
git lfs pull || true; \
fi; \
git switch "$$current_branch"; \
if [ $$stash_was_needed -eq 1 ]; then \
if git stash apply; then \
git stash drop; \
else \
echo "$(RED)Error: Stash apply had conflicts. Resolve them, then run: git stash drop$(_COLOR)"; \
fi; \
fi; \
trap - EXIT
@if [ "$(WITH_HOOKS)" = "true" ]; then \
$(MAKE) enable-pre-commit; \
fi
.PHONY: test-hooks
test-hooks: ## Run hook unit tests
@bash tests/test-unit.sh
.PHONY: test-integration
test-integration: ## Run pre-commit integration tests
@bash tests/test-integration.sh
.PHONY: test
test: test-hooks test-integration ## Run all tests
.PHONY: check
check: run-pre-commit test ## Run all code quality checks and tests
.PHONY: benchmark
benchmark: ## Run all benchmark scripts (see scripts/benchmark/run.sh --list)
@sh scripts/benchmark/run.sh
.PHONY: release-pr
release-pr: ## Trigger Release PR workflow (usage: make release-pr VERSION=1.2.3 or VERSION=v1.2.3)
@test -n "$(VERSION)" || (echo "$(RED)Error: VERSION is required (e.g. 1.2.3 or v1.2.3)$(_COLOR)"; exit 1)
@gh workflow run release-pr.yml --ref main -f version=$(VERSION)
.PHONY: release-pr-watch
release-pr-watch: ## Watch the latest workflow run (run after make release-pr)
@gh run watch
.PHONY: enable-pre-commit
enable-pre-commit: ## Enable pre-commit hooks (along with commit-msg and pre-push hooks)
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit install --hook-type commit-msg --hook-type pre-commit --hook-type pre-push --hook-type prepare-commit-msg ; \
else \
echo "$(YELLOW)Warning: pre-commit is not installed. Skipping hook installation.$(_COLOR)"; \
echo "Install it with: pip install pre-commit (or brew install pre-commit on macOS)"; \
fi
.PHONY: run-pre-commit
run-pre-commit: ## Run the pre-commit checks
$(PRECOMMIT) run --all-files