-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
200 lines (157 loc) · 5.62 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
ifdef CIRCLECI
RUN := poetry run
else ifdef HEROKU_APP_NAME
SKIP_INSTALL := true
else
RUN := poetry run
endif
.PHONY: all
all: check test ## CI | Run all validation targets
.PHONY: dev
dev: install ## CI | Rerun all validation targests in a loop
@ rm -rf $(FAILURES)
$(RUN) sniffer
# SYSTEM DEPENDENCIES #########################################################
.PHONY: bootstrap
bootstrap: ## Attempt to install system dependencies
asdf plugin add python || asdf plugin update python
asdf plugin add poetry || asdf plugin update poetry
asdf install
.PHONY: doctor
doctor: ## Check for required system dependencies
bin/verchew-wrapper --exit-code
.envrc:
echo export SECRET_KEY=local >> $@
echo export DATABASE_URL=postgresql://localhost/ballotbuddies_dev >> $@
echo export REDIS_URL=redis://127.0.0.1:6379/0 >> $@
echo >> $@
echo export MANDRILL_API_KEY=??? >> $@
echo export GOOGLE_OAUTH_CLIENT_ID= >> $@
echo export GOOGLE_OAUTH_CLIENT_SECRET= >> $@
echo export GOOGLE_OAUTH_DISABLED=false >> $@
echo >> $@
echo export ELECTIONS_HOST=https://michiganelections.io >> $@
echo export PREVIEW_HOST=https://share.michiganelections.io >> $@
echo export [email protected],First,Last,YYYY-MM-DD,ZIP/[email protected],Rosalynn,Bliss,1975-08-03,49503 >> $@
echo #export TODAY=now >> @
- direnv allow
# PROJECT DEPENDENCIES ########################################################
VIRTUAL_ENV ?= .venv
BACKEND_DEPENDENCIES = $(VIRTUAL_ENV)/.poetry-$(shell bin/checksum pyproject.toml poetry.lock)
.PHONY: install
ifndef SKIP_INSTALL
install: $(BACKEND_DEPENDENCIES) ## Install project dependencies
endif
$(BACKEND_DEPENDENCIES): poetry.lock
@ rm -rf $(VIRTUAL_ENV)/.poetry-*
@ rm -rf ~/Library/Preferences/pypoetry
@ poetry config virtualenvs.in-project true
poetry install
@ mkdir -p staticfiles
@ touch $@
ifndef CI
poetry.lock: pyproject.toml
poetry lock --no-update
@ touch $@
endif
.PHONY: clean
clean: ## Delete virtual environment and temporary files
rm -rf .cache .coverage $(VIRTUAL_ENV) htmlcov staticfiles
# RUNTIME DEPENDENCIES ########################################################
.PHONY: migrations
migrations: install ## Database | Generate database migrations
$(RUN) python manage.py makemigrations
.PHONY: migrate
migrate: install ## Database | Run database migrations
$(RUN) python manage.py migrate
.PHONY: data
data: install migrate ## Database | Seed data for manual testing
$(RUN) python manage.py gendata $(TEST_VOTERS)
.PHONY: reset
reset: install ## Database | Create a new database, migrate, and seed it
- dropdb ballotbuddies_dev
- createdb ballotbuddies_dev
make data
# VALIDATION TARGETS ##########################################################
PYTHON_PACKAGES := config ballotbuddies
FAILURES := .cache/pytest/v/cache/lastfailed
.PHONY: check
check: check-backend ## Run static analysis
.PHONY: format
format: format-backend
.PHONY: check-backend
check-backend: install format-backend
$(RUN) mypy $(PYTHON_PACKAGES) tests
$(RUN) pylint $(PYTHON_PACKAGES) tests --rcfile=.pylint.ini
format-backend: install
$(RUN) isort $(PYTHON_PACKAGES) tests
$(RUN) black $(PYTHON_PACKAGES) tests
ifdef DISABLE_COVERAGE
PYTEST_OPTIONS := --no-cov --disable-warnings
endif
.PHONY: test
test: test-backend ## Run all tests
.PHONY: test-backend
test-backend: test-backend-all
ifdef COVERALLS_REPO_TOKEN
poetry run coveralls
endif
.PHONY: test-backend-unit
test-backend-unit: install
@ ( mv $(FAILURES) $(FAILURES).bak || true ) > /dev/null 2>&1
$(RUN) pytest $(PYTHON_PACKAGES) tests/unit -m "not django_db" $(PYTEST_OPTIONS)
@ ( mv $(FAILURES).bak $(FAILURES) || true ) > /dev/null 2>&1
ifndef DISABLE_COVERAGE
$(RUN) coveragespace update unit
endif
.PHONY: test-backend-integration
test-backend-integration: install
@ if test -e $(FAILURES); then $(RUN) pytest tests/integration --last-failed; fi
@ rm -rf $(FAILURES)
$(RUN) pytest tests/integration $(PYTEST_OPTIONS)
$(RUN) coveragespace update integration
.PHONY: test-backend-all
test-backend-all: install
@ if test -e $(FAILURES); then $(RUN) pytest $(PYTHON_PACKAGES) tests/unit tests/integration --last-failed; fi
@ rm -rf $(FAILURES)
$(RUN) pytest $(PYTHON_PACKAGES) tests/unit tests/integration $(PYTEST_OPTIONS)
$(RUN) coveragespace update overall
.PHONY: test-system
test-system: install
$(RUN) honcho start --procfile=tests/system/Procfile --env=tests/system/.env
# SERVER TARGETS ##############################################################
HONCHO := .venv/bin/honcho
.PHONY: run
run: .envrc install migrate ## Run the applicaiton
$(RUN) python manage.py runserver $${PORT:-8000}
.PHONY: run/all
run/all: .envrc install
$(HONCHO) start --procfile=Procfile.dev
.PHONY: run/production
run/production: .envrc install
poetry run python manage.py collectstatic --no-input
poetry run heroku local release
HEROKU_APP_NAME=local poetry run heroku local web --port=$${PORT:-8000}
# RELEASE TARGETS #############################################################
.PHONY: build
build: install
.PHONY: deploy
deploy:
@ echo
git diff --exit-code
heroku git:remote -a ballotbuddies-staging
@ echo
git push heroku main
.PHONY: promote
promote: install
@ echo
TEST_SITE=https://staging-app.michiganelections.io $(RUN) pytest tests/system --cache-clear
@ echo
heroku pipelines:promote --app ballotbuddies-staging --to ballotbuddies
@ echo
TEST_SITE=https://app.michiganelections.io $(RUN) pytest tests/system
# HELP ########################################################################
.PHONY: help
help: install
@ grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help