From f64c2786696059712519d665f949c6d0915286e8 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Sun, 22 Feb 2026 13:01:46 +0100 Subject: [PATCH 1/2] Cleaned up script stuff --- .dockerignore | 4 ++++ .gitignore | 1 + composer.json | 2 ++ rector.php | 3 +++ scripts/base | 50 +++------------------------------------- scripts/code-analysis | 1 - scripts/compose.yaml | 53 +++++++++++++++++++++++++++++++++++++++---- scripts/rector | 1 - 8 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eadd688 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.idea +vendor +composer.lock +*.cache diff --git a/.gitignore b/.gitignore index 722dce6..eadd688 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea vendor composer.lock *.cache diff --git a/composer.json b/composer.json index aa2f294..a5eaef5 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ ], "require": { "ext-dom": "*", + "ext-xsl": "*", "drupal/system_stream_wrapper": "^2.1", "drush/drush": "^12 || ^13", "itk-dev/serviceplatformen": "dev-feature/SF2900-Fordelingskomponenten as 1.7.9999", @@ -20,6 +21,7 @@ "drupal/coder": "^8.3", "ergebnis/composer-normalize": "^2.50", "mglaman/phpstan-drupal": "^2.0", + "palantirnet/drupal-rector": "^0.21.1", "phpstan/extension-installer": "^1.4", "phpunit/phpunit": "^9.6", "vincentlanglet/twig-cs-fixer": "^3.13" diff --git a/rector.php b/rector.php index 44fe530..24bef86 100644 --- a/rector.php +++ b/rector.php @@ -14,6 +14,9 @@ __DIR__ . '/src', // __DIR__ . '/tests', ]) + ->withSkip([ + __DIR__ . '/vendor', + ]) ->withSets([ Drupal10SetList::DRUPAL_10, ]) diff --git a/scripts/base b/scripts/base index d12b23d..04392b0 100644 --- a/scripts/base +++ b/scripts/base @@ -74,53 +74,9 @@ module_name=$(basename "$module_path") trap teardown EXIT setup() { - compose down --remove-orphans - compose pull - compose up --detach --remove-orphans --wait - - # @todo Do this in a dockerfile. - compose exec drupal sh -c 'apt update && apt --yes install git' - - # Allow all plugins to run. - composer --no-plugins config allow-plugins true - composer --no-plugins config minimum-stability dev - - composer --no-plugins config extra.drupal-lenient.allow-all --json true - # composer --no-plugins config extra.drupal-lenient.allowed-list --json '[ "drupal/coc_forms_auto_export", "drupal/webform_node_element" ]' - composer require mglaman/composer-drupal-lenient --with-all-dependencies - - # -------------------------------------------------------------------------------------------------------------------- - # We need to install dev requirements from our module, so we use - # wikimedia/composer-merge-plugin to merge our module composer.json into - # Drupal's. - # - # wikimedia/composer-merge-plugin is dead and has some issues - # https://github.com/wikimedia/composer-merge-plugin/issues/159 » - # https://github.com/wikimedia/composer-merge-plugin/pull/253 - # - # Install wikimedia/composer-merge-plugin without any configuration - composer require wikimedia/composer-merge-plugin --with-all-dependencies - # Patch to make COMPOSER_IGNORE_PLATFORM_REQS=1 have effect - # https://github.com/wikimedia/composer-merge-plugin/pull/253 - shell sh -c 'cd vendor/wikimedia/composer-merge-plugin/ && curl https://patch-diff.githubusercontent.com/raw/wikimedia/composer-merge-plugin/pull/253.diff | patch --strip=1' - - # Configure wikimedia/composer-merge-plugin - composer --no-plugins config extra.merge-plugin.include "$module_path/composer.json" - # Use --json to actually set a boolean value (rather that a string value, e.g. "true") - composer --no-plugins config extra.merge-plugin.merge-extra --json true - composer --no-plugins config extra.merge-plugin.merge-extra-deep --json true - - composer update - # Our module and its dev requirements are now installed. - # -------------------------------------------------------------------------------------------------------------------- - - # Reset Drupal installation - compose exec drupal sh -c 'find . -name .ht.sqlite -ls -delete; rm web/sites/default/settings.php' || true - # Install a minimal Drupal site. - drush --yes site:install --db-url='sqlite://sites/default/files/.ht.sqlite?module=sqlite' minimal -vvv - - # Uncomment this line if you need to debug - # shell bash + # compose down --remove-orphans + compose pull --ignore-buildable + compose up --detach --remove-orphans --wait # --build # Finally, install our module. drush --yes pm:install "$module_name" diff --git a/scripts/code-analysis b/scripts/code-analysis index d0bb172..09735a0 100755 --- a/scripts/code-analysis +++ b/scripts/code-analysis @@ -6,7 +6,6 @@ script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$script_dir" execute() { - composer require --dev symfony/phpunit-bridge shell vendor/bin/phpstan --configuration="$module_path/phpstan.neon" --memory-limit=256M } diff --git a/scripts/compose.yaml b/scripts/compose.yaml index cb08be5..315361b 100644 --- a/scripts/compose.yaml +++ b/scripts/compose.yaml @@ -2,7 +2,52 @@ services: drupal: - image: drupal:${DRUPAL_VERSION:-10}-apache + # image: drupal:${DRUPAL_VERSION:-10}-apache + build: + context: ../ + dockerfile_inline: | + FROM drupal:${DRUPAL_VERSION:-10}-apache + + COPY ./composer.json web/modules/${MODULE_NAME?}/ + + # https://github.com/docker-library/docs/blob/master/php/README.md#how-to-install-more-php-extensions + RUN apt update && apt --yes install git libxml2-dev libxslt1-dev \ + && docker-php-ext-configure soap \ + && docker-php-ext-install soap \ + && docker-php-ext-configure xsl \ + && docker-php-ext-install xsl + + # -------------------------------------------------------------------------------------------------------------------- + # We need to install dev requirements from our module, so we use + # wikimedia/composer-merge-plugin to merge our module composer.json into + # Drupal's. + # + # wikimedia/composer-merge-plugin is dead and has some issues + # https://github.com/wikimedia/composer-merge-plugin/issues/159 » + # https://github.com/wikimedia/composer-merge-plugin/pull/253 + RUN composer --no-plugins config allow-plugins true \ + && composer --no-plugins config minimum-stability dev \ + # Use --json to actually set a boolean value (rather that a string value, e.g. "true") + && composer --no-plugins config extra.drupal-lenient.allow-all --json true \ + + # Configure wikimedia/composer-merge-plugin + && composer --no-plugins config extra.merge-plugin.merge-extra --json true \ + && composer --no-plugins config extra.merge-plugin.merge-extra-deep --json true \ + && composer --no-plugins config extra.merge-plugin.include "web/modules/${MODULE_NAME?}/composer.json" \ + && composer require mglaman/composer-drupal-lenient wikimedia/composer-merge-plugin --with-all-dependencies + + # Patch to make COMPOSER_IGNORE_PLATFORM_REQS=1 have effect + # https://github.com/wikimedia/composer-merge-plugin/pull/253 + # RUN cd vendor/wikimedia/composer-merge-plugin/ && curl https://patch-diff.githubusercontent.com/raw/wikimedia/composer-merge-plugin/pull/253.diff | patch --strip=1 + + # Reset Drupal installation + RUN find . -name .ht.sqlite -delete \ + && find web/sites/default -name -delete + + # Install a minimal Drupal site. + # https://www.drush.org/13.x/commands/site_install/ + RUN drush --yes site:install --db-url=sqlite://sites/default/files/.ht.sqlite?module=sqlite minimal -vvv + ports: - 80 volumes: @@ -13,10 +58,10 @@ services: # volume (which is what we're creating here) will be initialized with the # existing content of the image at the same location - /var/www/html/sites - # Mount our code into the web/modules/contrib folder - - ../:/opt/drupal/web/modules/contrib/$MODULE_NAME + # Mount our code into the web/modules folder + - ../:/opt/drupal/web/sites/default/modules/$MODULE_NAME environment: # Let the module path, i.e. the mounted path, be known in the container - MODULE_PATH: web/modules/contrib/$MODULE_NAME + MODULE_PATH: web/sites/default/modules/$MODULE_NAME # https://getcomposer.org/doc/03-cli.md#composer-ignore-platform-req-or-composer-ignore-platform-reqs COMPOSER_IGNORE_PLATFORM_REQS: 1 diff --git a/scripts/rector b/scripts/rector index 658d933..f695ffd 100755 --- a/scripts/rector +++ b/scripts/rector @@ -6,7 +6,6 @@ script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) cd "$script_dir" execute() { - composer require --dev palantirnet/drupal-rector shell vendor/bin/rector --config="$module_path/rector.php" } From 6fae1aa7d72d98570f8f94a4c4f2db99699f6274 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Sun, 22 Feb 2026 13:13:19 +0100 Subject: [PATCH 2/2] DEBUG --- .github/workflows/project.yaml | 11 +++++++++++ Taskfile.yml | 18 ++++++++++++++++++ scripts/base | 2 +- scripts/compose.yaml | 9 +++++---- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/project.yaml b/.github/workflows/project.yaml index da5ae3d..8c91dee 100644 --- a/.github/workflows/project.yaml +++ b/.github/workflows/project.yaml @@ -14,9 +14,20 @@ jobs: code-analysis: name: PHP - Code analysis runs-on: ubuntu-latest + environment: + BUILDKIT_PROGRESS: plain steps: - uses: actions/checkout@v5 + # https://github.com/mxschmitt/action-tmate?tab=readme-ov-file#manually-triggered-debug + # Enable tmate debugging if debug logging is enabled (cf. + # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#runner-context) + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: false + if: 1 == runner.debug + - run: | ./scripts/code-analysis diff --git a/Taskfile.yml b/Taskfile.yml index 4a8d6a0..6621c0f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -132,6 +132,24 @@ tasks: # Cf. .github/workflows/yaml.yaml - docker compose run --rm prettier '**/*.{yml,yaml}' --check + code-analysis:phpstan: + desc: Run static code analysis + cmds: + - ./scripts/code-analysis + + code-analysis:rector: + desc: Run static code analysis + cmds: + - ./scripts/rector + + code-analysis:build-image: + desc: Build Drupal image used for static code analysis + prompt: Really? + cmds: + - docker image rm drupal-module-drupal --force + - docker builder prune --force + - BUILDKIT_PROGRESS=plain docker compose --project-directory scripts build + test: cmds: - docker compose run --env PHP_XDEBUG_MODE --env PHP_XDEBUG_WITH_REQUEST --env PHP_IDE_CONFIG --rm phpfpm vendor/bin/phpunit {{.CLI_ARGS}} diff --git a/scripts/base b/scripts/base index 04392b0..aada47c 100644 --- a/scripts/base +++ b/scripts/base @@ -76,7 +76,7 @@ trap teardown EXIT setup() { # compose down --remove-orphans compose pull --ignore-buildable - compose up --detach --remove-orphans --wait # --build + compose up --detach --remove-orphans --wait # Finally, install our module. drush --yes pm:install "$module_name" diff --git a/scripts/compose.yaml b/scripts/compose.yaml index 315361b..f505f7a 100644 --- a/scripts/compose.yaml +++ b/scripts/compose.yaml @@ -6,12 +6,12 @@ services: build: context: ../ dockerfile_inline: | - FROM drupal:${DRUPAL_VERSION:-10}-apache + FROM drupal:${DRUPAL_VERSION:-10}-php${PHP_VERSION:-8.3}-apache COPY ./composer.json web/modules/${MODULE_NAME?}/ # https://github.com/docker-library/docs/blob/master/php/README.md#how-to-install-more-php-extensions - RUN apt update && apt --yes install git libxml2-dev libxslt1-dev \ + RUN apt-get update && apt-get --yes install git libxml2-dev libxslt1-dev \ && docker-php-ext-configure soap \ && docker-php-ext-install soap \ && docker-php-ext-configure xsl \ @@ -34,7 +34,8 @@ services: && composer --no-plugins config extra.merge-plugin.merge-extra --json true \ && composer --no-plugins config extra.merge-plugin.merge-extra-deep --json true \ && composer --no-plugins config extra.merge-plugin.include "web/modules/${MODULE_NAME?}/composer.json" \ - && composer require mglaman/composer-drupal-lenient wikimedia/composer-merge-plugin --with-all-dependencies + && composer require mglaman/composer-drupal-lenient wikimedia/composer-merge-plugin --with-all-dependencies \ + && composer update --with-all-dependencies # Patch to make COMPOSER_IGNORE_PLATFORM_REQS=1 have effect # https://github.com/wikimedia/composer-merge-plugin/pull/253 @@ -46,7 +47,7 @@ services: # Install a minimal Drupal site. # https://www.drush.org/13.x/commands/site_install/ - RUN drush --yes site:install --db-url=sqlite://sites/default/files/.ht.sqlite?module=sqlite minimal -vvv + RUN vendor/bin/drush --yes site:install --db-url=sqlite://sites/default/files/.ht.sqlite?module=sqlite minimal -vvv ports: - 80