From 696aa5d617440b9a6aed8ce6347e7d0bd050f780 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 18 Oct 2023 20:38:53 +0200 Subject: [PATCH] feat(drupal): allow for disabling quality checks For Commerce Kickstart, there are no custom modules so these checks will fail in the CI pipeline. --- src/Action/CreateListOfFilesToGenerate.php | 15 ++++++++++++--- src/DataTransferObject/Config.php | 2 ++ templates/drupal/run.twig | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Action/CreateListOfFilesToGenerate.php b/src/Action/CreateListOfFilesToGenerate.php index f628027..c86a9be 100644 --- a/src/Action/CreateListOfFilesToGenerate.php +++ b/src/Action/CreateListOfFilesToGenerate.php @@ -73,7 +73,6 @@ final class CreateListOfFilesToGenerate new TemplateFile(data: 'drupal/.hadolint.yaml', name: '.hadolint.yaml'), new TemplateFile(data: 'drupal/Dockerfile', name: 'Dockerfile'), new TemplateFile(data: 'drupal/docker-compose.yaml', name: 'docker-compose.yaml'), - new TemplateFile(data: 'drupal/phpstan.neon.dist', name: 'phpstan.neon.dist'), new TemplateFile(data: 'drupal/run', name: 'run'), ]); @@ -86,8 +85,18 @@ final class CreateListOfFilesToGenerate )); } - $filesToGenerate->push(new TemplateFile(data: 'drupal/phpcs.xml.dist', name: 'phpcs.xml.dist')); - $filesToGenerate->push(new TemplateFile(data: 'drupal/phpunit.xml.dist', name: 'phpunit.xml.dist')); + if ($configurationDataDto->php['phpcs'] !== false) { + $filesToGenerate->push(new TemplateFile(data: 'drupal/phpcs.xml.dist', name: 'phpcs.xml.dist')); + } + + if ($configurationDataDto->php['phpstan'] !== false) { + $filesToGenerate->push(new TemplateFile(data: 'drupal/phpstan.neon.dist', name: 'phpstan.neon.dist')); + } + + if ($configurationDataDto->php['phpunit'] !== false) { + $filesToGenerate->push(new TemplateFile(data: 'drupal/phpunit.xml.dist', name: 'phpunit.xml.dist')); + } + $filesToGenerate->push(new TemplateFile( data: 'drupal/docker-entrypoint-php', name: 'docker-entrypoint-php', diff --git a/src/DataTransferObject/Config.php b/src/DataTransferObject/Config.php index b57d9fb..c953c9c 100644 --- a/src/DataTransferObject/Config.php +++ b/src/DataTransferObject/Config.php @@ -59,4 +59,6 @@ final class Config #[Assert\NotBlank] public ?string $projectRoot; + + public array $php; } diff --git a/templates/drupal/run.twig b/templates/drupal/run.twig index c7b36e2..e3251d5 100755 --- a/templates/drupal/run.twig +++ b/templates/drupal/run.twig @@ -21,9 +21,13 @@ function ci:test { composer install --quiet --no-progress +{% if not php.phpcs is same as false %} test --testdox +{% endif %} +{% if not php.phpcs is same as false and not php.phpstan is same as false %} quality +{% endif %} } # Run a command within the php container. @@ -31,9 +35,11 @@ function cmd { docker compose exec php "${@}" } +{% if not php.phpcs is same as false %} function coding-standards { cmd phpcs "${@}" } +{% endif %} function composer { _exec php composer "${@}" @@ -65,10 +71,16 @@ function lint:dockerfile { hadolint/hadolint hadolint --ignore DL3008 --ignore DL3059 -t style "${@}" - < Dockerfile } +{% if not php.phpcs is same as false and not php.phpstan is same as false %} function quality { +{% if not php.phpcs is same as false %} coding-standards +{% endif %} +{% if not php.phpstan is same as false %} static-analysis +{% endif %} } +{% endif %} function start { cp -v --no-clobber .env.example .env @@ -76,22 +88,28 @@ function start { docker compose up -d } +{% if not php.phpstan is same as false %} function static-analysis { cmd phpstan --memory-limit=-1 --no-progress "${@}" } +{% endif %} function stop { docker compose down } +{% if not php.phpunit is same as false %} function test { _exec php phpunit --colors=always "${@}" } +{% endif %} function test:commit { +{% if not php.phpunit is same as false %} test --testdox --testsuite functional test --testdox --testsuite kernel test --testdox --testsuite unit +{% endif %} quality }