Skip to content

Commit

Permalink
Add Taskfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsche committed Oct 12, 2024
1 parent 4d15cac commit 3197565
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
.phpunit.result.cache
.phpunit.cache
###< phpunit/phpunit ###

/.task
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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! 🙂


Expand Down Expand Up @@ -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 🔗
Expand All @@ -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)
Expand Down
138 changes: 138 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3197565

Please sign in to comment.