-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
Makefile
172 lines (140 loc) · 4.48 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
export PYTHONBREAKPOINT=ipdb.set_trace
.PHONY: all
all: doctor format check test ## Run all validation targets
.PHONY: dev
dev: install ## Rerun all validation targests in a loop
@ sleep 2 && touch */__init__.py &
@ poetry run watchmedo shell-command --recursive --pattern="*.py" --command="clear && make test check format SKIP_SLOW=true && echo && echo ✅ && echo" --wait --drop
###############################################################################
# System Dependencies
.PHONY: bootstrap
bootstrap: ## Attempt to install system dependencies
asdf plugin add python || asdf plugin update python
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git || asdf plugin update poetry
asdf install
.PHONY: doctor
doctor: ## Check for required system dependencies
bin/verchew --exit-code
###############################################################################
# Project Dependencies
BACKEND_DEPENDENCIES := .venv/.flag
.PHONY: install
install: $(BACKEND_DEPENDENCIES) ## Install project dependencies
$(BACKEND_DEPENDENCIES): poetry.lock
@ poetry config virtualenvs.in-project true
ifdef CI
poetry install
else
poetry install --extras testing
endif
@ touch $@
ifndef CI
poetry.lock: pyproject.toml
poetry lock --no-update
@ touch $@
endif
site: install
poetry run mkdocs build --strict
sed -i -e 's/http:\/\/localhost:5000/https:\/\/api.memegen.link/g' site/examples/index.html
echo memegen.link > site/CNAME
ifeq ($(CIRCLE_BRANCH),main)
@ echo
git config --global user.name CircleCI
poetry run mkdocs gh-deploy --dirty
endif
.PHONY: clean
clean: clean-tmp
rm -rf .cache .venv site
.PHONY: clean-tmp
clean-tmp:
rm -rf images templates/_custom* templates/*/_* templates/*/*.*.* "templates/<sample>"
.PHONY: clean-all
clean-all: clean
rm -rf app/tests/images
###############################################################################
# Development Tasks
PACKAGES := app scripts
.PHONY: format
format: install
poetry run autoflake --recursive $(PACKAGES) --in-place --remove-all-unused-imports --ignore-init-module-imports
poetry run isort $(PACKAGES)
poetry run black $(PACKAGES)
.PHONY: check
check: install ## Run static analysis
poetry run mypy $(PACKAGES)
.PHONY: test
test: install ## Run all tests
ifdef CI
poetry run pytest --verbose --junit-xml=results/junit.xml
else
@ if test -e .cache/pytest/v/cache/lastfailed; then \
echo "Running failed tests..." && \
poetry run pytest --last-failed --maxfail=1 --no-cov && \
echo "Running all tests..." && \
poetry run pytest --cache-clear; \
else \
echo "Running all tests..." && \
poetry run pytest --new-first --maxfail=1; \
fi
endif
ifdef SKIP_SLOW
poetry run coveragespace update unit
else
poetry run coveragespace update overall
endif
.PHONY: test-fast
test-fast: install
poetry run pytest -m "not slow" --durations=10
.PHONY: test-slow
test-slow: install
poetry run pytest -m slow --durations=0 --durations-min=0.05
.PHONY: run
run: install ## Run the applicaiton
ifdef DEBUG
make clean-tmp
endif
poetry run honcho start --procfile Procfile.dev
###############################################################################
# Delivery Tasks
.PHONY: run-production
run-production: install .env
poetry run heroku local web
.PHONY: compress
compress: clean-tmp
@ for letter in {a..z} ; do \
echo "Optimizing templates starting with $$letter..." ;\
find templates/$$letter* -name '*.jpg' -or -name '*.jpeg' | xargs jpegoptim -m85 --strip-all -q ;\
find templates/$$letter* -name '*.png' | xargs optipng -o7 -quiet ;\
done
.PHONY: deploy
deploy: .envrc
@ echo
git diff --exit-code
heroku git:remote -a memegen-staging
@ echo
git push heroku main
.PHONY: promote
promote: install .envrc
@ echo
SITE=https://staging.memegen.link poetry run pytest scripts/check_deployment.py --verbose --no-cov
@ echo
heroku pipelines:promote --app memegen-staging --to memegen-production
@ echo
sleep 30
@ echo
SITE=https://api.memegen.link poetry run pytest scripts/check_deployment.py --verbose --no-cov
.env:
echo WEB_CONCURRENCY=2 >> $@
echo MAX_REQUESTS=0 >> $@
echo MAX_REQUESTS_JITTER=0 >> $@
.envrc:
echo dotenv >> $@
echo >> $@
echo "export CF_API_KEY=???" >> $@
echo "export REMOTE_TRACKING_URL=???" >> $@
echo "export DEBUG=true" >> $@
# 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