-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
108 lines (91 loc) · 3.5 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
.DEFAULT_GOAL = all
# Bash is needed for time, compgen, [[ and other builtin commands
SHELL := /bin/bash -o pipefail
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
NOCOLOR := $(shell tput sgr0)
# Module specific parameters
MODULE := html2tei
# These targets do not show as possible target with bash completion
__extra-deps:
@# Do extra stuff (e.g. compiling, downloading) before building the package
@exit 0
.PHONY: __extra-deps
__clean-extra-deps:
@# e.g. @rm -rf stuff
@exit 0
.PHONY: __clean-extra-deps
# From here only generic parts
all: clean venv install test
@echo "all: clean, venv, install, test"
.PHONY: all
install-dep-packages:
@echo "Installing needed packages from Aptfile..."
@# Aptfile can be omited if empty
@[[ ! -s "$(CURDIR)/Aptfile" ]] || \
((command -v apt >/dev/null 2>&1 || (echo >&2 "$(RED)Command 'apt' could not be found!$(NOCOLOR)"; exit 1)) && \
([[ $$(dpkg -l | grep -wcf $(CURDIR)/Aptfile) -ne $$(cat $(CURDIR)/Aptfile | wc -l) ]] || \
(sudo -E apt-get update && \
sudo -E apt-get -yq --no-install-suggests --no-install-recommends $(travis_apt_get_options) \
install `cat $(CURDIR)/Aptfile`)))
@echo "$(GREEN)Needed packages are succesfully installed!$(NOCOLOR)"
.PHONY: install-dep-packages
venv:
@python3 -m venv venv
@./venv/bin/pip install poetry
@./venv/bin/poetry env use python3
@./venv/bin/poetry install --all-extras --no-root
.PHONY: venv
build: install-dep-packages venv __extra-deps
@./venv/bin/poetry build
.PHONY: build
# Install the actual wheel package to test it in later steps
install: build
@./venv/bin/poetry run pip install --upgrade dist/*.whl
.PHONY: install
# Upload to PyPi with poetry (with token if $$PYPI_TOKEN is specified)
upload:
@[[ ! -z "$(PYPI_TOKEN)" ]] && ./venv/bin/poetry publish --username "__token__" --password $(PYPI_TOKEN) || ./venv/bin/poetry publish
.PHONY: upload
test:
@./venv/bin/poetry run python -m pytest --verbose tests/
.PHONY: test
clean: __clean-extra-deps
@rm -rf dist/ .pytest_cache/ $$(./venv/bin/poetry env info -p)
.PHONY: clean
# Do actual release with new version. Originally from: https://github.com/mittelholcz/contextfun
release-major:
@make -s __release BUMP="major"
.PHONY: release-major
release-minor:
@make -s __release BUMP="minor"
.PHONY: release-minor
release-patch:
@make -s __release BUMP="patch"
.PHONY: release-patch
__release:
@[[ "$(BUMP)" == "major" || "$(BUMP)" == "minor" || "$(BUMP)" == "patch" ]] || \
(echo -e "$(RED)Do not call this target!\nUse 'release-major', 'release-minor' or 'release-patch'!$(NOCOLOR)"; \
exit 1)
@[[ -z $$(git status --porcelain) ]] || (echo "$(RED)Working dir is dirty!$(NOCOLOR)"; exit 1)
@# Update dependencies before building and testing (closest to clean install)
@./venv/bin/poetry update
@# poetry version will modify pyproject.toml only. The other steps must be done manually.
@./venv/bin/poetry version $(BUMP)
@# Add modified files to git before commit
@git add pyproject.toml poetry.lock
@# Clean install with (built package) and test
@make all
@# Create release commit and git tag
@make -S __commit_to_origin NEWVER=$$(./venv/bin/poetry run python src/$(MODULE)/version.py)
.PHONY: __release
__commit_to_origin:
@[[ ! -z "$(NEWVER)" ]] || \
(echo -e "$(RED)Do not call this target!\nUse 'release-major', 'release-minor' or 'release-patch'!$(NOCOLOR)"; \
exit 1)
@echo "NEW VERSION: $(NEWVER)"
@git commit -m "Release $(NEWVER)"
@git tag -a "v$(NEWVER)" -m "Release v$(NEWVER)"
@git push
@git push --tags
.PHONY: __commit_to_origin