-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
200 lines (154 loc) · 6.25 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
DESIGN_SYSTEM_VERSION=`cat .design-system-version`
.DEFAULT_GOAL := all
.EXPORT_ALL_VARIABLES:
# Default to development config if DJANGO_SETTINGS_MODULE is not set
DJANGO_SETTINGS_MODULE ?= cms.settings.dev
.PHONY: all
all: ## Show the available make targets.
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@grep -E '^[0-9a-zA-Z_-]+:.*? .*$$' \
$(MAKEFILE_LIST) \
| awk 'BEGIN { FS=":.*?## " }; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' \
| sort
.PHONY: clean
clean: ## Clean the temporary files.
rm -rf .mypy_cache
rm -rf .coverage
rm -rf .ruff_cache
rm -rf megalinter-reports
.PHONY: format
format: format-py format-html format-frontend ## Format the code.
.PHONY: format-py
format-py: ## Format the Python code
poetry run ruff format .
poetry run ruff check . --fix
.PHONY: format-html
format-html: ## Format the HTML code
find cms/ -name '*.html' | xargs poetry run djhtml
.PHONY: format-frontend
format-frontend: ## Format front-end files (CSS, JS, YAML, MD)
npm run format
.PHONY: lint
lint: lint-py lint-html lint-frontend lint-migrations ## Run all linters (python, html, front-end, migrations)
.PHONY: lint-py
lint-py: ## Run all Python linters (ruff/pylint/mypy).
poetry run ruff check .
poetry run ruff format --check .
find . -type f -name "*.py" | xargs poetry run pylint --reports=n --output-format=colorized --rcfile=.pylintrc --django-settings-module=cms.settings.production -j 0
make mypy
.PHONY: lint-html
lint-html: ## Run HTML Linters
find cms/ -name '*.html' | xargs poetry run djhtml --check
.PHONY: lint-frontend
lint-frontend: ## Run front-end linters
npm run lint
.PHONY: lint-migrations
lint-migrations: ## Run django-migration-linter
poetry run python manage.py lintmigrations --quiet ignore ok
.PHONY: test
test: ## Run the tests and check coverage.
poetry run coverage erase
poetry run coverage run ./manage.py test --parallel --settings=cms.settings.test --shuffle
poetry run coverage combine
poetry run coverage report --fail-under=90
.PHONY: mypy
mypy: ## Run mypy.
poetry run mypy cms
.PHONY: install
install: ## Install the dependencies excluding dev.
poetry install --only main --no-root
.PHONY: install-dev
install-dev: ## Install the dependencies including dev.
poetry install --no-root
.PHONY: megalint
megalint: ## Run the mega-linter.
docker run --platform linux/amd64 --rm \
-v /var/run/docker.sock:/var/run/docker.sock:rw \
-v $(shell pwd):/tmp/lint:rw \
oxsecurity/megalinter-cupcake:v8
.PHONY: load-design-system-templates
load-design-system-templates: ## Load the design system templates
./scripts/load-design-system-templates.sh $(DESIGN_SYSTEM_VERSION)
# Docker and docker compose make commands
.PHONY: compose-build
compose-build: load-design-system-templates ## Build the main application's Docker container
docker compose build
.PHONY: compose-pull
compose-pull: ## Pull Docker containers
docker compose pull
.PHONY: compose-up
compose-up: ## Start Docker containers
docker compose up --detach
.PHONY: compose-down
compose-down: ## Stop and remove Docker containers and networks
docker compose down --volumes
.PHONY: compose-stop
compose-stop: ## Stop Docker containers
docker compose stop
.PHONY: docker-shell
docker-shell: ## SSH into the main application's Docker container
docker compose exec web bash
# Docker and docker compose make commands for the dev containers
.PHONY: compose-dev-pull
compose-dev-pull: ## Pull dev Docker containers
docker compose -f docker-compose-dev.yml pull
.PHONY: compose-dev-up
compose-dev-up: ## Start dev Docker containers
docker compose -f docker-compose-dev.yml up --detach
.PHONY: compose-dev-stop
compose-dev-stop: ## Stop dev Docker containers
docker compose -f docker-compose-dev.yml stop
.PHONY: compose-dev-down
compose-dev-down: ## Stop and remove dev Docker containers and networks
docker compose -f docker-compose-dev.yml down
# Django make command
.PHONY: makemigrations-check
makemigrations-check: ## Check whether there are new migrations to be generated
poetry run python ./manage.py makemigrations --check
.PHONY: makemigrations
makemigrations: ## Generate new migrations
poetry run python ./manage.py makemigrations
.PHONY: collectstatic
collectstatic: ## Collect static files from all Django apps
poetry run python ./manage.py collectstatic --verbosity 0 --noinput --clear
.PHONY: migrate
migrate: ## Apply the database migrations
poetry run python ./manage.py migrate
.PHONY: createsuperuser
createsuperuser: ## Create a super user with a default username and password
poetry run python ./manage.py shell -c "from cms.users.models import User;(not User.objects.filter(username='admin').exists()) and User.objects.create_superuser('admin', '[email protected]', 'changeme')"
.PHONY: runserver
runserver: ## Run the Django application locally
poetry run python ./manage.py runserver 0:8000
.PHONY: dev-init
dev-init: load-design-system-templates collectstatic makemigrations migrate createsuperuser ## Run the pre-run setup scripts
.PHONY: functional-tests-up
functional-tests-up: ## Start the functional tests docker compose dependencies
docker compose -f functional_tests/docker-compose.yml up -d
.PHONY: functional-tests-dev-up
functional-tests-dev-up: ## Start the functional tests docker compose dependencies and dev app
docker compose -f functional_tests/docker-compose-dev.yml up -d
.PHONY: functional-tests-down
functional-tests-down: ## Stop the functional tests docker compose dependencies (and dev app if running)
docker compose -f functional_tests/docker-compose-dev.yml down
.PHONY: functional-tests-run
functional-tests-run: load-design-system-templates collectstatic ## Only run the functional tests (dependencies must be run separately)
# Run migrations to work around Django bug (#35967)
poetry run ./manage.py migrate --noinput --settings cms.settings.functional_test
poetry run behave functional_tests
.PHONY: functional-tests
functional-tests: functional-tests-up functional-tests-run functional-tests-down ## Run the functional tests with dependencies (all in one)
.PHONY: playwright-install
playwright-install: ## Install Playwright dependencies
poetry run playwright install --with-deps
# Aliases
.PHONY: start
start: compose-up
.PHONY: stop
stop: compose-stop
.PHONY: shell
shell: docker-shell
.PHONY: run
run: runserver