forked from spwhitton/git-remote-gcrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
256 lines (207 loc) · 7.58 KB
/
Copy pathMakefile
File metadata and controls
256 lines (207 loc) · 7.58 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
SHELL:=/bin/bash
# .ONESHELL:
# .EXPORT_ALL_VARIABLES:
.DEFAULT_GOAL := _help
.SHELLFLAGS = -ec
.PHONY: _help
_help:
@printf "\nUsage: make <command>, valid commands:\n\n"
@awk 'BEGIN {FS = ":.*?##H "}; \
/##H/ && !/@awk.*?##H/ { \
target=$$1; doc=$$2; \
if (length(target) > max) max = length(target); \
targets[NR] = target; docs[NR] = doc; list[NR] = 1; \
} \
END { \
for (i = 1; i <= NR; i++) { \
if (list[i]) printf " \033[1;34m%-*s\033[0m %s\n", max, targets[i], docs[i]; \
} \
print ""; \
}' $(MAKEFILE_LIST)
.PHONY: vars
vars: ##H Display all Makefile variables (simple)
$(info === Makefile Variables (file/command/line origin) ===)
@$(foreach V,$(sort $(.VARIABLES)), \
$(if $(filter file command line,$(origin $(V))), \
$(info $(shell printf "%-30s" "$(V)") = $(value $(V))) \
) \
)
define print_err
printf "\033[1;31m%s\033[0m\n" "$(1)"
endef
define print_warn
printf "\033[1;33m%s\033[0m\n" "$(1)"
endef
define print_success
printf "\033[1;34m✓ %s\033[0m\n" "$(1)"
endef
define print_info
printf "\033[1;36m%s\033[0m\n" "$(1)"
endef
define print_target
printf "\033[1;35m-> %s\033[0m\n" "$(1)"
endef
.PHONY: check/deps
check/deps: check/deps/shellcheck check/deps/kcov ##H Verify kcov & shellcheck
.PHONY: check/deps/shellcheck
check/deps/shellcheck:
@$(call print_info, --- shellcheck version ---)
@shellcheck --version
.PHONY: check/deps/kcov
check/deps/kcov:
@$(call print_info, --- kcov version ---)
@kcov --version
LINT_LOCS_PY ?= $(shell git ls-files '*.py')
LINT_LOCS_SH ?= $(shell git ls-files '*.sh' ':!tests/system-test.sh')
FORMAT_LOCS_SHELL ?= completions/*.sh completions/bash/* completions/zsh/* completions/fish/* completions/templates/bash.in completions/templates/zsh.in completions/templates/fish.in
.PHONY: format
format: ##H Format scripts
@$(call print_target,format)
@$(call print_info,Formatting shell scripts...)
shfmt -ci -bn -s -w $(LINT_LOCS_SH) $(FORMAT_LOCS_SHELL)
@$(call print_success,OK.)
@$(call print_info,Formatting Python scripts...)
-black $(LINT_LOCS_PY)
-isort $(LINT_LOCS_PY)
@$(call print_success,OK.)
@$(call print_info,Formatting YAML files...)
-prettier --write .github/workflows
@$(call print_success,OK.)
.PHONY: lint
lint: ##H Run shellcheck
@$(call print_target,lint)
@$(call print_info,Running shellcheck...)
shellcheck --version
shellcheck install.sh
shellcheck -s sh -e SC3043,SC2001 git-remote-gcrypt
shellcheck tests/*.sh
@$(call print_success,OK.)
@$(call print_info,Linting Python scripts...)
-ruff check $(LINT_LOCS_PY)
@$(call print_success,OK.)
# --- Test Config ---
PWD := $(shell pwd)
COV_ROOT := $(PWD)/.coverage
COV_SYSTEM := $(COV_ROOT)/system
COV_INSTALL := $(COV_ROOT)/installer
.PHONY: test/, test
test: test/
test/: ##H Run tests (purity checks only if kcov missing)
@if command -v kcov >/dev/null 2>&1; then \
$(MAKE) test/installer test/system test/cov; \
else \
$(call print_warn,kcov not found: skipping coverage/bash tests.); \
$(MAKE) test/purity; \
fi
.PHONY: test/installer
test/installer: ##H Test installer logic
@rm -rf $(COV_INSTALL)
@mkdir -p $(COV_INSTALL) .tmp
@rm -f .tmp/kcov.log
@export COV_DIR=$(COV_INSTALL); \
set -o pipefail; \
for test_script in tests/installer-test*.sh; do \
if [ "$$test_script" = "tests/installer-test-logic.sh" ]; then \
kcov --bash-dont-parse-binary-dir \
--include-pattern=install.sh \
--exclude-path=$(PWD)/.git,$(PWD)/tests \
$(COV_INSTALL) \
"$$test_script" 2>&1 | (mkdir -p .tmp; tee -a .tmp/kcov.log); \
else \
bash "$$test_script" 2>&1 | tee -a .tmp/kcov.log; \
fi; \
done; \
if grep -q 'kcov: error:' .tmp/kcov.log; then \
echo "FAIL: kcov errors detected (see above)"; exit 1; \
fi
.PHONY: test/purity
test/purity: ##H Run logic tests (with native /bin/sh)
@echo "running system tests (native /bin/sh)..."
@export GPG_TTY=$$(tty); \
[ -n "$(DEBUG)$(V)" ] && export GCRYPT_DEBUG=1; \
export GIT_CONFIG_PARAMETERS="'gcrypt.gpg-args=--pinentry-mode loopback --no-tty'"; \
for test_script in tests/system-test*.sh; do \
./$$test_script || exit 1; \
done
.PHONY: test/system
test/system: ##H Run logic tests (with bash & coverage)
@echo "running system tests (coverage/bash)..."
@rm -rf $(COV_SYSTEM)
@mkdir -p $(COV_SYSTEM)
@export GPG_TTY=$$(tty); \
[ -n "$(DEBUG)$(V)" ] && export GCRYPT_DEBUG=1 && $(call print_warn,Debug mode enabled); \
export GIT_CONFIG_PARAMETERS="'gcrypt.gpg-args=--pinentry-mode loopback --no-tty'"; \
sed -i 's|^#!/bin/sh|#!/bin/bash|' git-remote-gcrypt; \
trap "sed -i 's|^#!/bin/bash|#!/bin/sh|' git-remote-gcrypt" EXIT; \
for test_script in tests/system-test*.sh; do \
kcov --include-path=$(PWD) \
--include-pattern=git-remote-gcrypt \
--exclude-path=$(PWD)/.git,$(PWD)/tests \
$(COV_SYSTEM)/$$(basename $$test_script) \
./$$test_script; \
done; \
kcov --merge $(COV_SYSTEM)/merged $(COV_SYSTEM)/system-test-*.sh; \
sed -i 's|^#!/bin/bash|#!/bin/sh|' git-remote-gcrypt; \
trap - EXIT
# Find coverage XML: preference for "merged" > any other (search depth: 2 subdirs)
find_coverage_xml = $(or \
$(filter %/merged/cobertura.xml, $(wildcard $(1)/cobertura.xml $(1)/*/cobertura.xml $(1)/*/*/cobertura.xml)), \
$(firstword $(wildcard $(1)/cobertura.xml $(1)/*/cobertura.xml $(1)/*/*/cobertura.xml)) \
)
CHECK_COVERAGE = $(if $(call find_coverage_xml,$(1)), \
echo "" ; \
echo "Debug: WILDCARD=$(wildcard $(1)/*/*/cobertura.xml)" ; \
echo "Debug: MERGED_FILTER=$(filter %/merged/kcov-merged/cobertura.xml, $(wildcard $(1)/*/*/cobertura.xml))" ; \
echo "Report for: file://$(abspath $(dir $(call find_coverage_xml,$(1))))/index.html" ; \
XML_FILE="$(call find_coverage_xml,$(1))" PATT="$(2)" FAIL_UNDER="$(3)" python3 tests/coverage_report.py, \
echo "" ; \
echo "Warning: No coverage report found for $(2) in $(1)")
.PHONY: test/cov
test/cov: ##H Show coverage gaps
$(call CHECK_COVERAGE,$(COV_SYSTEM),git-remote-gcrypt,56) || err=1; \
$(call CHECK_COVERAGE,$(COV_INSTALL),install.sh,84) || err=1; \
exit $$err
# Version from git describe (or fallback)
__VERSION__ := $(shell git describe --tags --always --dirty 2>/dev/null || echo "@@DEV_VERSION@@")
.PHONY: generate
generate: ##H Autogen man docs & shell completions
@$(call print_info,Generating documentation and completions...)
./completions/gen_docs.sh
@$(call print_success,Generated.)
.PHONY: install/, install
install/: install
install: ##H Install system-wide
@$(call print_target,install)
@$(call print_info,Installing git-remote-gcrypt...)
@bash ./install.sh
@$(call print_success,Installed.)
.PHONY: install/user
install/user: ##H make install prefix=~/.local
$(MAKE) install prefix=~/.local
.PHONY: check/install
check/install: ##H Verify installation works
bash ./tests/verify-system-install.sh
.PHONY: uninstall/, uninstall
uninstall/: uninstall
uninstall: ##H Uninstall
@$(call print_target,uninstall)
@bash ./uninstall.sh
@$(call print_success,Uninstalled.)
.PHONY: uninstall/user
uninstall/user: ##H make uninstall prefix=~/.local
$(MAKE) uninstall prefix=~/.local
.PHONY: deploy/debian
deploy/debian: ##H Build Debian package
@$(call print_target,deploy/debian)
@$(call print_info,Building Debian package...)
gbp buildpackage -uc -us
@$(call print_success,Built Debian package.)
.PHONY: deploy/redhat
deploy/redhat: ##H Build RPM package
@$(call print_target,deploy/redhat)
@$(call print_info,Building RPM package...)
rpmbuild -bb redhat/git-remote-gcrypt.spec
@$(call print_success,Built RPM package.)
.PHONY: clean
clean: ##H Clean up
rm -rf .coverage .build_tmp