/
Makefile
246 lines (184 loc) · 10.3 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
# —— Inspired by ———————————————————————————————————————————————————————————————
# https://www.strangebuzz.com/fr/snippets/le-makefile-parfait-pour-symfony
# who was inspired by
# http://fabien.potencier.org/symfony4-best-practices.html
# https://speakerdeck.com/mykiwi/outils-pour-ameliorer-la-vie-des-developpeurs-symfony?slide=47
# https://blog.theodo.fr/2018/05/why-you-need-a-makefile-on-your-project/
# —— Setup ————————————————————————————————————————————————————————————————————————
DC = docker-compose
PROJECT_DIR = /glsr
RUN = $(DC) run --rm
RUN_SERVER = $(RUN) -w $(PROJECT_DIR)/server
EXEC = $(DC) exec
SERVER_CONSOLE = $(EXEC) php php server/bin/console
GIT_AUTHOR = Dev-Int
PASS_PHRASE? = glsr
VERSION? =
.DEFAULT_GOAL :=help
.PHONY: help start stop build up reset cc install security config
check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))$(if $(value @), \
required by target `$@')))
## —— The Glsr Makefile ———————————————————————————————————————————————
help: ## Outputs this help screen
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
## —— Composer —————————————————————————————————————————————————————————————————
update: server/composer.json ## Update vendors according to the composer.json file
@echo "Update php dependencies"
@$(RUN_SERVER) php php -d memory_limit=-1 /usr/local/bin/composer update --no-interaction
## —— Project —————————————————————————————————————————————————————————————————————
start: config build project-vendors up #db-test ## Install and start the project
stop: ## Remove docker containers
@echo "Stopping containers"
@$(DC) kill > /dev/null
@$(DC) rm -v --force > /dev/null
@echo "Container stopped"
reset: stop start ## Reset the whole project
install: start security ## Install the whole project
cc: ## Clear the cache in dev env
@rm -rf server/var/cache/*
@$(EXEC) php php -d memory_limit=-1 server/bin/console cache:warmup
clean-dir: ## Clean directories
@rm -rf server/var/cache/* \
server/var/logs/*
clear: cc clean-dir ## Remove all the cache, the logs, the sessions
security:
@mkdir -p server/config/jwt/
@$(EXEC) php openssl genrsa -aes256 -passout pass:$(PASS_PHRASE) -out server/config/jwt/private.pem 4096
@$(EXEC) php openssl rsa -pubout -in server/config/jwt/private.pem -passin pass:$(PASS_PHRASE) -out server/config/jwt/public.pem
config: server/.env.local docker-compose.override.yml dist-files .git/hooks/pre-commit ## Init files required
@echo 'Configuration files copied'
bash-php: ## Open bash in php container
@$(EXEC) php bash
bash-client: ## Open bash in client container
@$(EXEC) client bash
## —— DB ——————————————————————————————————————————————————————————————————————————
db-test: server/.env.test ## Create tests database
@echo "create database for tests"
@$(SERVER_CONSOLE) doctrine:database:create --env=test
db-clean: cc ## Clean DB local
- @$(SERVER_CONSOLE) d:d:d --force
@$(SERVER_CONSOLE) d:d:c
@$(SERVER_CONSOLE) d:m:m -n
@$(SERVER_CONSOLE) d:f:l -n
db-clean-test: test-cc ## Clean DB test
- @$(SERVER_CONSOLE) d:d:d --force --env=test
@$(SERVER_CONSOLE) d:d:c --env=test
@$(SERVER_CONSOLE) d:m:m -n --env=test
@$(SERVER_CONSOLE) d:f:l -n --env=test
db-diff: ## Generation doctrine diff
@$(SERVER_CONSOLE) doctrine:migrations:diff --namespace 'Core\Infrastructure\Doctrine\Migrations'
db-migrate: ## Launch doctrine migrations
@$(SERVER_CONSOLE) doctrine:migrations:migrate --no-interaction
db-reset: ## Reset database with given DUMP variable
@:$(call check_defined, DUMP, sql file)
@echo 'Reseting database'
@$(EXEC) mysql reset $(DUMP) > /dev/null
db-save: ## Save database to a sql file
@:$(call check_defined, DUMP, sql file)
@echo 'Saving database'
@$(EXEC) mysql save $(DUMP) > /dev/null
reload: load-fixtures ## Reload fixtures
load-fixtures: ## Build the DB, load fixtures
@echo ""
$(SERVER_CONSOLE) doctrine:cache:clear-metadata
$(SERVER_CONSOLE) doctrine:database:create --if-not-exists
$(SERVER_CONSOLE) doctrine:fixtures:load -n
## —— Tests ———————————————————————————————————————————————————————————————————————
test-all: test-cc server/phpunit.xml ## Execute tests
@echo 'Running all tests'
@echo '—— Unit tests ——'
@$(EXEC) -w /glsr/server php php -d memory_limit=-1 bin/phpunit --stop-on-failure
test-domain: server/phpunit.xml test-cc ## Launch Domain unit tests
@echo "Running unit Domain tests"
@$(EXEC) -w /glsr/server php php -d memory_limit=-1 bin/phpunit --testsuite=Domain --stop-on-failure
test-e2e: server/phpunit.xml test-cc ## Launch End2End tests
@echo "Running end to end tests"
@$(EXEC) -w /glsr/server php php -d memory_limit=-1 bin/phpunit --testsuite=End2End --stop-on-failure
test-coverage: clean-dir ## Run test coverage
@echo 'Running tests coverage'
@$(EXEC) -w /glsr/server php php -d memory_limit=-1 bin/phpunit --coverage-html=var/test-coverage/
test-cc: ## Clear the cache in test environment. DID YOU CLEAR YOUR CACHE????
$(SERVER_CONSOLE) c:c --env=test
## —— Coding standards ✨ ———————————————————————————————————————————————————————
cs: codesniffer stan #lint ## Launch check style and static analysis
codesniffer: ## Run php_codesniffer only
@$(EXEC) php server/vendor/squizlabs/php_codesniffer/bin/phpcs --standard=server/phpcs.xml -n -p server/src/
stan: ## Execute phpstan
@$(EXEC) php server/vendor/bin/phpstan analyze -c server/phpstan.neon
cs-fixer: ## Execute php-cs-fixer
@$(EXEC) php server/vendor/bin/php-cs-fixer fix --config server/.php_cs
#psalm: ## Run psalm only
# @$(EXEC) php vendor/bin/psalm --show-info=false
#
#init-psalm: ## Init a new psalm config file for a given level, it must be decremented to have stricter rules
# @rm ./psalm.xml
# @$(EXEC) php vendor/bin/psalm --init src/ 3
version: ## Add a new tag with current date and publish it
@git checkout main > /dev/null
@git fetch --tags && git pull
@echo "MEP $(shell date '+%Y.%m.%d')\n" > VERSION
@git log --graph --pretty='%s' $(shell git tag | sort -r | head -n 1)..main >> VERSION
@git tag -a $(shell date '+%Y.%m.%d') -F VERSION > /dev/null
@git push --tags > /dev/null
@rm VERSION
# ## —— Deploy & Prod ————————————————————————————————————————————————————————————
#deploy: ## Full no-downtime deployment with EasyDeploy
# $(SERVER_CONSOLE) deploy -v
#
#env-check: ## Check the main ENV variables of the project
# printenv | grep -i app_
#
#le-renew: ## Renew Let's Encrypt HTTPS certificates
# certbot --apache -d demo.glsr.fr
# —— Yarn / JavaScript ————————————————————————————————————————————————————————
#dev: ## Rebuild assets for the dev env
# yarn install
# yarn run encore dev
#
#watch: ## Watch files and build assets when needed for the dev env
# yarn run encore dev --watch
#
#build: ## Build assets for production
# yarn run build
lint: ## Run TSLint on client
@$(EXEC) client yarn run lint
## Dependencies ————————————————————————————————————————————————————————————————
# Internal rules
project-vendors: server/vendor client/node_modules ## Server vendors
@echo "Vendors installed"
build:
@echo "Building images"
@$(DC) build > /dev/null
up:
@echo "Starting containers"
@$(DC) up -d --remove-orphans
# Single file dependencies
.env.local: server/.env
@echo "Copying docker environment variables"
@cp .env .env.local
@sed -i "s/^APP_USER_ID=.*/APP_USER_ID=$(shell id -u)/" .env.local
@sed -i "s/^APP_GROUP_ID=.*/APP_GROUP_ID=$(shell id -g)/" .env.local
.git/hooks/pre-commit: .docker/git/pre-commit
@echo "Copying git hooks"
@cp .docker/git/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
docker-compose.override.yml: docker-compose.override.yml.dist
@echo "Copying docker configuration"
@cp docker-compose.override.yml.dist docker-compose.override.yml
server/vendor: server/composer.lock
@echo "Installing project dependencies"
@$(RUN_SERVER) php php -d memory_limit=-1 /usr/local/bin/composer install --no-interaction
dist-files: server/.php_cs.dist
@echo "Coping .dist files"
@cp server/.php_cs.dist server/.php_cs
client/node_modules: client/yarn.lock
@echo "Installing client dependencies"
@$(RUN) client yarn install
## —— Stats ————————————————————————————————————————————————————————————————————
stats: ## Commits by the hour for the main author of this project
@git log --author="$(GIT_AUTHOR)" --date=iso | perl -nalE 'if (/^Date:\s+[\d-]{10}\s(\d{2})/) { say $$1+0 }' | sort | uniq -c|perl -MList::Util=max -nalE '$$h{$$F[1]} = $$F[0]; }{ $$m = max values %h; foreach (0..23) { $$h{$$_} = 0 if not exists $$h{$$_} } foreach (sort {$$a <=> $$b } keys %h) { say sprintf "%02d - %4d %s", $$_, $$h{$$_}, "*"x ($$h{$$_} / $$m * 50); }'