-
-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (118 loc) · 4.42 KB
/
Copy pathMakefile
File metadata and controls
138 lines (118 loc) · 4.42 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
SHELL=/bin/bash
-include .env
STATIC_ANALYSIS_CHECKER := $(shell which shellcheck 2> /dev/null)
LINTER_CHECKER := $(shell which editorconfig-checker 2> /dev/null)
GIT_DIR = $(shell git rev-parse --git-dir 2> /dev/null)
OS:=
ifeq ($(OS),Windows_NT)
OS +=WIN32
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
OS +=_AMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
OS +=_IA32
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS+=LINUX
endif
ifeq ($(UNAME_S),Darwin)
OS+=OSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
OS +=_AMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
OS+=_IA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
OS+=_ARM
endif
endif
help:
@echo ""
@echo "Usage: make [command]"
@echo ""
@echo "Commands:"
@echo " test Run the tests"
@echo " test/list List all tests under the tests directory"
@echo " test/watch Automatically run tests every second"
@echo " docker/alpine Run into a Docker Linux/Alpine:latest image"
@echo " pre_commit/install Install the pre-commit hook"
@echo " pre_commit/run Function that will be called when the pre-commit hook runs"
@echo " sa Run shellcheck static analysis tool"
@echo " lint Run editorconfig linter tool"
@echo " docs/install Install docs npm dependencies (in docs/)"
@echo " docs/dev Start the VitePress dev server"
@echo " docs/build Build the documentation site"
@echo " docs/preview Preview the built documentation"
SRC_SCRIPTS_DIR=src
TEST_SCRIPTS_DIR=tests
EXAMPLE_TEST_SCRIPTS=./example/logic_test.sh
PRE_COMMIT_SCRIPTS_FILE=./bin/pre-commit
TEST_SCRIPTS = $(wildcard $(TEST_SCRIPTS_DIR)/*/*[tT]est.sh)
test/list:
@echo "Test scripts found:"
@echo $(TEST_SCRIPTS) | tr ' ' '\n'
test: $(TEST_SCRIPTS)
@bash ./bashunit $(TEST_SCRIPTS)
test/watch: $(TEST_SCRIPTS)
@bash ./bashunit $(TEST_SCRIPTS)
@fswatch -m poll_monitor -or $(SRC_SCRIPTS_DIR) $(TEST_SCRIPTS_DIR) .env Makefile | xargs -n1 bash ./bashunit $(TEST_SCRIPTS)
docker/alpine:
@docker run --rm -it -v "$(shell pwd)":/project -w /project alpine:latest \
sh -c "apk add bash make shellcheck git && bash"
docker/ubuntu:
@docker run --rm -it -v "$(shell pwd)":/project -w /project ubuntu:latest \
sh -c "apt update && apt install -y bash make shellcheck git && bash"
pre_commit/install:
@echo "Installing pre-commit hook"
cp $(PRE_COMMIT_SCRIPTS_FILE) $(GIT_DIR)/hooks/
pre_commit/run:
@$(MAKE) -j3 test/parallel sa lint
test/parallel: $(TEST_SCRIPTS)
@bash ./bashunit --parallel --simple $(TEST_SCRIPTS)
# sa: xargs (unlike `find -exec {} \;`) propagates shellcheck's exit code, so
# findings actually fail the target; the excludes mirror the CI workflow's
# SHELLCHECK_OPTS for local/CI parity. One file per invocation (like CI's
# action) because shellcheck 0.11.0 can crash on multi-file batches with -x;
# -P 4 keeps the wall time reasonable.
#
# The file list comes from git, not `find`, for two reasons: `find .` descends
# into .claude/worktrees/ (linked worktrees hold whole copies of the tree, so
# the target lints the repo N+1 times and appears to hang), and its "*.sh" glob
# never sees the extensionless entrypoint or the bin/ scripts. `find` remains
# the fallback outside a git checkout.
#
# --others --exclude-standard includes files that are new and not yet staged:
# without it a brand-new script is invisible to `make sa` and only fails once CI
# lints it, which is exactly backwards.
sa:
ifndef STATIC_ANALYSIS_CHECKER
@printf "\e[1m\e[31m%s\e[0m\n" "Shellcheck not installed: Static analysis not performed!" && exit 1
else
@{ if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then \
git ls-files -z --cached --others --exclude-standard \
"*.sh" bashunit bin/pre-commit bin/create-pr; \
else \
find . -name "*.sh" -not -path "./local/*" -not -path "./.claude/worktrees/*" -print0; \
fi; } \
| xargs -0 -n 1 -P 4 shellcheck -xC -e SC1091 -e SC2155 -e SC2016 \
&& printf "\e[1m\e[32m%s\e[0m\n" "ShellCheck: OK!"
endif
lint:
ifndef LINTER_CHECKER
@printf "\e[1m\e[31m%s\e[0m\n" "Editorconfig not installed: Lint not performed!" && exit 1
else
@editorconfig-checker && printf "\e[1m\e[32m%s\e[0m\n" "editorconfig-check: OK!"
endif
docs/install:
@cd docs && npm ci
docs/dev:
@cd docs && npm run dev
docs/build:
@cd docs && npm run build
docs/preview:
@cd docs && npm run preview