Skip to content

Commit db5f2c3

Browse files
committed
👌 IMPROVE: rewritten Makefile
1 parent a03e9f1 commit db5f2c3

File tree

1 file changed

+66
-53
lines changed

1 file changed

+66
-53
lines changed

Makefile

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
isDocker := $(shell docker info > /dev/null 2>&1 && echo 1)
2-
isContainerRunning := $(shell docker ps | grep symfony-php > /dev/null 2>&1 && echo 1)
1+
containerName = "symfony-php"
2+
isContainerRunning := $(shell docker info > /dev/null 2>&1 && docker ps | grep $(containerName) > /dev/null 2>&1 && echo 1)
33
user := $(shell id -u)
44
group := $(shell id -g)
55

6-
ifeq ($(isDocker), 1)
7-
ifeq ($(isContainerRunning), 1)
8-
DOCKER_COMPOSE := USER_ID=$(user) GROUP_ID=$(group) docker-compose
9-
DOCKER_EXEC := docker exec -u $(user):$(group) symfony-php
10-
dr := $(DOCKER_COMPOSE) run --rm
11-
sf := $(DOCKER_EXEC) php bin/console
12-
drtest := $(DOCKER_COMPOSE) -f docker-compose.test.yml run --rm
13-
php := $(DOCKER_EXEC) php
14-
else
15-
DOCKER_COMPOSE := USER_ID=$(user) GROUP_ID=$(group) docker-compose
16-
DOCKER_EXEC :=
17-
sf := php bin/console
18-
php :=
19-
endif
20-
else
21-
DOCKER_EXEC :=
22-
sf := php bin/console
23-
php :=
24-
endif
6+
DOCKER :=
7+
DOCKER_COMPOSE := USER_ID=$(user) GROUP_ID=$(group) docker-compose
8+
DOCKER_TEST := APP_ENV=test
9+
10+
CONSOLE := $(DOCKER) php
11+
CONSOLE_MEMORY := $(DOCKER) php -d memory_limit=256M
12+
CONSOLE_TEST := $(DOCKER_TEST) php
13+
COMPOSER = $(DOCKER) composer
2514

26-
COMPOSER = $(DOCKER_EXEC) composer
27-
CONSOLE = $(DOCKER_COMPOSE) php bin/console
15+
ifeq ($(isContainerRunning), 1)
16+
DOCKER := @docker exec -t -u $(user):$(group) $(containerName)
17+
DOCKER_COMPOSE := USER_ID=$(user) GROUP_ID=$(group) docker-compose
18+
DOCKER_TEST := @docker exec -t -u $(user):$(group) $(containerName) APP_ENV=test
19+
endif
2820

2921
## —— App ————————————————————————————————————————————————————————————————
3022
build-docker:
@@ -41,72 +33,93 @@ stop:
4133
$(DOCKER_COMPOSE) stop
4234
$(DOCKER_COMPOSE) ps
4335

44-
restore-permissions:
45-
@echo "Restoring permissions..."
46-
sudo chown -R $(user):$(group) .
36+
prune:
37+
@docker-compose down --remove-orphans
38+
@docker-compose down --volumes
39+
@docker-compose rm -f
40+
41+
serve:
42+
$(CONSOLE) serve
43+
44+
install-project: install reset-database generate-jwt ## First installation for setup the project
45+
46+
update-project: install reset-database ## update the project after a checkout on another branch or to reset the state of the project
47+
48+
sync: update-project test-all ## Synchronize the project with the current branch, install composer dependencies, drop DB and run all migrations, fixtures and all test
4749

4850
## —— 🐝 The Symfony Makefile 🐝 ———————————————————————————————————
4951
help: ## Outputs this help screen
5052
@grep -E '(^[a-zA-Z0-9_-]+:.*?## .*$$)|(^## )' Makefile | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
5153

5254
## —— Composer 🧙‍♂️ ————————————————————————————————————————————————————————————
53-
composer-install: composer.lock ## Install vendors according to the current composer.lock file
55+
install: composer.lock ## Install vendors according to the current composer.lock file
5456
$(COMPOSER) install -n
5557

56-
composer-update: composer.json ## Update vendors according to the composer.json file
58+
update: composer.json ## Update vendors according to the composer.json file
5759
$(COMPOSER) update -w
5860

5961
## —— Symfony ————————————————————————————————————————————————————————————————
6062
cc: ## Apply cache clear
61-
$(DOCKER_EXEC) sh -c "rm -rf var/cache/*"
62-
$(sf) cache:clear
63-
$(DOCKER_EXEC) sh -c "chmod -R 777 var/cache"
63+
$(DOCKER) sh -c "rm -rf var/cache"
64+
$(CONSOLE) cache:clear
65+
$(DOCKER) sh -c "chmod -R 777 var/cache"
66+
67+
cc-test: ## Apply cache clear
68+
$(DOCKER) sh -c "rm -rf var/cache"
69+
$(CONSOLE_TEST) cache:clear
70+
$(DOCKER) sh -c "chmod -R 777 var/cache"
6471

6572
doctrine-validate:
66-
$(sf) doctrine:schema:validate --skip-sync $c
73+
$(CONSOLE) doctrine:schema:validate --skip-sync $c
6774

6875
reset-database: drop-database database migrate load-fixtures ## Reset database with migration
6976

7077
database: ## Create database if no exists
71-
$(sf) doctrine:database:create --if-not-exists
78+
$(CONSOLE) migrate:status
7279

7380
drop-database: ## Drop the database
74-
$(sf) doctrine:database:drop --force --if-exists
81+
$(CONSOLE) doctrine:database:drop --force --if-exists
7582

7683
migration: ## Apply doctrine migration
77-
$(sf) make:migration
84+
$(CONSOLE) make:migration
7885

7986
migrate: ## Apply doctrine migrate
80-
$(sf) doctrine:migration:migrate -n --all-or-nothing
81-
82-
load-fixtures: ## Load fixtures
83-
$(sf) doctrine:fixtures:load -n
87+
$(CONSOLE) doctrine:migration:migrate -n --all-or-nothing
8488

85-
generate-jwt:
86-
$(sf) lexik:jwt:generate-keypair --overwrite -q $c
89+
generate-jwt: ## Generate private and public keys
90+
$(CONSOLE) lexik:jwt:generate-keypair --overwrite -q $c
8791

8892
## —— Tests ✅ ————————————————————————————————————————————————————————————
89-
test-load-fixtures: ## load database schema & fixtures
90-
$(DOCKER_COMPOSE) sh -c "APP_ENV=test php bin/console doctrine:database:drop --if-exists --force"
91-
$(DOCKER_COMPOSE) sh -c "APP_ENV=test php bin/console doctrine:database:create --if-not-exists"
92-
$(DOCKER_COMPOSE) sh -c "APP_ENV=test php bin/console doctrine:migration:migrate -n --all-or-nothing"
93-
$(DOCKER_COMPOSE) sh -c "APP_ENV=test php bin/console doctrine:fixtures:load -n"
93+
test-database: ### load database schema
94+
$(CONSOLE_TEST) doctrine:database:drop --if-exists --force
95+
$(CONSOLE_TEST) doctrine:database:create --if-not-exists
96+
$(CONSOLE_TEST) doctrine:migration:migrate -n --all-or-nothing
97+
$(CONSOLE_TEST) doctrine:fixtures:load -n
98+
99+
pest:
100+
$(CONSOLE) ./vendor/bin/pest
94101

95102
test: phpunit.xml* ## Launch main functional and unit tests, stopped on failure
96-
$(php) APP_ENV=test ./vendor/bin/simple-phpunit
103+
$(CONSOLE) ./vendor/bin/pest --stop-on-failure $c
97104

98105
test-all: phpunit.xml* test-load-fixtures ## Launch main functional and unit tests
99-
$(php) APP_ENV=test ./vendor/bin/simple-phpunit
106+
$(DOCKER_TEST) ./vendor/bin/pest
100107

101-
test-report: phpunit.xml* test-load-fixtures ## Launch main functionnal and unit tests with report
102-
$(php) APP_ENV=test ./vendor/bin/simple-phpunit --coverage-text --coverage-clover=coverage.xml
108+
test-report: phpunit.xml* test-load-fixtures ## Launch main functional and unit tests with report
109+
$(DOCKER_TEST) ./vendor/bin/pest --coverage-text --colors=never --log-junit report.xml $c
103110

104111
## —— Coding standards ✨ ——————————————————————————————————————————————————————
105112
stan: ## Run PHPStan only
106-
$(php) ./vendor/bin/phpstan analyse -l 9 src --no-progress -c phpstan.neon --memory-limit 256M
113+
$(CONSOLE) ./vendor/bin/phpstan analyse -l 9 src --no-progress -c phpstan.neon --memory-limit 256M
114+
115+
ecs: ## Run ECS only
116+
$(CONSOLE) ./vendor/bin/ecs check --memory-limit 256M
117+
118+
ecs-fix: ## Run php-cs-fixer and fix the code.
119+
$(CONSOLE) ./vendor/bin/ecs check --fix --memory-limit 256M
107120

108121
cs-fix: ## Run php-cs-fixer and fix the code.
109-
$(php) ./vendor/bin/php-cs-fixer fix --allow-risky=yes
122+
$(CONSOLE) ./vendor/bin/php-cs-fixer fix --allow-risky=yes
110123

111124
cs-dry: ## Dry php-cs-fixer and display code may to be change
112-
$(php) ./vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes
125+
$(CONSOLE) ./vendor/bin/php-cs-fixer fix --dry-run --allow-risky=yes

0 commit comments

Comments
 (0)