|
| 1 | +# Parameters (optional) |
| 2 | +# * `arg`: arbitrary arguments to pass to rules (default: none) |
| 3 | +arg ?= |
| 4 | + |
| 5 | +# Docker containers |
| 6 | +LIB_SERVICE = memio-validator |
| 7 | + |
| 8 | +# Executables |
| 9 | +COMPOSER = docker exec $(LIB_SERVICE) composer |
| 10 | +PHP_CS_FIXER = docker exec $(LIB_SERVICE) php vendor/bin/php-cs-fixer |
| 11 | +PHPSPEC = docker exec $(LIB_SERVICE) php vendor/bin/phpspec |
| 12 | +PHPSTAN = docker exec $(LIB_SERVICE) php vendor/bin/phpstan --memory-limit=256M |
| 13 | +RECTOR = docker exec $(LIB_SERVICE) php vendor/bin/rector |
| 14 | +SWISS_KNIFE = docker exec $(LIB_SERVICE) php vendor/bin/swiss-knife |
| 15 | + |
| 16 | +# Misc |
| 17 | +.DEFAULT_GOAL = help |
| 18 | +.PHONY: * |
| 19 | + |
| 20 | +## —— 🔭 The Super Secret Makefile —————————————————————————————————————————————— |
| 21 | +## Based on https://github.com/dunglas/symfony-docker |
| 22 | +## (arg) denotes the possibility to pass "arg=" parameter to the target |
| 23 | +## this allows to add command and options, example: make composer arg='dump --optimize' |
| 24 | +help: ## Outputs this help screen |
| 25 | + @grep -E '(^[a-zA-Z0-9\./_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) \ |
| 26 | + | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' \ |
| 27 | + | sed -e 's/\[32m##/[33m/' |
| 28 | + |
| 29 | +## —— Docker 🐳 ———————————————————————————————————————————————————————————————— |
| 30 | +docker: ## Runs Docker (arg, eg `arg='ps'`) |
| 31 | + @docker $(arg) |
| 32 | + |
| 33 | +docker-init: ## Builds the Docker image and starts the container in detached mode |
| 34 | + @docker build --platform linux/amd64 --pull -t $(LIB_SERVICE) . |
| 35 | + @docker run -d --platform linux/amd64 --name $(LIB_SERVICE) -v .:/app $(LIB_SERVICE) tail -f /dev/null |
| 36 | + |
| 37 | +docker-down: ## Stops and removes the container |
| 38 | + @docker rm -f $(LIB_SERVICE) 2>/dev/null || true |
| 39 | + |
| 40 | +docker-bash: ## Opens a (bash) shell in the container |
| 41 | + @docker exec -it $(LIB_SERVICE) bash |
| 42 | + |
| 43 | +## —— PHP 🐘 ——————————————————————————————————————————————————————————————————— |
| 44 | +composer: ## Runs Composer (arg, eg `arg='outdated'`) |
| 45 | + @$(COMPOSER) $(arg) |
| 46 | + |
| 47 | +composer-install: ## Install dependencies (arg, eg `arg='--no-dev'`) |
| 48 | + @$(COMPOSER) install --optimize-autoloader $(arg) |
| 49 | + |
| 50 | +composer-update: ## Updates dependencies (arg, eg `arg='--no-dev'`) |
| 51 | + @$(COMPOSER) update --optimize-autoloader $(arg) |
| 52 | + |
| 53 | +composer-dump: ## Dumps autoloader (arg, eg `arg='--classmap-authoritative'`) |
| 54 | + @$(COMPOSER) dump-autoload --optimize --strict-psr --strict-ambiguous $(arg) |
| 55 | + |
| 56 | +cs-check: ## Checks CS with PHP-CS-Fixer (arg, eg `arg='../monolith/web'`) |
| 57 | + @$(PHP_CS_FIXER) fix --dry-run --verbose $(arg) |
| 58 | + |
| 59 | +cs-fix: ## Fixes CS with Swiss Knife and PHP-CS-Fixer |
| 60 | + @$(SWISS_KNIFE) namespace-to-psr-4 spec/Memio/Validator --namespace-root 'spec\\Memio\\Validator\\' |
| 61 | + @$(SWISS_KNIFE) namespace-to-psr-4 src/Memio/Validator --namespace-root 'Memio\\Validator\\' |
| 62 | + @$(PHP_CS_FIXER) fix --verbose $(arg) |
| 63 | + |
| 64 | +phpstan: ## Static Analysis with PHPStan (arg, eg `arg='--level=6'`) |
| 65 | + @$(PHPSTAN) analyze $(arg) |
| 66 | + |
| 67 | +swiss-knife: ## Automated refactorings with Swiss Knife (arg, eg `arg='namespace-to-psr-4 src --namespace-root \'App\\\''`) |
| 68 | + @$(SWISS_KNIFE) $(arg) |
| 69 | + |
| 70 | +phpspec: ## Runs the specifications with phpspec (arg, eg `arg='--format=dot'`) |
| 71 | + @$(PHPSPEC) --no-interaction run $(arg) |
| 72 | + |
| 73 | +rector-fix: ## Automated refactorings with Rector (arg, eg `arg='--clear-cache'`) |
| 74 | + @$(RECTOR) $(arg) |
| 75 | + |
| 76 | +rector-check: ## Refactoring checks with Rector |
| 77 | + @$(RECTOR) process --dry-run |
| 78 | + |
| 79 | +## —— Lib 📚 ——————————————————————————————————————————————————————————————————— |
| 80 | +lib-init: ## First install / resetting (Docker build, up, etc) |
| 81 | + @echo '' |
| 82 | + @echo ' // Installing git hooks...' |
| 83 | + @git config core.hooksPath bin/hooks |
| 84 | + @echo '' |
| 85 | + @echo ' // Stopping lib docker services...' |
| 86 | + @$(MAKE) docker-down |
| 87 | + @echo '' |
| 88 | + @echo ' // Starting lib docker services...' |
| 89 | + @$(MAKE) docker-init |
| 90 | + @echo '' |
| 91 | + @echo ' [OK] Lib initialized' |
| 92 | + |
| 93 | +lib-qa: ## Runs full QA pipeline (composer-dump, cs-check, phpstan, rector-check, phpspec) |
| 94 | + @echo '' |
| 95 | + @echo ' // Running composer dump...' |
| 96 | + @$(MAKE) composer-dump |
| 97 | + @echo '' |
| 98 | + @echo ' // Running PHP CS Fixer...' |
| 99 | + @$(MAKE) cs-check |
| 100 | + @echo '' |
| 101 | + @echo ' // Running PHPStan...' |
| 102 | + @$(MAKE) phpstan |
| 103 | + @echo '' |
| 104 | + @echo ' // Running Rector...' |
| 105 | + @$(MAKE) rector-check |
| 106 | + @echo '' |
| 107 | + @echo ' // Running phpspec...' |
| 108 | + @$(MAKE) phpspec |
| 109 | + @echo '' |
| 110 | + @echo ' [OK] QA done' |
0 commit comments