Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build pipeline fix, drop Drupal <10.1 support, flag PHP 8.2 support #100

Merged
merged 5 commits into from
Apr 19, 2024
Merged
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
6 changes: 3 additions & 3 deletions .dev/.ci/check-cs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -e

if [[ ${CHECK_CS} == true ]]; then
docker-compose exec -T php composer normalize -d .. --no-update-lock --dry-run
docker compose exec -T php composer normalize -d .. --no-update-lock --dry-run
# @TODO There is a weird file access issue on GHA.
# Drupal QA: Unable to set 511 visibility for file at /mnt/files/local_mount.
docker-compose exec -T php ./vendor/bin/phpcs -s ./vendor/pronovix/drupal-qa/config/phpcs.xml.dist --ignore="contrib/*,*/build/*" web/modules
docker-compose exec -T php ./vendor/bin/phpstan --no-progress
docker compose exec -T php ./vendor/bin/phpcs -s ./vendor/pronovix/drupal-qa/config/phpcs.xml.dist --ignore="contrib/*,*/build/*" web/modules
docker compose exec -T php ./vendor/bin/phpstan --no-progress
fi
14 changes: 7 additions & 7 deletions .dev/.ci/init-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ set -e

# Lock Drupal core to the expected major version.
if [[ -n "${DRUPAL_CORE}" ]]; then
docker-compose exec php composer require -d .. --no-update drupal/core:${DRUPAL_CORE}
docker compose exec php composer require -d .. --no-update drupal/core:${DRUPAL_CORE}
fi
# We need to run both "install" and "update" commands because:
# * `--prefer-lowest` is not supported by "install".
# * it seems there is an issue with the merge plugin and because of that if we would only run
# `composer update --prefer-lowest` then incorrect lower versions could be installed, ex.: drupal/core:8.5.0 where
# there is a drupal/core: ^8.7 constraint.
docker-compose exec php composer install -d .. ${COMPOSER_GLOBAL_OPTIONS}
docker compose exec php composer install -d .. ${COMPOSER_GLOBAL_OPTIONS}
if [[ -n "${DEPENDENCIES}" ]]; then
# Avoid failing builds caused by "Source directory /mnt/files/local_mount/build/vendor/drupal/coder has uncommitted changes.".
docker-compose exec php composer config -d .. --global discard-changes true
docker-compose exec php composer update -d .. ${COMPOSER_GLOBAL_OPTIONS} ${DEPENDENCIES} -n --with-dependencies
docker compose exec php composer config -d .. --global discard-changes true
docker compose exec php composer update -d .. ${COMPOSER_GLOBAL_OPTIONS} ${DEPENDENCIES} -n --with-dependencies
else
# Ensure Drupal coding standard is registered.
# TODO Check why it gets immediately unregistered after it has been registered
# Error:
# PHP CodeSniffer Config installed_paths set to ../../drupal/coder/coder_sniffer
# PHP CodeSniffer Config installed_paths delete
docker-compose exec php composer update -d .. none
docker compose exec php composer update -d .. none
fi
# Log the installed versions.
docker-compose exec php composer --version
docker-compose exec php composer show -d .. -f json
docker compose exec php composer --version
docker compose exec php composer show -d .. -f json

sudo chown -R travis:travis .
ln -s ../../../../drupal-dev/drupal/settings.php build/web/sites/default/settings.php
Expand Down
2 changes: 1 addition & 1 deletion .dev/.ci/run-phpunit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ set -e
if [[ ${RUN_PHPUNIT_TESTS} == true ]]; then
# Custom bootstrap file is required to prevent infinite loop caused by symlinking that Drupal's original
# bootstrap file cannot handle.
docker-compose run --rm php ./vendor/bin/phpunit -c web/core -v --debug --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter' --bootstrap=vendor/pronovix/drupal-qa/src/Drupal/PhpUnit/bootstrap.php web/modules/drupal_module/tests/
docker compose run --rm php ./vendor/bin/phpunit -c web/core -v --debug --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter' --bootstrap=/mnt/files/local_mount/tests/src/bootstrap.php web/modules/drupal_module/tests/
fi
28 changes: 17 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
env:
PHP_IMAGE: "wodby/drupal-php:8.1-dev"
run: |
docker-compose pull --quiet
docker-compose up -d --build
docker compose pull --quiet
docker compose up -d --build

- name: Install dependencies
run: |
chmod a+rw .
docker-compose exec -T php composer install --no-interaction --no-suggest --no-progress -d ..
docker compose exec -T php composer install --no-interaction --no-suggest --no-progress -d ..

- name: Run code style check
run: CHECK_CS="true" ./.dev/.ci/check-cs.sh
Expand All @@ -48,10 +48,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php_image: ["wodby/drupal-php:8.1-dev"]
php_image: ["wodby/drupal-php:8.1-dev", "wodby/drupal-php:8.2-dev"]
db_image: ["wodby/mariadb:10.5"]
# TODO Get version range from composer.json dynamically.
drupal_version: ["~9.4.0", "~9.5.0", "^10.0"]
drupal_version: ["^10.1"]
lowest_highest: ["--prefer-lowest", ""]

steps:
Expand All @@ -64,6 +64,12 @@ jobs:
repository: Pronovix/docker-drupal-dev
path: ./drupal-dev

# TODO Remove this after Drupal QA got a PHP 8.2 compatible release.
- name: Drupal QA workaround
if: matrix.php_image == 'wodby/drupal-php:8.2-dev'
run: |
export COMPOSER_IGNORE_PLATFORM_REQ=php+

- name: Setup environment
run: |
mkdir build
Expand All @@ -77,19 +83,19 @@ jobs:
PHP_IMAGE: ${{ matrix.php_image }}
DB_IMAGE: ${{ matrix.db_image }}
run: |
docker-compose pull --quiet
docker-compose up -d --build
docker compose pull --quiet
docker compose up -d --build

- name: Install dependencies
run: |
chmod a+rw .
docker-compose exec -T php composer install --no-interaction --no-suggest --no-progress -d ..
docker compose exec -T php composer install --no-interaction --no-suggest --no-progress -d ..
chmod a+rw composer.json
docker-compose exec -T php composer require drupal/core:${{ matrix.drupal_version }} drupal/core-dev:${{ matrix.drupal_version }} drupal/core-recommended:${{ matrix.drupal_version }} drupal/core-composer-scaffold:${{ matrix.drupal_version }} --no-update -d ..
docker-compose exec --env COMPOSER_DISCARD_CHANGES=true -T php composer update --no-progress ${{ matrix.lowest_highest }} -d ..
docker compose exec -T php composer require drupal/core:${{ matrix.drupal_version }} drupal/core-dev:${{ matrix.drupal_version }} drupal/core-recommended:${{ matrix.drupal_version }} drupal/core-composer-scaffold:${{ matrix.drupal_version }} --no-update -d ..
docker compose exec --env COMPOSER_DISCARD_CHANGES=true -T php composer update --no-progress ${{ matrix.lowest_highest }} -d ..

- name: List installed dependencies
run: docker-compose exec -T php composer show -d ..
run: docker compose exec -T php composer show -d ..

- name: Set up Drupal settings files
run: |
Expand Down
20 changes: 10 additions & 10 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ $ git clone https://github.com/Pronovix/docker-drupal-dev.git drupal-dev
$ mkdir build;
$ ln -s drupal-dev/docker-compose.yml
$ ln -s drupal-dev/Dockerfile
$ printf "COMPOSE_PROJECT_NAME=swagger_ui_formatter\nPHP_IMAGE=wodby/drupal-php:7.4-dev\n#You can find examples for available customization in the drupal-dev/examples/.env file.\n" > .env && source .env
$ docker-compose up -d --build
$ docker-compose exec php composer install
$ printf "COMPOSE_PROJECT_NAME=swagger_ui_formatter\n#You can find examples for available customization in the drupal-dev/examples/.env file.\n" > .env && source .env
$ docker compose up -d --build
$ docker compose exec php composer install
$ ln -s ../../../../drupal-dev/drupal/settings.php build/web/sites/default/settings.php
$ ln -s ../../../../drupal-dev/drupal/settings.shared.php build/web/sites/default/settings.shared.php
$ ln -s ../../../../drupal-dev/drupal/settings.testing.php build/web/sites/default/settings.testing.php
$ ln -s ../../../drupal-dev/drupal/development.services.yml.dist build/web/sites/development.services.yml.dist
$ docker-compose exec php drush si -y
$ docker-compose exec php drush en swagger_ui_formatter -y
$ docker compose exec php vendor/bin/drush si -y
$ docker compose exec php vendor/bin/drush en swagger_ui_formatter -y
```

## QA

### Code-style checks

```sh
$ docker-compose exec php composer normalize --indent-size=4 --indent-style=space --no-update-lock
$ docker-compose exec php ./vendor/bin/phpcbf -s ../phpcs.xml.dist --ignore="contrib/*" web/modules
$ docker-compose exec php ./vendor/bin/phpcs -s ../phpcs.xml.dist --ignore="contrib/*" web/modules
$ docker-compose exec php ./vendor/bin/drupal-check --drupal-root=. -e "*/build/*" ..
$ docker compose exec php composer normalize --indent-size=4 --indent-style=space --no-update-lock
$ docker compose exec php ./vendor/bin/phpcbf -s ../phpcs.xml.dist --ignore="contrib/*" web/modules
$ docker compose exec php ./vendor/bin/phpcs -s ../phpcs.xml.dist --ignore="contrib/*" web/modules
$ docker compose exec php ./vendor/bin/phpstan --no-progress ..
```

### Running tests

```sh
$ docker-compose run --rm php ./vendor/bin/phpunit -c web/core -v --debug --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter' --bootstrap=vendor/pronovix/drupal-qa/src/Drupal/PhpUnit/bootstrap.php web/modules/drupal_module/tests/
$ docker compose run --rm php ./vendor/bin/phpunit -c web/core -v --debug --printer '\Drupal\Tests\Listeners\HtmlOutputPrinter' --bootstrap=/mnt/files/local_mount/tests/src/bootstrap.php web/modules/drupal_module/tests/
```
41 changes: 25 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
"league/container version contraint is here to prevent randomy failed highest-lowest tests caused by this missing fix: https://github.com/thephpleague/container/commit/97a0c39bf37d709d3bbc31d0505cea9373d927e7"
],
"require": {
"php": "~8.1.0",
"drupal/core": "^9.4 || ^10.0"
"php": "~8.1.0 || ~8.2.0",
"drupal/core": "^10.1"
},
"require-dev": {
"bower-asset/swagger-ui": "^4.15.0",
"composer/installers": "^v2.2.0",
"drupal/core-composer-scaffold": "^9.4 || ^10.0.0",
"drupal/core-dev": "^9.4 || ^10.0.0",
"drupal/core-recommended": "^9.4 || ^10.0.0",
"drupal/devel": "^5.1.1",
"league/container": "<4.0.0 || >=4.1.1",
"pronovix/drupal-qa": "^3.11.1",
"pronovix/simple-symlink": "^3.11.1",
"bower-asset/swagger-ui": "^4.17.0",
"composer/installers": "^2.2.0",
"drupal/core-composer-scaffold": "^10.1",
"drupal/core-dev": "^10.1",
"drupal/core-recommended": "^10.1",
"drupal/devel": "^5.2.1",
"league/container": "<4.0.0 || >=4.2.2",
"pronovix/drupal-qa": "^4",
"zaporylie/composer-drupal-optimizations": "^1.2"
},
"repositories": [
Expand Down Expand Up @@ -60,15 +59,19 @@
"config": {
"allow-plugins": {
"composer/installers": true,
"drupal/core-composer-scaffold": true,
"cweagans/composer-patches": true,
"zaporylie/composer-drupal-optimizations": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true,
"ergebnis/composer-normalize": true,
"php-http/discovery": false,
"phpstan/extension-installer": false,
"pronovix/drupal-qa": true,
"phpstan/extension-installer": false
"zaporylie/composer-drupal-optimizations": true
},
"optimize-autoloader": true,
"platform": {
"php": "8.1.6"
},
"sort-packages": true,
"vendor-dir": "build/vendor"
},
Expand Down Expand Up @@ -139,10 +142,16 @@
},
"scripts": {
"post-install-cmd": [
"Pronovix\\SimpleSymlink\\ScriptHandler::createSymlinks"
"@symlink-for-local-dev-env"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a replacement of pronovix/simple-symlink

],
"post-update-cmd": [
"Pronovix\\SimpleSymlink\\ScriptHandler::createSymlinks"
"@symlink-for-local-dev-env"
],
"symlink-for-local-dev-env": [
"@php -r \"@symlink('../../..', 'build/web/modules/drupal_module');\"",
"@php -r \"@symlink('../phpcs.xml.dist', 'build/phpcs.xml.dist');\"",
"@php -r \"@symlink('../phpstan-baseline.neon', 'build/phpstan-baseline.neon');\"",
"@php -r \"@symlink('../phpstan.neon.dist', 'build/phpstan.neon.dist');\""
]
}
}
24 changes: 23 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
parameters:
ignoreErrors: []
ignoreErrors:
-
message: """
#^Call to method __construct\\(\\) of deprecated class Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterIterator\\:
in drupal\\:10\\.2\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use
\\\\Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterCallback instead\\.$#
"""
count: 1
path: ../tests/src/DrupalExtensionFilterIterator.php

-
message: """
#^Class Drupal\\\\Tests\\\\swagger_ui_formatter\\\\DrupalExtensionFilterIterator extends deprecated class Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterIterator\\:
in drupal\\:10\\.2\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use
\\\\Drupal\\\\Core\\\\Extension\\\\Discovery\\\\RecursiveExtensionFilterCallback instead\\.$#
"""
count: 1
path: ../tests/src/DrupalExtensionFilterIterator.php

-
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(string\\|false\\)\\: bool\\)\\|null, 'file_exists' given\\.$#"
count: 1
path: ../tests/src/bootstrap.php
51 changes: 51 additions & 0 deletions tests/src/DrupalExtensionFilterIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* Forked version of a removed solution from Pronovix/drupal-qa.
* @see https://github.com/Pronovix/drupal-qa/commit/5f1bf60dfe2b78de7a5a69baee3f7db61edf1b51.
*/

namespace Drupal\Tests\swagger_ui_formatter;

use Drupal\Core\Extension\Discovery\RecursiveExtensionFilterIterator as DrupalRecursiveExtensionFilterIterator;

/**
* Improved version of Drupal's RecursiveExtensionFilterIterator for PHPUnit.
*
* This class and bootstrap.php was created to be able to run PHPUnit tests in
* setups where modules, themes or profiles may contain a "build" folder with
* a Drupal core and a symlink that to themselves which could lead to infinite
* recursions when the original PHPUnit bootstrap script tries to discovery
* available tests.
*
* Example structure:
* ├── build
* │   └── web
* │   ├── core
* │   ├── index.php
* │   ├── modules
* │   | ├── drupal_module -> ../../../
* └── my_module.info.yml
*
* Related issues on Drupal.org:
* https://www.drupal.org/project/drupal/issues/2943172
* https://www.drupal.org/project/drupal/issues/3050881
*/
final class DrupalExtensionFilterIterator extends DrupalRecursiveExtensionFilterIterator
{
/**
* DrupalExtensionFilterIterator constructor.
*
* @param \RecursiveIterator $iterator
* The iterator to filter.
*/
public function __construct(\RecursiveIterator $iterator)
{
// We should not initialize Settings here to retrieve
// `file_scan_ignore_directories` here although that would remove some
// code duplications.
parent::__construct($iterator, ['build', 'node_modules', 'bower_components']);
}
}
Loading
Loading