-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (182 loc) · 7.47 KB
/
Makefile
File metadata and controls
220 lines (182 loc) · 7.47 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
# =============================================================================
# Basher Makefile
# =============================================================================
SHELL := /bin/bash
.DEFAULT_GOAL := help
# Directories
ROOT_DIR := $(shell pwd)
SCRIPTS_DIR := $(ROOT_DIR)/scripts
LIB_DIR := $(ROOT_DIR)/lib
TESTS_DIR := $(ROOT_DIR)/tests
DEMOS_DIR := $(ROOT_DIR)/demos
# Tools
BATS := $(TESTS_DIR)/bats/bin/bats
TEST_RUNNER := $(TESTS_DIR)/run_bats_suite.sh
BATS_TEST_SHELL := $(shell if [ -x /opt/homebrew/bin/bash ]; then printf '/opt/homebrew/bin/bash'; elif [ -x /usr/local/bin/bash ]; then printf '/usr/local/bin/bash'; else command -v bash; fi)
SHELLCHECK := shellcheck
VHS := vhs
# Colors
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m
# =============================================================================
# HELP
# =============================================================================
.PHONY: help
help: ## Show this help message
@printf "$(BLUE)Basher CLI Toolkit$(NC)\n\n"
@printf "$(GREEN)Usage:$(NC) make <target>\n\n"
@printf "$(GREEN)Targets:$(NC)\n"
@awk 'BEGIN {FS = ":.*##"; } /^[a-zA-Z_-]+:.*?##/ { printf " $(YELLOW)%-15s$(NC) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
# =============================================================================
# DEVELOPMENT
# =============================================================================
.PHONY: setup
setup: ## Set up development environment
@printf "$(BLUE)Setting up development environment...$(NC)\n"
@mkdir -p $(SCRIPTS_DIR)/{data,agent,git,file,api,dev}
@mkdir -p $(TESTS_DIR)/{unit,integration,fixtures}/{data,agent,git,file,api,dev}
@mkdir -p $(DEMOS_DIR)/{tapes,gifs}/{data,agent,git,file,api,dev}
@mkdir -p config completions
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: test-deps
test-deps: ## Install test dependencies (BATS)
@printf "$(BLUE)Installing BATS...$(NC)\n"
@if [ ! -d "$(TESTS_DIR)/bats" ]; then \
git clone https://github.com/bats-core/bats-core.git $(TESTS_DIR)/bats; \
fi
@if [ ! -d "$(TESTS_DIR)/bats-support" ]; then \
git clone https://github.com/bats-core/bats-support.git $(TESTS_DIR)/bats-support; \
fi
@if [ ! -d "$(TESTS_DIR)/bats-assert" ]; then \
git clone https://github.com/bats-core/bats-assert.git $(TESTS_DIR)/bats-assert; \
fi
@if [ ! -d "$(TESTS_DIR)/bats-file" ]; then \
git clone https://github.com/bats-core/bats-file.git $(TESTS_DIR)/bats-file; \
fi
@printf "$(GREEN)Done!$(NC)\n"
# =============================================================================
# LINTING
# =============================================================================
.PHONY: lint
lint: lint-lib lint-scripts lint-hooks ## Run all linters
.PHONY: lint-lib
lint-lib: ## Lint library files
@printf "$(BLUE)Linting libraries...$(NC)\n"
@$(SHELLCHECK) -x $(LIB_DIR)/*.sh
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: lint-scripts
lint-scripts: ## Lint script files
@printf "$(BLUE)Linting scripts...$(NC)\n"
@find $(SCRIPTS_DIR) -name '*.sh' -type f | xargs $(SHELLCHECK) -x 2>/dev/null || true
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: lint-hooks
lint-hooks: ## Lint hook files
@printf "$(BLUE)Linting hooks...$(NC)\n"
@find hooks -name '*.sh' -type f | xargs $(SHELLCHECK) -x 2>/dev/null || true
@printf "$(GREEN)Done!$(NC)\n"
# =============================================================================
# TESTING
# =============================================================================
.PHONY: test
test: test-deps ## Run the full Bats matrix
@printf "$(BLUE)Running the full Bats matrix...$(NC)\n"
@BATS_TEST_SHELL="$(BATS_TEST_SHELL)" $(TEST_RUNNER) --scope all
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: test-unit
test-unit: test-deps ## Run unit and library contract tests
@printf "$(BLUE)Running unit tests...$(NC)\n"
@BATS_TEST_SHELL="$(BATS_TEST_SHELL)" $(TEST_RUNNER) --scope unit
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: test-top
test-top: test-deps ## Run top-level Bats suites in tests/*.bats
@printf "$(BLUE)Running top-level tests...$(NC)\n"
@BATS_TEST_SHELL="$(BATS_TEST_SHELL)" $(TEST_RUNNER) --scope top
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: test-integration
test-integration: test-deps ## Run integration tests only
@printf "$(BLUE)Running integration tests...$(NC)\n"
@BATS_TEST_SHELL="$(BATS_TEST_SHELL)" $(TEST_RUNNER) --scope integration
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: test-coverage
test-coverage: test-deps ## Run tests with coverage
@printf "$(BLUE)Running tests with coverage...$(NC)\n"
@mkdir -p coverage
@BATS_TEST_SHELL="$(BATS_TEST_SHELL)" kcov --include-path=$(LIB_DIR)/,$(SCRIPTS_DIR)/ coverage $(BATS) $(TESTS_DIR)/unit/
@printf "$(GREEN)Coverage report: coverage/index.html$(NC)\n"
.PHONY: test-watch
test-watch: ## Watch for changes and run tests
@printf "$(BLUE)Watching for changes...$(NC)\n"
@while true; do \
inotifywait -e modify,create,delete -r $(LIB_DIR) $(SCRIPTS_DIR) $(TESTS_DIR); \
make test-unit; \
done
# =============================================================================
# DEMOS
# =============================================================================
.PHONY: demos
demos: ## Generate all VHS demos
@printf "$(BLUE)Generating demos...$(NC)\n"
@find $(DEMOS_DIR)/tapes -name '*.tape' -exec $(VHS) {} \;
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: demos-data
demos-data: ## Generate data script demos
@find $(DEMOS_DIR)/tapes/data -name '*.tape' -exec $(VHS) {} \;
.PHONY: demos-agent
demos-agent: ## Generate agent script demos
@find $(DEMOS_DIR)/tapes/agent -name '*.tape' -exec $(VHS) {} \;
# =============================================================================
# BUILD & RELEASE
# =============================================================================
.PHONY: build
build: lint test ## Build for release (lint + test)
@printf "$(GREEN)Build complete!$(NC)\n"
.PHONY: release
release: build ## Create a release
@printf "$(BLUE)Creating release...$(NC)\n"
@./scripts/dev/release.sh
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: changelog
changelog: ## Generate changelog
@printf "$(BLUE)Generating changelog...$(NC)\n"
@git log --oneline --pretty=format:"- %s" > CHANGELOG.md
@printf "$(GREEN)Done!$(NC)\n"
# =============================================================================
# DOCUMENTATION
# =============================================================================
.PHONY: docs
docs: ## Generate documentation
@printf "$(BLUE)Generating documentation...$(NC)\n"
@./scripts/dev/generate-docs.sh
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: docs-serve
docs-serve: ## Serve documentation locally
@printf "$(BLUE)Serving docs at http://localhost:8000$(NC)\n"
@cd docs && python3 -m http.server
# =============================================================================
# CLEANUP
# =============================================================================
.PHONY: clean
clean: ## Clean build artifacts
@printf "$(BLUE)Cleaning...$(NC)\n"
@rm -rf coverage/
@rm -rf $(DEMOS_DIR)/gifs/*
@find . -name '*.tmp' -delete
@find . -name '*.bak' -delete
@printf "$(GREEN)Done!$(NC)\n"
.PHONY: clean-all
clean-all: clean ## Clean everything including dependencies
@rm -rf $(TESTS_DIR)/bats
@rm -rf $(TESTS_DIR)/bats-support
@rm -rf $(TESTS_DIR)/bats-assert
@rm -rf $(TESTS_DIR)/bats-file
# =============================================================================
# INSTALLATION
# =============================================================================
.PHONY: install
install: ## Install basher locally
@./install.sh
.PHONY: uninstall
uninstall: ## Uninstall basher
@./uninstall.sh