-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
186 lines (133 loc) · 5.27 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
SHELL := /bin/bash
APPLICATION_NAME="Leaving service"
.PHONY: setup
help: # List commands and their descriptions
@grep -E '^[a-zA-Z0-9_-]+: # .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ": # "; printf "\n\033[93;01m%-30s %-30s\033[0m\n\n", "Command", "Description"}; {split($$1,a,":"); printf "\033[96m%-30s\033[0m \033[92m%s\033[0m\n", a[1], $$2}'
build: # Run docker-compose build
docker compose build
npm-build: # Install and build npm packages
npm install
npm run build
up: # Start the project
docker compose up
up-detached: # Start the project in a detached state
docker compose up -d --wait
down: # Stop the project
docker compose down
# Run a command in a new container
run = docker compose run --rm
# Run a command in a new container without starting linked services
run-no-deps = $(run) --no-deps
# Run a command in an existing container
exec = docker compose exec
# Run on existing container if available otherwise a new one
leavers := ${if $(shell docker ps -q -f name=leavers),$(exec) leavers,$(run) leavers}
db := ${if $(shell docker ps -q -f name=db),$(exec) db,$(run) db}
manage = python manage.py
# Run poetry if it is installed, otherwise run it in the leavers container
POETRY := $(shell command -v poetry 2> /dev/null)
ifdef POETRY
poetry = poetry --quiet
else
poetry = $(leavers) poetry --quiet
endif
setup: # Set up the project from scratch
make npm-build
make down
make up-detached
$(leavers) $(manage) createcachetable
$(leavers) $(manage) migrate
$(leavers) $(manage) collectstatic --no-input
$(leavers) $(manage) initialise_staff_index
$(leavers) $(manage) create_test_users
$(leavers) $(manage) seed_employee_ids
$(leavers) $(manage) update_staff_index
$(leavers) $(manage) set_permissions
$(leavers) $(manage) create_test_users
make up
check-fixme: # Run check-fixme
! git --no-pager grep -rni fixme -- ':!./makefile' ':!./.circleci/config.yml' ':!./.github/workflows/ci.yml'
migrate: # Run migrations
$(leavers) $(manage) migrate
migrations: # Create needed migrations
$(leavers) $(manage) makemigrations
empty-migration: # Create an empty migration `make empty-migration app=app_name name=migration_name`
$(leavers) $(manage) makemigrations $(app) --empty --name=$(name)
checkmigrations: # Check for missing migrations
$(run-no-deps) leavers $(manage) makemigrations --check
compilescss: # Compile SCSS into CSS
npm run css:build
shell: # Run a Django shell
$(leavers) $(manage) shell_plus
flake8: # Run flake8
$(poetry) run flake8 $(file)
black: # Run black
$(poetry) run black .
check-black: # Run check-black
$(poetry) run black . --check
isort: # Run isort
$(poetry) run isort .
check-isort: # Run check-isort
$(poetry) run isort . --check
djlint: # Run djlint
$(poetry) run djlint . --reformat --format-css --format-js
check-djlint: # Run check-djlint
$(poetry) run djlint . --check
check: # Run formatters to see if there are any errors
make flake8
make check-black
make check-isort
make check-djlint
fix: # Run formatters to fix any issues that can be fixed automatically
make flake8
make black
make isort
make djlint
mypy: # Run mypy
$(leavers) mypy .
collectstatic: # Run Django collectstatic
$(leavers) $(manage) collectstatic
bash: # Start a bash session on the application container
$(leavers) bash
pytest: # Run pytest
$(leavers) pytest --cov --cov-report html -raP --capture=sys -n 4
test: # Run tests
$(leavers) pytest --disable-warnings --reuse-db $(test)
test-fresh: # Run tests with a fresh database
$(leavers) pytest --disable-warnings --create-db --reuse-db $(test)
view-coverage: # View coverage in new tab -> htmlcov/index.html
python -m webbrowser -t htmlcov/index.html
superuser: # Create a superuser
$(leavers) $(manage) createsuperuser
test-users: # Create test users
$(leavers) $(manage) create_test_users
seed-employee-ids: # Seed employee IDs
$(leavers) $(manage) seed_employee_ids
model-graphs: # Generate model graphs at jml_data_model.png
$(leavers) $(manage) graph_models -a -g -o jml_data_model.png
ingest-activity-stream: # Ingest activity stream
$(leavers) $(manage) ingest_activity_stream --limit=10
serve-docs: # Serve mkdocs
$(poetry) run mkdocs serve -a localhost:8000
staff-index: # Ingest staff data
$(leavers) $(manage) ingest_staff_data --skip-ingest-staff-records --skip-service-now
detect-secrets-init: # Initialise the detect-secrets for the project
$(poetry) run detect-secrets scan > .secrets.baseline
detect-secrets-scan: # detect-secrets scan for the project
$(poetry) run detect-secrets scan --baseline .secrets.baseline
detect-secrets-audit: # detect-secrets audit for the project
$(poetry) run detect-secrets audit --baseline .secrets.baseline
poetry-update: # Run poetry update
$(poetry) update
# DB
db-shell: # Open the database container postgres shell
$(db) psql -U postgres
db-reset: # Reset the database
docker-compose stop db
docker-compose rm -f db
docker-compose up -d db
DUMP_NAME = local
db-dump: # Dump the current database, use `DUMP_NAME` to change the name of the dump
@PGPASSWORD='postgres' pg_dump postgres -U postgres -h localhost -p 5433 -O -x -c -f ./.dumps/$(DUMP_NAME).dump
db-from-dump: # Load a dumped database, use `DUMP_NAME` to change the name of the dump
@PGPASSWORD='postgres' psql -h localhost -U postgres postgres -p 5433 -f ./.dumps/$(DUMP_NAME).dump