forked from kpn/katka-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
166 lines (124 loc) · 3.63 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
# This Makefile requires the following commands to be available:
# * virtualenv
# * python3.8
# * docker
IMAGE=katka-core
DOCKER_REPOSITORY=kpnnv
REQUIREMENTS_BASE:=requirements/requirements-base.txt
REQUIREMENTS_TEST:=requirements/requirements-testing.txt
REQUIREMENTS_TXT:=requirements.txt
PYTHON_VERSION=python3.8
BLACK="black"
FLAKE8="flake8"
ISORT="isort"
PIP="pip"
TOX="tox"
PYTHON="$(PYTHON_VERSION)"
TWINE="twine"
# When we are not in Docker we assume virtualenv usage
ifneq ($(IN_DOCKER), 1)
BLACK="venv/bin/black"
FLAKE8="venv/bin/flake8"
ISORT="venv/bin/isort"
PIP="venv/bin/pip"
TOX="venv/bin/tox"
PYTHON="venv/bin/python"
TWINE="venv/bin/twine"
endif
MAKE_MIGRATIONS=`$(shell echo $(PYTHON)) manage.py makemigrations;`
MIGRATIONS_CHECK=`echo $(MAKE_MIGRATIONS_OUTPUT) | awk '{print match($$0, "No changes detected")}'`
# ********** Cleaning **********
.PHONY: pyclean
pyclean:
@find . -name *.pyc -delete
@rm -rf *.egg-info build
@rm -rf coverage.xml .coverage
.PHONY: clean
clean: pyclean
@rm -rf venv
@rm -rf .tox
# ********** Migrations **********
# check if there is any forgotten migration
.PHONY: check_forgotten_migrations
check_forgotten_migrations: install_requirement_txt
$(eval MAKE_MIGRATIONS_OUTPUT:="$(shell echo $(MAKE_MIGRATIONS))")
@echo $(MAKE_MIGRATIONS_OUTPUT)
@if [ $(MIGRATIONS_CHECK) -gt 0 ]; then \
echo "There aren't any forgotten migrations. Well done!"; \
else \
echo "Error! You've forgotten to add the migrations!"; \
exit 1; \
fi
# migrate on dev environment
.PHONY: migrate
migrate:
$(PYTHON) manage.py migrate --noinput
@echo 'Done!'
# ********** Docker **********
docker/build:
docker build -t $(DOCKER_REPOSITORY)/$(IMAGE) .
docker/build/%:
docker build -t $(DOCKER_REPOSITORY)/$(IMAGE):$* .
docker/tag/%:
docker tag $(DOCKER_REPOSITORY)/$(IMAGE) $(DOCKER_REPOSITORY)/$(IMAGE):$*
docker/push/%:
docker push $(DOCKER_REPOSITORY)/$(IMAGE):$*
docker/%: docker/build
docker run --rm -v $(PWD):$(PWD) --tmpfs $(PWD)/.tox:exec -w $(PWD) $(DOCKER_REPOSITORY)/$(IMAGE) make $*
docker/publish: docker/build
docker run --rm -v $(PWD):$(PWD) -w $(PWD) \
-e tag=$(TAG) -e TWINE_PASSWORD=$(TWINE_PASSWORD) -e TWINE_USERNAME=$(TWINE_USERNAME) \
$(DOCKER_REPOSITORY)/$(IMAGE) make publish
# ********** Tests **********
# Used by the PR jobs. This target should include all tests necessary
# to determine if the PR should be rejected or not.
.PHONY: tox
tox:
$(TOX)
.PHONY: test
test: docker/test_local
.PHONY: test_local
test_local: install_requirement_txt check_forgotten_migrations install_requirement_unittests lint tox
@echo 'tests done'
# ********** Code style **********
.PHONY: lint
lint: lint/flake8 lint/isort lint/black
.PHONY: lint/isort
lint/isort:
$(ISORT) -rc -c katka tests
.PHONY: lint/flake8
lint/flake8:
$(FLAKE8) katka tests
.PHONY: lint/black
lint/black:
$(BLACK) --check katka tests
.PHONY: format
format: format/isort format/black
.PHONY: format/isort
format/isort:
$(ISORT) -rc katka tests
.PHONY: format/black
format/black:
$(BLACK) --verbose katka tests
# ********** Packaging and distributing **********
setup.py:
$(PYTHON) setup_gen.py
@echo 'setup.py created'
publish: setup.py
$(PYTHON) setup.py sdist bdist_wheel
$(TWINE) check dist/*
$(TWINE) upload dist/*
# ********** Requirements **********
.PHONY: install_requirement_txt
install_requirement_txt:
@$(PIP) install -r $(REQUIREMENTS_TXT)
.PHONY: install_requirement_unittests
install_requirement_unittests:
$(PIP) install -r $(REQUIREMENTS_TEST)
# ********** Virtual environment **********
.PHONY: venv
venv:
@rm -rf venv
@$(PYTHON_VERSION) -m venv venv
@$(PIP) install -r $(REQUIREMENTS_TXT)
@touch $@