-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathMakefile
More file actions
360 lines (299 loc) · 12 KB
/
Makefile
File metadata and controls
360 lines (299 loc) · 12 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
SHELL=bash
COMPOSE = docker compose
PHP = $(COMPOSE) exec app
PHP_ROOT = $(COMPOSE) exec --user=root app
DB = $(COMPOSE) exec db
CONSOLE = $(PHP) bin/console
INI_DIR = /usr/local/etc/php/custom_conf.d
# Get playwright's version so that the correct docker image is used.
PLAYWRIGHT_VERSION = $(shell $(PHP) jq -r '.packages["node_modules/@playwright/test"].version' package-lock.json)
# Load E2E env files
include tests/e2e/.env
-include tests/e2e/.env.local
# See: https://playwright.dev/docs/docker
PLAYWRIGHT = docker run \
-it \
--rm \
--ipc=host \
--user=$(shell id -u):$(shell id -g) \
-v .:/app \
-w /app \
-p 9323:9323 \
-e E2E_BASE_URL=$(E2E_BASE_URL) \
--add-host host.docker.internal:host-gateway \
mcr.microsoft.com/playwright:v$(PLAYWRIGHT_VERSION)-noble \
npx playwright
# Helper variables
_TITLE := "\033[32m[%s]\033[0m %s\n" # Green text
_ERROR := "\033[31m[%s]\033[0m %s\n" # Red text
##
## This Makefile is used for *local development* only.
## Production or deployment should be handled following GLPI's documentation.
##
## —— General ——————————————————————————————————————————————————————————————————
.DEFAULT_GOAL := help
help: ## Show this help message
@grep -hE '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-25s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
.PHONY: help
install: init-override build up vendor db-install test-db-install ## Install the project
.PHONY: install
## —— Docker ———————————————————————————————————————————————————————————————————
init-override:
@\
if [ ! -f "./docker-compose.override.yaml" ]; then \
printf $(_TITLE) "Project" "Creating \"./docker-compose.override.yaml\" file for Docker Compose" ; \
touch ./docker-compose.override.yaml ; \
fi ;
.PHONY: init-override
build: ## Build the Docker images
@printf $(_TITLE) "Project" "Pulling Docker images" \
@$(COMPOSE) pull
@$(COMPOSE) build --no-cache
.PHONY: build
up: ## Start all containers
@$(COMPOSE) up -d
.PHONY: start
down: ## Stop the containers
@$(COMPOSE) down --remove-orphans
.PHONY: stop
kill: ## Stop the containers and remove the volumes (use with caution)
@$(COMPOSE) kill
@$(COMPOSE) down --volumes --remove-orphans
.PHONY: kill
bash: ## Start a shell inside the php container
@$(PHP) bash
.PHONY: bash
sql: ## Enter the database cli
@$(DB) sh -c 'mariadb --user=$$MARIADB_USER --password=$$MARIADB_PASSWORD $$MARIADB_DATABASE'
.PHONY: sql
## —— GLPI commands ————————————————————————————————————————————————————————————
console: ## Run a console command, example: make console c='glpi:mycommand'
@$(eval c ?=)
@$(CONSOLE) $(c)
.PHONY: console
vendor: c=dependencies install ## Install dependencies
vendor: console
.PHONY: vendor
locales-extract: ## Extract locales
@$(CONSOLE) tools:locales:extract
.PHONY: locales-extract
locales-compile:
@$(CONSOLE) tools:locales:compile
.PHONY: locales-compile
cc: c=cache:clear ## Clear the cache
cc: console
.PHONY: cc
license-headers-check: ## Verify that the license headers is present all files
@$(CONSOLE) tools:licence_headers_check
.PHONY: license-headers-check
license-headers: ## Add the missing license headers in all files
@$(CONSOLE) tools:licence_headers_check --fix
.PHONY: license-headers
## —— Database —————————————————————————————————————————————————————————————————
db-install: ## Install local development's database
@$(CONSOLE) database:install \
-r -f \
--db-host=db \
--db-port=3306 \
--db-name=glpi \
--db-user=root \
--db-password=glpi \
--no-interaction \
--no-telemetry
.PHONY: db-install
db-update: ## Update local development's database
@$(CONSOLE) database:update \
-n \
--allow-unstable \
--force \
--skip-db-checks
.PHONY: db-update
db-dump: ## Dump the database
@mkdir -p ./.dump; \
DUMP_FILE="./.dump/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz"; \
printf $(_TITLE) "db-dump" "Dumping database to $$DUMP_FILE"; \
$(DB) sh -c 'mariadb-dump --user $$MARIADB_USER --password=$$MARIADB_PASSWORD $$MARIADB_DATABASE | gzip' > $$DUMP_FILE; \
printf $(_TITLE) "db-dump" "Database successfully dumped to $$DUMP_FILE"
.PHONY: db-dump
db-restore: ## Drop the database and restores it from a dump file, i.e: make db-restore f=./.dump/dump.sql.gz
@$(eval f ?=)
@if [ -z "$(f)" ]; then \
printf $(_ERROR) "db-restore" "Please provide a file path, i.e: make db-restore f=./.dump/dump.sql.gz"; \
exit 1; \
fi
@printf $(_TITLE) "db-restore" "Dropping and recreating database..."
@$(DB) sh -c 'mariadb --user=$$MARIADB_USER --password=$$MARIADB_PASSWORD -e "DROP DATABASE IF EXISTS \`$$MARIADB_DATABASE\`; CREATE DATABASE \`$$MARIADB_DATABASE\`;"'
@printf $(_TITLE) "db-restore" "Restoring from $(f)"
@gunzip -c $(f) | $(COMPOSE) exec -T db sh -c 'mariadb --user=$$MARIADB_USER --password=$$MARIADB_PASSWORD $$MARIADB_DATABASE'
.PHONY: db-restore
test-db-install: ## Install testing's database
@$(CONSOLE) database:install \
-r -f \
--db-host=db \
--db-port=3306 \
--db-name=glpi_test \
--db-user=root \
--db-password=glpi \
--no-interaction \
--no-telemetry \
--env=testing
.PHONY: test-db-install
test-db-update: ## Update testing's database
@$(CONSOLE) database:update \
-n \
--allow-unstable \
--force \
--skip-db-checks \
--env=testing
.PHONY: test-db-update
test-db-clone: ## Set up DBs for parallel test execution, example: make test-db-clone p=8
@$(eval p ?= 4)
@$(DB) bash -c ' \
for i in $$(seq 2 $(p)); do \
mariadb -u root -pglpi -e "DROP DATABASE IF EXISTS glpi_test_$$i"; \
mariadb -u root -pglpi -e "CREATE DATABASE glpi_test_$$i CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; \
mariadb-dump -u root -pglpi --single-transaction glpi_test | mariadb -u root -pglpi glpi_test_$$i; \
echo "Database glpi_test_$$i created and populated"; \
done \
'
.PHONY: test-db-clone
e2e-db-install: ## Install e2e testing's database
@$(CONSOLE) database:install \
-r -f \
--db-host=db \
--db-port=3306 \
--db-name=glpi_e2e \
--db-user=root \
--db-password=glpi \
--no-interaction \
--no-telemetry \
--env=e2e_testing
.PHONY: e2e-db-install
e2e-db-update: ## Update e2e testing's database
@$(CONSOLE) database:update \
-n \
--allow-unstable \
--force \
--skip-db-checks \
--env=e2e_testing
.PHONY: e2e-db-update
## —— Dependencies —————————————————————————————————————————————————————————————
composer: ## Run a composer command, example: make composer c='require mypackage/package'
@$(eval c ?=)
@$(PHP) composer $(c)
.PHONY: composer
npm: ## Run a npm command, example: make npm c='install mypackage/package'
@$(eval c ?=)
@$(PHP) npm $(c)
.PHONY: npm
## —— Testing and static analysis ——————————————————————————————————————————————
phpunit: ## Run phpunits tests, example: make phpunit c='tests/functional/Glpi/MySpecificTest.php'
@$(eval c ?=)
@$(PHP) php vendor/bin/phpunit $(c)
.PHONY: phpunit
paratest: ## Run paratest, example: make paratest p=8
@$(eval p ?= 4)
@$(eval c ?=)
@$(PHP) php vendor/bin/paratest -p $(p) --exclude-group "single-thread" $(c)
.PHONY: paratest
phpstan: ## Run phpstan
@$(eval c ?=)
@$(PHP) php vendor/bin/phpstan --memory-limit=1G $(c)
.PHONY: phpstan
phpstan-generate-baseline: c=--generate-baseline=.phpstan-baseline.php analyze ## Generate phpstan baseline file
phpstan-generate-baseline: phpstan
.PHONY: phpstan-generate-baseline
parallel-lint:
@$(eval c ?=.)
$(PHP) php vendor/bin/parallel-lint \
--show-deprecated \
--colors \
--exclude ./files/ \
--exclude ./marketplace/ \
--exclude ./plugins/ \
--exclude ./vendor/ \
$(c)
.PHONY: parallel-lint
psalm: ## Run psalm analysis
@$(eval c ?=)
@$(PHP) php vendor/bin/psalm $(c)
.PHONY: psalm
rector-check: ## Run rector with dry run
@$(eval c ?=)
@$(PHP) php vendor/bin/rector --dry-run $(c)
.PHONY: rector-check
rector: ## Run rector
@$(eval c ?=)
@$(PHP) php vendor/bin/rector $(c)
.PHONY: rector
cypress: ## Run cypress tests
@$(eval c ?=)
@$(CONSOLE) config:set url_base http://localhost:8080 --env=testing
@$(PHP) bash -c 'node_modules/.bin/cypress verify || node_modules/.bin/cypress install'
@$(PHP) node_modules/.bin/cypress run --project tests $(c)
.PHONY: cypress
cypress-open: ## Open cypress UI
@$(eval c ?=)
@$(CONSOLE) config:set url_base http://localhost:8080 --env=testing
@$(PHP) bash -c 'node_modules/.bin/cypress verify || node_modules/.bin/cypress install'
@$(PHP) node_modules/.bin/cypress open --e2e --browser electron --project tests $(c)
.PHONY: cypress-open
playwright: ## Run playwright tests
@$(eval c ?=)
@$(CONSOLE) config:set url_base $(E2E_BASE_URL) --env=e2e_testing
@$(PLAYWRIGHT) test $(c)
.PHONY: playwright
playwright-report: ## View playwright reports
@$(eval c ?=)
@$(CONSOLE) config:set url_base $(E2E_BASE_URL) --env=e2e_testing
@$(PLAYWRIGHT) show-report tests/e2e/results --host=0.0.0.0 $(c)
.PHONY: playwright-report
playwright-ui: ## Open playwright's UI mode
@$(eval c ?=)
@$(PLAYWRIGHT) test --ui-host=0.0.0.0 --ui-port=9323 $(c)
.PHONY: playwright-ui
## —— Coding standards —————————————————————————————————————————————————————————
phpcsfixer-check: ## Check for php coding standards issues
@$(PHP) vendor/bin/php-cs-fixer check --diff -vvv
.PHONY: phpcsfixer-check
phpcsfixer: ## Fix php coding standards issues
@$(PHP) vendor/bin/php-cs-fixer fix
.PHONY: phpcsfixer
## —— Linters ——————————————————————————————————————————————————————————————————
lint: lint-php lint-scss lint-twig lint-js lint-playwright ## Run all linters
.PHONY: lint
lint-php: ## Run the php linter script
@$(PHP) .github/actions/lint_php-lint.sh
.PHONY: lint-php
lint-scss: ## Run the scss linter script
@$(PHP) .github/actions/lint_scss-lint.sh
.PHONY: lint-scss
lint-twig: ## Run the twig linter script
@$(PHP) .github/actions/lint_twig-lint.sh
.PHONY: lint-twig
lint-js: ## Run the js linter script
@$(PHP) .github/actions/lint_js-lint.sh
.PHONY: lint-js
lint-playwright: ## Run the ts linter script
@$(PHP) npx tsc -p tsconfig.json --noEmit
.PHONY: lint-playwright
## —— Xdebug ———————————————————————————————————————————————————————————————————
XDEBUG_FILE = xdebug-mode.ini
xdebug-off: ## Disable xdebug
@$(PHP_ROOT) bash -c 'echo "xdebug.mode=off" > $(INI_DIR)/$(XDEBUG_FILE)'
@$(PHP_ROOT) service apache2 reload
.PHONY: xdebug-off
xdebug-on: ## Enable xdebug
@$(PHP_ROOT) bash -c 'echo "xdebug.mode=debug" > $(INI_DIR)/$(XDEBUG_FILE)'
@$(PHP_ROOT) bash -c 'echo "xdebug.start_with_request=1" >> $(INI_DIR)/$(XDEBUG_FILE)'
@$(PHP_ROOT) service apache2 reload
.PHONY: xdebug-on
xdebug-profile: ## Enable xdebug performance profiling
@$(PHP_ROOT) bash -c 'echo "xdebug.mode=profile" > $(INI_DIR)/$(XDEBUG_FILE)'
@$(PHP_ROOT) bash -c 'echo "xdebug.start_with_request=1" >> $(INI_DIR)/$(XDEBUG_FILE)'
@$(PHP_ROOT) service apache2 reload
.PHONY: xdebug-profile
xdebug-reset: ## Reset xdebug config by deleting custom ini file
@$(PHP_ROOT) bash -c 'test -e $(INI_DIR)/$(XDEBUG_FILE) && rm $(INI_DIR)/$(XDEBUG_FILE) || true'
@$(PHP_ROOT) service apache2 reload
.PHONY: xdebug-reset