Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
vendor
composer.lock
*.cache
11 changes: 11 additions & 0 deletions .github/workflows/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor
composer.lock
*.cache
18 changes: 18 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
__DIR__ . '/src',
// __DIR__ . '/tests',
])
->withSkip([
__DIR__ . '/vendor',
])
->withSets([
Drupal10SetList::DRUPAL_10,
])
Expand Down
48 changes: 2 additions & 46 deletions scripts/base
Original file line number Diff line number Diff line change
Expand Up @@ -74,54 +74,10 @@ module_name=$(basename "$module_path")
trap teardown EXIT

setup() {
compose down --remove-orphans
compose pull
# compose down --remove-orphans
compose pull --ignore-buildable
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

# Finally, install our module.
drush --yes pm:install "$module_name"
}
Expand Down
1 change: 0 additions & 1 deletion scripts/code-analysis
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
54 changes: 50 additions & 4 deletions scripts/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,53 @@

services:
drupal:
image: drupal:${DRUPAL_VERSION:-10}-apache
# image: drupal:${DRUPAL_VERSION:-10}-apache
build:
context: ../
dockerfile_inline: |
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-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 \
&& 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 \
&& composer update --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 vendor/bin/drush --yes site:install --db-url=sqlite://sites/default/files/.ht.sqlite?module=sqlite minimal -vvv

ports:
- 80
volumes:
Expand All @@ -13,10 +59,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
1 change: 0 additions & 1 deletion scripts/rector
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
Loading