-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
158 lines (128 loc) · 5.03 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
#
# CONVENTIONS:
#
# - targets shall be ordered such that help list rensembles a typical workflow, e.g. 'make devenv tests'
# - add doc to relevant targets
# - internal targets shall start with '.'
# - KISS
#
SHELL = /bin/bash
.DEFAULT_GOAL := help
OUTPUT_DIR := $(if $(COOCKIECUTTER_OUTPUT_DIR),$(COOCKIECUTTER_OUTPUT_DIR),$(CURDIR)/.output)
TEMPLATE = $(CURDIR)
VERSION := $(shell cat VERSION)
# PYTHON ENVIRON -----------------------------------
.PHONY: devenv
.venv:
@python3 --version
python3 -m venv $@
# upgrading package managers
$@/bin/pip install --upgrade \
pip \
wheel \
setuptools
devenv: .venv ## create a python virtual environment with tools to dev, run and tests cookie-cutter
# installing extra tools
@$</bin/pip3 install -r requirements-dev.txt
# your dev environment contains
@$</bin/pip3 list
@echo "To activate the virtual environment, run 'source $</bin/activate'"
.PHONY: tests
tests: ## tests backed cookie
@pytest -vv \
--basetemp=$(CURDIR)/tmp \
--exitfirst \
--failed-first \
--durations=0 \
--pdb \
$(CURDIR)/tests
# COOKIECUTTER -----------------------------------
.PHONY: play
$(OUTPUT_DIR):
# creating $@
@mkdir -p $@
define cookiecutterrc =
$(shell find $(OUTPUT_DIR) -name ".cookiecutterrc" 2>/dev/null | tail -n 1 )
endef
play: $(OUTPUT_DIR) ## runs cookiecutter into output folder
ifeq (,$(cookiecutterrc))
# baking cookie $(TEMPLATE) onto $<
@cookiecutter --output-dir "$<" "$(TEMPLATE)"
else
# replaying cookie-cutter using $(cookiecutterrc)
@cookiecutter --no-input -f \
--config-file="$(cookiecutterrc)" \
--output-dir="$<" "$(TEMPLATE)"
endif
@echo "To see generated code, lauch 'code $(OUTPUT_DIR)'"
# VERSION BUMP -------------------------------------------------------------------------------
.PHONY: version-patch version-minor version-major
version-patch version-minor version-major: ## commits version as patch (bug fixes not affecting the API), minor/minor (backwards-compatible/INcompatible API addition or changes)
# upgrades as $(subst version-,,$@) version, commits and tags
@bump2version --verbose --list $(subst version-,,$@)
# RELEASE -------------------------------------------------------------------------------
prod_prefix := v
_git_get_current_branch = $(shell git rev-parse --abbrev-ref HEAD)
# NOTE: be careful that GNU Make replaces newlines with space which is why this command cannot work using a Make function
_url_encoded_title = $(VERSION)
_url_encoded_tag = $(prod_prefix)$(VERSION)
_url_encoded_target = $(if $(git_sha),$(git_sha),master)
_prettify_logs = $$(git log \
$$(git describe --match="$(prod_prefix)*" --abbrev=0 --tags)..$(if $(git_sha),$(git_sha),HEAD) \
--pretty=format:"- %s")
define _url_encoded_logs
$(shell \
scripts/url-encoder.bash \
"$(_prettify_logs)"\
)
endef
_git_get_repo_orga_name = $(shell git config --get remote.origin.url | \
grep --perl-regexp --only-matching "((?<=git@github\.com:)|(?<=https:\/\/github\.com\/))(.*?)(?=.git)")
.PHONY: .check-master-branch
.check-master-branch:
@if [ "$(_git_get_current_branch)" != "master" ]; then\
echo -e "\e[91mcurrent branch is not master branch."; exit 1;\
fi
.PHONY: release
release pre-release: .check-master-branch ## Creates github release link. Usage: make release-prod git_sha=optional
# ensure tags are up-to-date
@git pull --tags
@echo -e "\e[33mOpen the following link to create a release:";
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring pre-, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)&body=$(_url_encoded_logs)";
@echo -e "\e[33mOr open the following link to create a release and paste the logs:";
@echo -e "\e[32mhttps://github.com/$(_git_get_repo_orga_name)/releases/new?prerelease=$(if $(findstring pre-, $@),1,0)&target=$(_url_encoded_target)&tag=$(_url_encoded_tag)&title=$(_url_encoded_title)";
@echo -e "\e[34m$(_prettify_logs)"
# TOOLS -----------------------------------
.PHONY: info
info: ## displays info about the scope
# python
@which python
@python --version
@which pip
@pip --version
@pip list
@cookiecutter --version
# environs
@echo "VERSION : $(VERSION)"
@echo "OUTPUT_DIR: $(OUTPUT_DIR)"
@echo "TEMPLATE: $(CURDIR)"
# cookiecutter config
@jq '.' cookiecutter.json
.PHONY: clean clean-force
_git_clean_args = -dx --force --exclude=.vscode/ --exclude=.venv/ --exclude=.python --exclude="*keep*"
clean: ## cleans all unversioned files in project and temp files create by this makefile
# Cleaning unversioned
@git clean -n $(_git_clean_args)
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
@git clean $(_git_clean_args)
-rm -r --force $(OUTPUT_DIR)
clean-force: clean
# removing .venv
-@rm -r --force .venv
.PHONY: help
help: ## this colorful help
@echo "Recipes for '$(notdir $(CURDIR))':"
@echo ""
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""