-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (85 loc) · 4.08 KB
/
Makefile
File metadata and controls
103 lines (85 loc) · 4.08 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
SHELL := /usr/bin/env bash
.DEFAULT_GOAL := help
SHS := $(shell git ls-files '*.sh' 2>/dev/null)
BINX := $(shell find bin -type f -perm -111 2>/dev/null)
BATS := $(shell command -v bats 2>/dev/null)
SHFMT_OPTS := -i 4 -ci -sr
# Versioning (optional)
VERSION_FILE ?= VERSION
SEMVER_RE := ^[0-9]+\.[0-9]+\.[0-9]+$
# --------------------------------------------------------------------
# Help
# --------------------------------------------------------------------
.PHONY: help
help: ## Show help
@awk 'BEGIN{FS=":.*##"; print "Targets:"} /^[a-zA-Z0-9_.-]+:.*##/{printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# --------------------------------------------------------------------
# Submodules
# --------------------------------------------------------------------
.PHONY: submodules-init submodules-update submodules-lock init update
submodules-init: ## git submodule init + sync + recursive update
git submodule sync --recursive
git submodule update --init --recursive
submodules-update: ## update submodules to latest tracked branches
git submodule foreach 'git fetch --tags --all || true'
git submodule update --remote --merge --recursive
submodules-lock: ## record current submodule commits (no fetch)
git add .gitmodules
git submodule status
init: submodules-init ## alias
update: submodules-update ## alias
# --------------------------------------------------------------------
# Code quality
# --------------------------------------------------------------------
.PHONY: fmt lint test ci
fmt: ## Format with shfmt
@if [ -n "$(SHS)" ]; then shfmt -w $(SHFMT_OPTS) $(SHS); else echo "No *.sh files to format."; fi
lint: ## Lint with shellcheck
@if [ -n "$(SHS)" ]; then shellcheck -x $(SHS); else echo "No *.sh files to lint."; fi
test: ## Run bats tests
@if [ -z "$(BATS)" ]; then echo "bats not installed"; exit 1; fi
@if ls tests/*.bats >/dev/null 2>&1; then bats -r tests; else echo "No tests/ found; ok."; fi
ci: submodules-init fmt lint test ## Format + lint + test
# --------------------------------------------------------------------
# Versioning (optional)
# --------------------------------------------------------------------
.PHONY: version show-version set-version tag release check-version
version show-version: ## Print current version
@if [ ! -f "$(VERSION_FILE)" ]; then echo "0.0.0" > $(VERSION_FILE); fi
@echo "Version: $$(cat $(VERSION_FILE))"
set-version: ## Set VERSION file (V=MAJOR.MINOR.PATCH)
@test -n "$(V)" || (echo "Usage: make set-version V=1.2.3" && exit 2)
@echo "$(V)" | grep -Eq '$(SEMVER_RE)' || (echo "Invalid version: $(V)"; exit 2)
@echo "$(V)" > $(VERSION_FILE)
@git add $(VERSION_FILE)
@git commit -m "chore: bump version to $(V)" || true
@echo "Set version to $(V)"
tag: ## Create annotated git tag from VERSION
@test -f $(VERSION_FILE) || (echo "Missing $(VERSION_FILE)"; exit 2)
@v=$$(cat $(VERSION_FILE)); echo "$$v" | grep -Eq '$(SEMVER_RE)' || (echo "Invalid version: $$v"; exit 2)
@git tag -a "v$$v" -m "Release v$$v"
@echo "Tagged v$$v"
release: ## Bump VERSION, tag, and push with tags (V=1.2.3)
@test -n "$(V)" || (echo "Usage: make release V=1.2.3" && exit 2)
$(MAKE) set-version V=$(V)
$(MAKE) tag
@git push --follow-tags
check-version: ## Validate VERSION file format
@test -f $(VERSION_FILE) || (echo "Missing $(VERSION_FILE)"; exit 2)
@v=$$(cat $(VERSION_FILE)); echo "$$v" | grep -Eq '$(SEMVER_RE)' || (echo "Invalid version: $$v"; exit 2)
@echo "VERSION OK: $$v"
# --------------------------------------------------------------------
# Install
# --------------------------------------------------------------------
.PHONY: install
install: ## Install all executables in bin/
install -d /usr/local/bin
@if [ -n "$(BINX)" ]; then \
for f in $(BINX); do install -m 0755 $$f /usr/local/bin/$$(basename $$f); done; \
else echo "No executable files in bin/"; fi
# --------------------------------------------------------------------
# Cleanup
# --------------------------------------------------------------------
.PHONY: clean
clean: ## Clean temp files
find . -type f -name '*.tmp' -delete 2>/dev/null || true