-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
285 lines (247 loc) · 11.1 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
VIRTUAL_ENV ?= venv
NODE_BIN = node_modules/.bin
SOURCE_DIRS = meinberlin tests
ARGUMENTS=$(filter-out $(firstword $(MAKECMDGOALS)), $(MAKECMDGOALS))
# for mac os gsed is needed (brew install gnu-sed and brew install gsed)
SED = sed
ifneq (, $(shell command -v gsed;))
SED = gsed
endif
# checks the OS uname respones (mac will respond with Darwin)
OS := $(shell uname)
START_NOW := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
ifeq ($(OS),Darwin)
END_NOW = $(shell date -u -v+30d +"%Y-%m-%dT%H:%M:%SZ")
START_2 = $(shell date -u -v+30d +"%Y-%m-%dT%H:%M:%SZ")
END_2 = $(shell date -u -v+30d +"%Y-%m-%dT%H:%M:%SZ")
START_3 = $(shell date -u -v+30d +"%Y-%m-%dT%H:%M:%SZ")
END_3 = $(shell date -u -v+30d +"%Y-%m-%dT%H:%M:%SZ")
else
END_NOW = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" -d "+30 days")
START_2 = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" -d "+31 days")
END_2 = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" -d "+61 days")
START_3 = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" -d "+62 days")
END_3 = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" -d "+92 days")
endif
.PHONY: all
all: help
.PHONY: help
help:
@echo mein.berlin development tools
@echo
@echo It will either use an exisiting virtualenv if it was entered
@echo before or create a new one in the venv subdirectory.
@echo
@echo usage:
@echo
@echo " make install -- install dev setup"
@echo " make clean -- delete node modules and venv"
@echo " make fixtures -- install regions"
@echo " make server -- start a dev server"
@echo " make watch -- start a dev server and rebuild js and css files on changes"
@echo " make background -- start background processes"
@echo " make test -- run all test cases"
@echo " make pytest -- run all test cases with pytest"
@echo " make pytest-lastfailed -- run test that failed last"
@echo " make pytest-clean -- test on new database"
@echo " make jstest -- run js tests with coverage"
@echo " make jstest-nocov -- run js tests without coverage"
@echo " make jstest-debug -- run changed tests only, no coverage"
@echo " make jstest-updateSnapshots -- update jest snapshots"
@echo " make coverage -- write coverage report to dir htmlcov"
@echo " make lint -- lint all project files"
@echo " make lint-quick -- lint all files staged in git"
@echo " make lint-js-fix -- fix linting for all js files staged in git"
@echo " make lint-html-fix -- fix linting for all html files passed as argument"
@echo " make lint-html-files -- lint for all html files with django profile rules"
@echo " make lint-python-files -- lint all python files passed as argument"
@echo " make po -- create new po files from the source"
@echo " make mo -- create new mo files from the translated po files"
@echo " make release -- build everything required for a release"
@echo " make postgres-start -- start the local postgres cluster"
@echo " make postgres-stop -- stops the local postgres cluster"
@echo " make postgres-create -- create the local postgres cluster (only works on ubuntu 20.04)"
@echo " make local-a4 -- patch to use local a4 (needs to have path ../adhocracy4)"
@echo " make celery-worker-start -- starts the celery worker in the foreground"
@echo " make celery-worker-status -- lists all registered tasks and active worker nodes"
@echo " make celery-worker-dummy-task -- calls the dummy task and prints result from redis"
@echo " make celery-beat -- starts the celery beat in the foreground"
@echo
.PHONY: install
install:
npm install --no-save
npm run build
if [ ! -f $(VIRTUAL_ENV)/bin/python3 ]; then python3 -m venv $(VIRTUAL_ENV); fi
$(VIRTUAL_ENV)/bin/python3 -m pip install --upgrade -r requirements/dev.txt
$(VIRTUAL_ENV)/bin/python3 manage.py migrate
.PHONY: clean
clean:
if [ -f package-lock.json ]; then rm package-lock.json; fi
if [ -d node_modules ]; then rm -rf node_modules; fi
if [ -d venv ]; then rm -rf venv; fi
.PHONY: fixtures
fixtures:
# set start date of active phase to today
$(SED) -i "s/2022-12-31T23:00:00Z/$(START_NOW)/g" meinberlin/fixtures/phases.json
$(SED) -i "s/2023-01-31T22:59:00Z/$(END_NOW)/g" meinberlin/fixtures/phases.json
# set start date of upcoming phase to today + 31
$(SED) -i "s/2023-01-31T23:00:00Z/$(START_2)/g" meinberlin/fixtures/phases.json
$(SED) -i "s/2023-02-28T22:59:00Z/$(END_2)/g" meinberlin/fixtures/phases.json
# set start date of last phase to today + 62
$(SED) -i "s/2023-02-28T23:00:00Z/$(START_3)/g" meinberlin/fixtures/phases.json
$(SED) -i "s/2023-03-31T21:59:00Z/$(END_3)/g" meinberlin/fixtures/phases.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/site-dev.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/users.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/accounts.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/administrative_districts.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/map-preset.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/organisations.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/projects.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/modules.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/phases.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/maps.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/polls.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/live_questions.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/categories.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/documents.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/labels.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/maptopicprop.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/moderationtasks.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/topicprio.json
$(VIRTUAL_ENV)/bin/python3 manage.py loaddata meinberlin/fixtures/votes.json
git restore meinberlin/fixtures/phases.json
.PHONY: server
server:
$(VIRTUAL_ENV)/bin/python3 manage.py runserver 8003
.PHONY: watch
watch:
trap 'kill %1' KILL; \
npm run watch & \
$(VIRTUAL_ENV)/bin/python3 manage.py runserver 8003
.PHONY: background
background:
$(VIRTUAL_ENV)/bin/python3 manage.py process_tasks
.PHONY: test
test:
$(VIRTUAL_ENV)/bin/py.test --reuse-db
npm run testNoCov
.PHONY: pytest
pytest:
$(VIRTUAL_ENV)/bin/py.test --reuse-db
.PHONY: pytest-lastfailed
pytest-lastfailed:
$(VIRTUAL_ENV)/bin/py.test --reuse-db --last-failed
.PHONY: pytest-clean
pytest-clean:
if [ -f test_db.sqlite3 ]; then rm test_db.sqlite3; fi
$(VIRTUAL_ENV)/bin/py.test
.PHONY: jstest
jstest:
npm run test
.PHONY: jstest-nocov
jstest-nocov:
npm run testNoCov
.PHONY: jstest-debug
jstest-debug:
npm run testDebug
.PHONY: jstest-updateSnapshots
jstest-updateSnapshots:
npm run updateSnapshots
.PHONY: coverage
coverage:
$(VIRTUAL_ENV)/bin/py.test --reuse-db --cov --cov-report=html
.PHONY: lint
lint:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/isort --diff -c $(SOURCE_DIRS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(SOURCE_DIRS) --exclude migrations,settings || EXIT_STATUS=$$?; \
npm run lint || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
.PHONY: lint-quick
lint-quick:
EXIT_STATUS=0; \
npm run lint-staged || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/python manage.py makemigrations --dry-run --check --noinput || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
.PHONY: lint-js-fix
lint-js-fix:
EXIT_STATUS=0; \
npm run lint-fix || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
# Use with caution, the automatic fixing might produce bad results
.PHONY: lint-html-fix
lint-html-fix:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/djlint $(ARGUMENTS) --reformat --profile=django || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
.PHONY: lint-html-files
lint-html-files:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/djlint $(ARGUMENTS) --profile=django --ignore=H030,H031,T002 || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
.PHONY: lint-python-files
lint-python-files:
EXIT_STATUS=0; \
$(VIRTUAL_ENV)/bin/black $(ARGUMENTS) || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/isort $(ARGUMENTS) --filter-files || EXIT_STATUS=$$?; \
$(VIRTUAL_ENV)/bin/flake8 $(ARGUMENTS) || EXIT_STATUS=$$?; \
exit $${EXIT_STATUS}
.PHONY: po
po:
$(VIRTUAL_ENV)/bin/python manage.py makemessages --all --no-obsolete -d django --extension html,email,py --ignore '$(CURDIR)/node_modules/adhocracy4/adhocracy4/*'
$(VIRTUAL_ENV)/bin/python manage.py makemessages --all --no-obsolete -d djangojs --ignore '$(VIRTUAL_ENV)/*' --ignore '$(CURDIR)/node_modules/dsgvo-video-embed/dist/*'
$(foreach file, $(wildcard locale/*/LC_MESSAGES/django*.po), \
$(SED) -i 's%#: .*/adhocracy4%#: adhocracy4%' $(file);)
$(foreach file, $(wildcard locale/*/LC_MESSAGES/django*.po), \
$(SED) -i 's%#: .*/dsgvo-video-embed/js%#: dsgvo-video-embed/js%' $(file);)
msgen locale/en_GB/LC_MESSAGES/django.po -o locale/en_GB/LC_MESSAGES/django.po
msgen locale/en_GB/LC_MESSAGES/djangojs.po -o locale/en_GB/LC_MESSAGES/djangojs.po
.PHONY: mo
mo:
$(VIRTUAL_ENV)/bin/python manage.py compilemessages
.PHONY: release
release: export DJANGO_SETTINGS_MODULE ?= meinberlin.config.settings.build
release:
npm install --silent
npm run build:prod
$(VIRTUAL_ENV)/bin/python3 -m pip install -r requirements.txt -q
$(VIRTUAL_ENV)/bin/python3 manage.py compilemessages -v0
$(VIRTUAL_ENV)/bin/python3 manage.py collectstatic --noinput -v0
.PHONY: postgres-start
start-postgres:
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/pg_ctl start
.PHONY: postgres-stop
stop-postgres:
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/pg_ctl stop
.PHONY: postgres-create
create-postgres:
if [ -d "pgsql" ]; then \
echo "postgresql has already been initialized"; \
else \
sudo install -d -m 774 -o postgres -g $(USER) pgsql; \
sudo -u postgres /usr/lib/postgresql/12/bin/initdb pgsql; \
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/pg_ctl start; \
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/createuser -s django; \
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/createdb -O django django; \
sudo -u postgres PGDATA=pgsql PGPORT=5555 /usr/lib/postgresql/12/bin/pg_ctl stop; \
fi
.PHONY: local-a4
local-a4:
if [ -d "../adhocracy4" ]; then \
$(VIRTUAL_ENV)/bin/python -m pip install --upgrade ../adhocracy4; \
$(VIRTUAL_ENV)/bin/python manage.py migrate; \
npm link ../adhocracy4; \
fi
.PHONY: celery-worker-start
celery-worker-start:
$(VIRTUAL_ENV)/bin/celery --app meinberlin worker --loglevel INFO
.PHONY: celery-worker-status
celery-worker-status:
$(VIRTUAL_ENV)/bin/celery --app meinberlin inspect registered
.PHONY: celery-worker-dummy-task
celery-worker-dummy-task:
$(VIRTUAL_ENV)/bin/celery --app meinberlin call dummy_task | awk '{print "celery-task-meta-"$$0}' | xargs redis-cli get | python3 -m json.tool
.PHONY: celery-beat
celery-beat:
$(VIRTUAL_ENV)/bin/celery --app meinberlin beat --loglevel INFO -S django