/
Makefile
355 lines (315 loc) · 11 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
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
ifndef APPLICATION_CONFIG
# Determine which .env file to use
ifneq ("$(wildcard .env.local)", "")
include .env.local
else
include .env
endif
endif
# Define used JWT keys paths and passphrase
JWT_PUBLIC_KEY=$$(echo | jq -r .JWT_PUBLIC_KEY ${APPLICATION_CONFIG})
JWT_SECRET_KEY=$$(echo | jq -r .JWT_SECRET_KEY ${APPLICATION_CONFIG})
JWT_PASSPHRASE=$$(echo | jq -r .JWT_PASSPHRASE ${APPLICATION_CONFIG})
ifdef GITHUB_WORKFLOW
INSIDE_DOCKER = 1
else ifneq ("$(wildcard /.dockerenv)", "")
INSIDE_DOCKER = 1
else
INSIDE_DOCKER = 0
endif
# Global variables that we're using
HOST_UID := $(shell id -u)
HOST_GID := $(shell id -g)
CONSOLE := $(shell which bin/console)
OPENSSL_BIN := $(shell which openssl)
PHPDBG := $(shell which phpdbg)
COMPOSER_BIN := $(shell which composer)
WARNING_HOST = @printf "\033[31mThis command cannot be run inside docker container!\033[39m\n"
WARNING_DOCKER = @printf "\033[31mThis command must be run inside docker container!\nUse 'make bash' command to get shell inside container.\033[39m\n"
.DEFAULT_GOAL := help
help:
@grep -E '^[a-zA-Z-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "[32m%-27s[0m %s\n", $$1, $$2}'
configuration: ## Prints out application current configuration
ifeq ($(INSIDE_DOCKER), 1)
@echo | jq -r . ${APPLICATION_CONFIG}
else
$(WARNING_DOCKER)
endif
cache-clear: ## Clears the cache
ifdef CONSOLE
@bin/console cache:clear --no-warmup
else
@rm -rf var/cache/*
endif
cache-warmup: cache-clear ## Warms up an empty cache
ifdef CONSOLE
@bin/console cache:warmup
else
@printf "Cannot warm up the cache (needs symfony/console).\n"
endif
generate-jwt-keys: ## Generates JWT auth keys
ifndef OPENSSL_BIN
@printf "\033[31mUnable to generate keys (needs OpenSSL)\033[39m\n"
else ifeq ($(INSIDE_DOCKER), 0)
$(WARNING_DOCKER)
else
@echo "\033[32mGenerating RSA keys for JWT\033[39m"
@mkdir -p config/jwt
@rm -f ${JWT_SECRET_KEY}
@rm -f ${JWT_PUBLIC_KEY}
@openssl genrsa -passout pass:${JWT_PASSPHRASE} -out ${JWT_SECRET_KEY} -aes256 4096
@openssl rsa -passin pass:${JWT_PASSPHRASE} -pubout -in ${JWT_SECRET_KEY} -out ${JWT_PUBLIC_KEY}
@chmod 644 ${JWT_SECRET_KEY}
@chmod 644 ${JWT_PUBLIC_KEY}
@echo "\033[32mRSA key pair successfully generated\033[39m"
endif
run-tests: ## Runs all tests via phpunit (Uses phpdbg if that is installed)
ifndef PHPDBG
@${MAKE} run-tests-php
else
@${MAKE} run-tests-phpdbg
endif
run-tests-fastest: ## Runs all test via fastest (Uses phpdbg if that is installed)
ifndef PHPDBG
@${MAKE} run-tests-fastest-php
else
@${MAKE} run-tests-fastest-phpdbg
endif
run-tests-php: ## Runs all tests via phpunit (pure PHP)
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning test with PhpUnit in single thread (pure PHP)\033[39m"
@php ./vendor/bin/phpunit --version
@rm -rf build/logs
@mkdir -p build/logs
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@./vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/junit.xml
else
$(WARNING_DOCKER)
endif
run-tests-phpdbg: ## Runs all tests via phpunit (phpdbg)
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning test with PhpUnit in single thread (phpdbg)\033[39m"
@php ./vendor/bin/phpunit --version
@rm -rf build/logs
@mkdir -p build/logs
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@phpdbg -qrr ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/junit.xml
else
$(WARNING_DOCKER)
endif
run-tests-fastest-php: ## Runs all test via fastest (pure PHP)
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning tests with liuggio/fastest + PhpUnit in multiple threads (pure PHP)\033[39m"
@rm -rf build/fastest
@mkdir -p build/fastest
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@find tests/ -name "*Test.php" | php ./vendor/bin/fastest -v -p 8 -o -b "php ./tests/bootstrap_fastest.php" "php ./vendor/bin/phpunit {} -c phpunit.fastest.xml --coverage-php build/fastest/{n}.cov --log-junit build/fastest/{n}.xml";
else
$(WARNING_DOCKER)
endif
run-tests-fastest-phpdbg: ## Runs all test via fastest (phpdbg)
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning tests with liuggio/fastest + PhpUnit in multiple threads (phpdbg)\033[39m"
@rm -rf build/fastest
@mkdir -p build/fastest
@rm -rf ./var/cache/test*
@bin/console cache:warmup --env=test
@find tests/ -name "*Test.php" | php ./vendor/bin/fastest -v -p 8 -o -b "php ./tests/bootstrap_fastest.php" "phpdbg -qrr -d memory_limit=4096M ./vendor/bin/phpunit {} -c phpunit.fastest.xml --coverage-php build/fastest/{n}.cov --log-junit build/fastest/{n}.xml";
else
$(WARNING_DOCKER)
endif
report-fastest: ## Creates clover and JUnit xml from fastest run
ifeq ($(INSIDE_DOCKER), 1)
@rm -rf build/logs
@mkdir -p build/logs
@./vendor/bin/phpcov merge ./build/fastest/ --clover=./build/logs/clover.xml --html ./build/report/
@php merge-phpunit-xml.php ./build/fastest/ ./build/logs/junit.xml
else
$(WARNING_DOCKER)
endif
infection: ## Runs Infection to codebase
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning Infection to codebase (pure PHP)\033[39m"
@mkdir -p build/infection
@bin/console cache:clear --env=test
@./vendor/bin/infection --threads=8 --only-covered --show-mutations --test-framework-options="--testsuite=Functional,Integration,Unit"
else
$(WARNING_DOCKER)
endif
phpmetrics: ## Generates PhpMetrics static analysis
ifeq ($(INSIDE_DOCKER), 1)
@mkdir -p build/phpmetrics
@if [ ! -f build/logs/junit.xml ] ; then \
printf "\033[32;49mclover.xml not found running tests...\033[39m\n" ; \
make run-tests or make run-tests-fastests ; \
fi;
@echo "\033[32mRunning PhpMetrics\033[39m"
@php ./vendor/bin/phpmetrics --version
@./vendor/bin/phpmetrics --junit=build/logs/junit.xml --report-html=build/phpmetrics .
else
$(WARNING_DOCKER)
endif
phpcs: ## Runs PHP CodeSniffer
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning PhpCodeSniffer\033[39m"
@php ./vendor/bin/phpcs --version
@php ./vendor/bin/phpcs --standard=PSR2 --colors -p src tests
else
$(WARNING_DOCKER)
endif
ecs: ## Runs The Easiest Way to Use Any Coding Standard
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning EasyCodingStandard\033[39m"
@php ./vendor/bin/ecs --version
@php ./vendor/bin/ecs --clear-cache check src tests
else
$(WARNING_DOCKER)
endif
ecs-fix: ## Runs The Easiest Way to Use Any Coding Standard to fix issues
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning EasyCodingStandard\033[39m"
@php ./vendor/bin/ecs --version
@php ./vendor/bin/ecs --clear-cache --fix check src tests
else
$(WARNING_DOCKER)
endif
phpinsights: ## Runs PHP Insights
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning PHP Insights\033[39m"
@php -d error_reporting=0 ./vendor/bin/phpinsights analyse --no-interaction --min-quality=100 --min-complexity=85 --min-architecture=100 --min-style=100
else
$(WARNING_DOCKER)
endif
psalm: ## Runs Psalm static analysis tool
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning Psalm - A static analysis tool for PHP\033[39m"
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --report=./build/psalm.json
else
$(WARNING_DOCKER)
endif
psalm-shepherd: ## Runs Psalm static analysis tool + report results to shepherd
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning Psalm - A static analysis tool for PHP\033[39m"
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --shepherd --report=./build/psalm.json
else
$(WARNING_DOCKER)
endif
psalm-github: ## Runs Psalm static analysis tool
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning Psalm - A static analysis tool for PHP\033[39m"
@mkdir -p build
@@bin/console cache:clear
@php ./vendor/bin/psalm --version
@php ./vendor/bin/psalm --no-cache --shepherd --report=./build/psalm.json --output-format=github
else
$(WARNING_DOCKER)
endif
phpstan: ## Runs PHPStan static analysis tool
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mRunning PHPStan - PHP Static Analysis Tool\033[39m"
@@bin/console cache:clear
@./vendor/bin/phpstan --version
@./vendor/bin/phpstan
else
$(WARNING_DOCKER)
endif
lint-configuration: ## Lint current defined `application.json` that it contains valid JSON
ifeq ($(INSIDE_DOCKER), 1)
@php -r "if (!json_decode(file_get_contents('${APPLICATION_CONFIG}'))) { echo \"\033[31mInvalid JSON in configuration file '${APPLICATION_CONFIG}'\033[39m\n\"; exit(1); } else { echo \"\033[32mNo errors in configuration file '${APPLICATION_CONFIG}'\033[39m\n\"; }"
else
$(WARNING_DOCKER)
endif
lint-yaml: ## Lint config YAML files
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mLinting YAML config files\033[39m"
@@bin/console lint:yaml config --parse-tags
else
$(WARNING_DOCKER)
endif
clear-tools: ## Clears all tools depedencies
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mClearing tools dependencies\033[39m"
@find -type d -name vendor | grep tools | xargs rm -rf
@echo "\033[32mremember to run 'make update' command after this\033[39m"
else
$(WARNING_DOCKER)
endif
check-dependencies: ## Checks if any vendor dependency can be updated
ifeq ($(INSIDE_DOCKER), 1)
@echo "\033[32mChecking vendor dependencies\033[39m"
@bin/console check-dependencies
else
$(WARNING_DOCKER)
endif
update: ## Update composer dependencies
ifeq ($(INSIDE_DOCKER), 1)
@php -d memory_limit=-1 /usr/bin/composer update --with-all-dependencies --optimize-autoloader
else
$(WARNING_DOCKER)
endif
update-bin: ## Update composer bin dependencies
ifeq ($(INSIDE_DOCKER), 1)
@php -d memory_limit=-1 $(COMPOSER_BIN) bin all update --no-progress --optimize-autoloader
else
$(WARNING_DOCKER)
endif
install-bin: ## Install composer bin dependencies
ifeq ($(INSIDE_DOCKER), 1)
@php -d memory_limit=-1 $(COMPOSER_BIN) bin all install --no-progress --optimize-autoloader
else
$(WARNING_DOCKER)
endif
bash: ## Get bash inside PHP container
ifeq ($(INSIDE_DOCKER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose exec php bash
endif
start: ## Start application in development mode
ifeq ($(INSIDE_DOCKER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose up
endif
stop: ## Stop application containers
ifeq ($(INSIDE_DOCKER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose down
endif
start-build: ## Start application in development mode and build containers
ifeq ($(INSIDE_DOCKER), 1)
$(WARNING_HOST)
else
@HOST_UID=$(HOST_UID) HOST_GID=$(HOST_GID) docker-compose up --build
endif
local-configuration: ## Create local configuration files
ifeq ($(INSIDE_DOCKER), 1)
@cp /app/.env /app/.env.local
@cp /app/secrets/application.json /app/secrets/application.local.json
@sed -i "s/application\.json/application\.local\.json/g" .env.local
@echo "\033[32mLocal configuration created, just edit your new \`secrets/application.local.json\` file for your needs\033[39m"
else
$(WARNING_DOCKER)
endif
normalize-composer: ## Normalizes `composer.json` content
ifeq ($(INSIDE_DOCKER), 1)
@composer normalize
else
$(WARNING_DOCKER)
endif
phploc: ## Runs `phploc` and create json output
ifeq ($(INSIDE_DOCKER), 1)
@php ./vendor/bin/phploc --log-json=./build/phploc.json ./src
else
$(WARNING_DOCKER)
endif