-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
214 lines (173 loc) · 7.43 KB
/
Copy pathMakefile
File metadata and controls
214 lines (173 loc) · 7.43 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
.DEFAULT_GOAL := help
# Configuration
PREFIX ?= /usr/local
BINPREFIX ?= $(PREFIX)/bin
VERSION = $(shell cat VERSION)
SHELL = bash
.ONESHELL:
VERSION = $(shell cat VERSION)
# Paths
app_root := $(CURDIR)
pkg_src = $(app_root)/rsenv
BINARY = rsenv
################################################################################
# Development #
################################################################################
.PHONY: test
test: ## Run all tests (single-threaded, required)
cd $(pkg_src) && cargo test -- --test-threads=1
.PHONY: test-verbose
test-verbose: ## Run tests with debug logging
cd $(pkg_src) && RUST_LOG=DEBUG cargo test -- --test-threads=1 --nocapture
# NOTE: recipes must be single logical lines (\-continued). The .ONESHELL above is
# silently ignored by the GNU make 3.81 that macOS ships (needs >= 3.82).
#
# Not covered by `make test`: skim drives the terminal directly, so the selector has
# no automated test. Run this after touching SkimSelector or bumping the skim crate.
.PHONY: test-skim
test-skim: build-debug ## Interactive smoke test of the skim selector (needs a TTY)
@test -t 0 || { echo "-E- test-skim is interactive: run it from a terminal, not a pipe or CI."; exit 1; }
@d=$$(mktemp -d); \
trap 'rm -rf "$$d"' EXIT; \
printf '# rsenv:\nexport BASE=1\n' > "$$d/base.env"; \
printf '# rsenv: base.env\nexport STAGE=dev\n' > "$$d/dev.env"; \
printf '# rsenv: base.env\nexport STAGE=prod\n' > "$$d/prod.env"; \
echo "-M- Fixture: $$d (dev.env and prod.env both inherit base.env)"; \
echo "-M- Expect a 3-entry picker. Type to filter, Enter to pick, Esc to abort."; \
echo "-M- pick dev.env -> prints BASE=1 and STAGE=dev"; \
echo "-M- Esc -> no output, exit 0"; \
echo; \
$(pkg_src)/target/debug/$(BINARY) env select "$$d"
.PHONY: watch
watch: ## Run tests on file changes (requires cargo-watch)
cd $(pkg_src) && cargo watch -x 'test -- --test-threads=1'
.PHONY: format
format: ## Format code
cd $(pkg_src) && cargo fmt
.PHONY: lint
lint: ## Lint and auto-fix
cd $(pkg_src) && cargo clippy --fix --allow-dirty --allow-staged
cd $(pkg_src) && cargo fix --lib -p rsenv --tests --allow-dirty --allow-staged
.PHONY: check
check: ## Quick compile check (no codegen)
cd $(pkg_src) && cargo check
.PHONY: doc
doc: ## Generate and open documentation
cd $(pkg_src) && cargo doc --open
################################################################################
# Building #
################################################################################
.PHONY: build
build: ## Build release version
cd $(pkg_src) && cargo build --release
.PHONY: build-debug
build-debug: ## Build debug version
cd $(pkg_src) && cargo build
.PHONY: all
all: clean build install ## Clean, build release, and install
.PHONY: all-debug
all-debug: clean build-debug install-debug ## Clean, build debug, and install
################################################################################
# Installation #
################################################################################
# macOS requires re-signing after copy (adhoc signature becomes invalid)
define install_binary
@echo "-M- Installing $(BINARY) v$(VERSION) from $(1)"
cp -f $(1) ~/bin/$(BINARY)$(VERSION)
codesign --force --sign - ~/bin/$(BINARY)$(VERSION)
ln -sf ~/bin/$(BINARY)$(VERSION) ~/bin/$(BINARY)
~/bin/$(BINARY) completion bash > ~/.bash_completions/$(BINARY) 2>/dev/null || true
endef
.PHONY: install
install: uninstall ## Install release binary to ~/bin
$(call install_binary,$(pkg_src)/target/release/$(BINARY))
.PHONY: install-debug
install-debug: uninstall ## Install debug binary to ~/bin
$(call install_binary,$(pkg_src)/target/debug/$(BINARY))
.PHONY: uninstall
uninstall: ## Remove installed binary
@rm -f ~/bin/$(BINARY) ~/bin/$(BINARY)[0-9]* ~/.bash_completions/$(BINARY)
################################################################################
# Release #
################################################################################
.PHONY: check-github-token
check-github-token:
@test -n "$$GITHUB_TOKEN" || { echo "Error: GITHUB_TOKEN not set"; exit 1; }
@echo "GITHUB_TOKEN is set"
.PHONY: bump-major
bump-major: check-github-token ## Bump major version, tag, push, create release
bump-my-version bump --commit --tag major
git push && git push --tags
@$(MAKE) create-release
.PHONY: bump-minor
bump-minor: check-github-token ## Bump minor version, tag, push, create release
bump-my-version bump --commit --tag minor
git push && git push --tags
@$(MAKE) create-release
.PHONY: bump-patch
bump-patch: check-github-token ## Bump patch version, tag, push, create release
bump-my-version bump --commit --tag patch
git push && git push --tags
@$(MAKE) create-release
.PHONY: bump-prenum
bump-prenum: check-github-token ## Bump pre-release number (alpha.1 → alpha.2)
bump-my-version bump --commit --tag prenum
git push && git push --tags
@$(MAKE) create-release
.PHONY: bump-pre
bump-pre: check-github-token ## Bump pre-release stage (alpha → beta → rc)
bump-my-version bump --commit --tag pre
git push && git push --tags
@$(MAKE) create-release
.PHONY: release
release: check-github-token ## Release current version (2.0.0-alpha.1 → 2.0.0)
@RELEASE_VERSION=$$(cat VERSION | sed 's/-.*//') && \
bump-my-version bump --commit --tag --new-version $$RELEASE_VERSION
git push && git push --tags
@$(MAKE) create-release
.PHONY: create-release
create-release: check-github-token ## Create GitHub release via gh CLI
@command -v gh >/dev/null || { echo "gh CLI not installed"; exit 1; }
@case "$(VERSION)" in \
*alpha*|*beta*|*rc*) gh release create "v$(VERSION)" --generate-notes --prerelease ;; \
*) gh release create "v$(VERSION)" --generate-notes --latest ;; \
esac
.PHONY: upload
upload: ## Publish to crates.io
@test -n "$$CARGO_REGISTRY_TOKEN" || { echo "Error: CARGO_REGISTRY_TOKEN not set"; exit 1; }
cd $(pkg_src) && cargo publish
.PHONY: fix-version
fix-version: check-github-token ## fix-version of Cargo.toml, re-connect with HEAD
git add rsenv/Cargo.lock
git commit --amend --no-edit
git tag -f "v$(VERSION)"
git push --force-with-lease
git push --tags --force
################################################################################
# Clean #
################################################################################
.PHONY: clean
clean: ## Clean build artifacts
cd $(pkg_src) && cargo clean
################################################################################
# Help #
################################################################################
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([%a-zA-Z0-9_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
if target != "dummy":
print("\033[36m%-20s\033[0m %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
.PHONY: help
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
.PHONY: debug
debug: ## Show Makefile variables
@echo "VERSION: $(VERSION)"
@echo "app_root: $(app_root)"
@echo "pkg_src: $(pkg_src)"
@echo "BINARY: $(BINARY)"