From 319756561998c6117159bef9d3f7e6a9c2bdc5bb Mon Sep 17 00:00:00 2001 From: jmsche Date: Sat, 12 Oct 2024 14:00:35 +0200 Subject: [PATCH] Add Taskfile --- .gitignore | 2 + README.md | 10 +++- Taskfile.yaml | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 Taskfile.yaml diff --git a/.gitignore b/.gitignore index b0de3ae..4f662a1 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ .phpunit.result.cache .phpunit.cache ###< phpunit/phpunit ### + +/.task diff --git a/README.md b/README.md index 2d5f9c8..cface9d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ Or with Castor: castor symfony:start +Or with Task: + + task start + Open [https://127.0.0.1:8000](https://127.0.0.1:8000) (considering your 8000 port is free) and enjoy! 🙂 @@ -92,7 +96,8 @@ You can also directly use the [FrankenPHP](https://github.com/strangebuzz/MicroS * The [Xdebug](https://xdebug.org/) PHP extension if you want to run the code coverage report * [Castor](https://github.com/jolicode/castor) task runner if you don't want to use - [Make](https://www.gnu.org/software/make/) and its [Makefile](https://github.com/strangebuzz/MicroSymfony/blob/main/Makefile) + [Make](https://www.gnu.org/software/make/) and its [Makefile](https://github.com/strangebuzz/MicroSymfony/blob/main/Makefile) or + [Task](https://taskfile.dev/) and its [Taskfile](https://github.com/strangebuzz/MicroSymfony/blob/main/Taskfile.yaml) ## Stack 🔗 @@ -111,9 +116,10 @@ to fix some issues as the project is not maintained anymore. **MicroSymfony** ships these features, ready to use: -* Two task runner +* Three task runners * [Make](https://www.gnu.org/software/make/) ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/Makefile)) ([demo](https://www.strangebuzz.com/en/blog/introducing-the-microsymfony-application-template#h3_4_1)) * [Castor](https://github.com/jolicode/castor) ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/castor.php)) ([demo](https://www.strangebuzz.com/en/blog/introducing-the-microsymfony-application-template#h3_4_2)) + * [Task](https://taskfile.dev/) ([source](https://github.com/strangebuzz/MicroSymfony/blob/main/Taskfile.yaml)) * Static analysis with [PHPStan](https://github.com/phpstan/phpstan) * [Configuration](https://github.com/strangebuzz/MicroSymfony/blob/main/phpstan.neon) * Coding standards with [php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) diff --git a/Taskfile.yaml b/Taskfile.yaml new file mode 100644 index 0000000..4ec8c72 --- /dev/null +++ b/Taskfile.yaml @@ -0,0 +1,138 @@ +version: '3' + +vars: + # You can modify the coverage threshold here + COVERAGE_THRESHOLD: 100 + +tasks: + ## —— Symfony binary 💻 ———————————————————————————————————————————————————————— + start: + desc: Serve the application with the Symfony binary + cmd: symfony serve --daemon + + stop: + desc: Stop the web server + cmd: symfony server:stop + + ## —— Symfony 🎶 —————————————————————————————————————————————————————————————— + go-prod: + desc: Switch to the production environment + cmds: + - cp .env.local.dist .env.local + # uncomment this line to optimize the auto-loading of classes in the prod env + # - composer dump-autoload --no-dev --classmap-authoritative + - bin/console asset-map:compile + + go-dev: + desc: Switch to the development environment + cmds: + - rm -f .env.local + - rm -rf ./public/assets/* + + warmup: + desc: Warmup the dev cache for the static analysis + cmd: bin/console c:w --env=dev + + purge: + desc: Purge all Symfony cache and logs + cmd: rm -rf ./var/cache/* ./var/logs/* ./var/coverage/* + + ## —— Tests ✅ ————————————————————————————————————————————————————————————————— + test: + desc: Run all PHPUnit tests + cmd: vendor/bin/phpunit + + coverage: + desc: Generate the HTML PHPUnit code coverage report (stored in var/coverage) + cmds: + - task: purge + - XDEBUG_MODE=coverage php -d xdebug.enable=1 -d memory_limit=-1 vendor/bin/phpunit --coverage-html=var/coverage --coverage-clover=var/coverage/clover.xml + - php bin/coverage-checker.php var/coverage/clover.xml {{.COVERAGE_THRESHOLD}} + + cov-report: + desc: Open the PHPUnit code coverage report (var/coverage/index.html) + cmd: open var/coverage/index.html + preconditions: + - test -f var/coverage/index.html + + ## —— Coding standards/lints ✨ ———————————————————————————————————————————————— + stan: + desc: Run PHPStan + cmds: + - APP_DEBUG=1 APP_ENV=dev bin/console cache:warmup + - vendor/bin/phpstan analyse -c phpstan.neon --memory-limit 1G -vv + + fix-php: + desc: Fix PHP files with php-cs-fixer (ignore PHP 8.2 warning) + cmd: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix + + lint-php: + desc: Lint PHP files with php-cs-fixer (report only) + cmd: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run + + lint-container: + desc: Lint the Symfony DI container + cmd: bin/console lint:container + + lint-twig: + desc: Lint Twig files + cmd: bin/console lint:twig templates/ + + lint-yaml: + desc: Lint YAML files + cmd: bin/console lint:yaml --parse-tags config/ + + cs: + desc: Run all CS checks + cmds: + - task: fix-php + - task: stan + + lint: + desc: Run all lints + cmds: + - task: lint-php + - task: lint-container + - task: lint-twig + - task: lint-yaml + + ci: + desc: Run CI locally + cmds: + - task: coverage + - task: warmup + - task: cs + - task: lint + + ## —— Other tools and helpers 🔨 ——————————————————————————————————————————————— + versions: + desc: Display current stack versions + cmds: + - task: version-php + - task: version-composer + - task: version-symfony + - task: version-phpunit + - task: version-phpstan + - task: version-php-cs-fixer + version-php: + desc: Display PHP version + cmd: php -v + version-composer: + desc: Display Composer version + cmd: composer --version + version-symfony: + desc: Display Symfony version + cmd: bin/console --version + version-phpunit: + desc: Display PHPUnit version + cmd: vendor/bin/phpunit --version + version-phpstan: + desc: Display PHPStan version + cmd: vendor/bin/phpstan --version + version-php-cs-fixer: + desc: Display PHP CS Fixer version + cmd: vendor/bin/php-cs-fixer --version + + check-requirements: + desc: Checks requirements for running Symfony + cmd: vendor/bin/requirements-checker