-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
197 lines (156 loc) · 5.33 KB
/
Makefile
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
.DEFAULT_GOAL := help
#MAKEFLAGS += --no-print-directory
# You can set these variables from the command line, and also from the environment for the first two.
PREFIX ?= /usr/local
BINPREFIX ?= "$(PREFIX)/bin"
VERSION = $(shell cat VERSION)
SHELL = bash
.ONESHELL:
app_root := $(if $(PROJ_DIR),$(PROJ_DIR),$(CURDIR))
pkg_src = $(app_root)/rsnip
tests_src = $(app_root)/rsnip/tests
BINARY = rsnip
# Makefile directory
CODE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# define files
MANS = $(wildcard ./*.md)
MAN_HTML = $(MANS:.md=.html)
MAN_PAGES = $(MANS:.md=.1)
# avoid circular targets
MAN_BINS = $(filter-out ./tw-extras.md, $(MANS))
################################################################################
# Admin \
ADMIN:: ## ##################################################################
.PHONY: init-env
init-env: ## init-env
@rm -fr ~/xxx/*
@mkdir -p ~/xxx
.PHONY: test
test: ## Run all tests (unit, integration, and doc tests) with debug logging
pushd $(pkg_src) && RUST_LOG=INFO cargo test --all-features --all-targets -- --test-threads=1 #--nocapture
.PHONY: test-cicd
test-cicd: ## Run tests excluding clipboard-dependent tests for CI/CD
RUST_LOG=DEBUG pushd $(pkg_src) && cargo test -- --test-threads=1 \
--skip given_snippet_without_description_when_copying_then_returns_some \
--skip given_template_snippet_when_copying_then_returns_rendered_content
.PHONY: test-trace
test-trace: ## test-trace: show traces (would not be shown due to fzf interactive mode)
rsnip/target/debug/rsnip -ddd complete --ctype mytype --input app --interactive
.PHONY: test-fzf-interactive_1
test-fzf-interactive_1: ## test-fzf-interactive_1
pushd $(pkg_src) && cargo test --color=always --package rsnip --test fuzzy given_no_matches_when_fuzzy_finder_then_shows_interface -- --ignored
################################################################################
# Building, Deploying \
BUILDING: ## ##################################################################
.PHONY: doc
doc: ## doc
@rustup doc --std
pushd $(pkg_src) && cargo doc --open
.PHONY: all
all: clean build install ## all
:
.PHONY: upload
upload: ## upload
@if [ -z "$$CARGO_REGISTRY_TOKEN" ]; then \
echo "Error: CARGO_REGISTRY_TOKEN is not set"; \
exit 1; \
fi
@echo "CARGO_REGISTRY_TOKEN is set"
pushd $(pkg_src) && cargo release publish --execute
.PHONY: build
build: ## build
pushd $(pkg_src) && cargo build --release
#.PHONY: install
#install: uninstall ## install
#@cp -vf $(pkg_src)/target/release/$(BINARY) ~/bin/$(BINARY)
.PHONY: install
install: uninstall ## install
@VERSION=$(shell cat VERSION) && \
echo "-M- Installagin $$VERSION" && \
cp -vf rsnip/target/release/$(BINARY) ~/bin/$(BINARY)$$VERSION && \
ln -vsf ~/bin/$(BINARY)$$VERSION ~/bin/$(BINARY)
.PHONY: uninstall
uninstall: ## uninstall
-@test -f ~/bin/$(BINARY) && rm -v ~/bin/$(BINARY)
.PHONY: bump-major
bump-major: ## bump-major, tag and push
bump-my-version bump --commit --tag major
git push
git push --tags
@$(MAKE) create-release
.PHONY: bump-minor
bump-minor: ## bump-minor, tag and push
bump-my-version bump --commit --tag minor
git push
git push --tags
@$(MAKE) create-release
.PHONY: bump-patch
bump-patch: ## bump-patch, tag and push
bump-my-version bump --commit --tag patch
git push
git push --tags
@$(MAKE) create-release
.PHONY: style
style: ## style
pushd $(pkg_src) && cargo fmt
.PHONY: lint
lint: ## lint
pushd $(pkg_src) && cargo clippy
.PHONY: create-release
create-release: ## create a release on GitHub via the gh cli
@if command -v gh version &>/dev/null; then \
echo "Creating GitHub release for v$(VERSION)"; \
gh release create "v$(VERSION)" --generate-notes; \
else \
echo "You do not have the github-cli installed. Please create release from the repo manually."; \
exit 1; \
fi
################################################################################
# Clean \
CLEAN: ## ############################################################
.PHONY: clean
clean:clean-rs ## clean all
:
.PHONY: clean-build
clean-build: ## remove build artifacts
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . \( -path ./env -o -path ./venv -o -path ./.env -o -path ./.venv \) -prune -o -name '*.egg-info' -exec rm -fr {} +
find . \( -path ./env -o -path ./venv -o -path ./.env -o -path ./.venv \) -prune -o -name '*.egg' -exec rm -f {} +
.PHONY: clean-pyc
clean-pyc: ## remove Python file artifacts
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
.PHONY: clean-rs
clean-rs: ## clean-rs
pushd $(pkg_src) && cargo clean -v
################################################################################
# Misc \
MISC: ## ############################################################
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)
debug: ## debug
@echo "-D- CODE_DIR: $(CODE_DIR)"
.PHONY: list
list: * ## list
@echo $^
.PHONY: list2
%: %.md ## list2
@echo $^
%-plan: ## call with: make <whatever>-plan
@echo $@ : $*
@echo $@ : $^