From 48e5816873d7d14a072175b5a50b218351a015b9 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Thu, 29 Aug 2024 16:56:45 +0200 Subject: [PATCH 1/7] OEL-3328: Add minimum package dependencies. --- .drone.yml | 62 +++++++++++++++++++++++++++++++++++++ .editorconfig | 14 +++++++++ .github_changelog_generator | 1 + .gitignore | 4 +++ composer.json | 22 +++++++++++++ docker-compose.yml | 31 +++++++++++++++++++ 6 files changed, 134 insertions(+) create mode 100644 .drone.yml create mode 100644 .editorconfig create mode 100644 .github_changelog_generator create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..44b5861 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,62 @@ +clone: + git: + image: registry.fpfis.eu/drone-plugins/git:next + when: + event: [ push, pull_request, tag ] + git: + image: registry.fpfis.eu/drone-plugins/git + when: + event: [ deployment ] + +workspace: + base: /test + path: code-review-drupal + +services: + web: + image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci + environment: + - DOCUMENT_ROOT=/test/code-review-drupal + - COMPOSERVER=--2 + +pipeline: + composer-install-lowest: + group: prepare + image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci + volumes: + - /cache:/cache + commands: + - export COMPOSER=composer.dev.json + - composer self-update --2 + - composer update --prefer-lowest --ansi + when: + matrix: + COMPOSER_BOUNDARY: lowest + + composer-install-highest: + group: prepare + image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci + volumes: + - /cache:/cache + commands: + - export COMPOSER=composer.dev.json + - composer self-update --2 + - composer install --ansi + when: + matrix: + COMPOSER_BOUNDARY: highest + + grumphp: + group: test + image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci + commands: + - ./vendor/bin/grumphp run + +matrix: + COMPOSER_BOUNDARY: + - lowest + - highest + PHP_VERSION: + - 8.1 + - 8.2 + - 8.3 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..89e9e06 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Editor configuration normalization +# @see http://editorconfig.org/ + +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.github_changelog_generator b/.github_changelog_generator new file mode 100644 index 0000000..19e64ae --- /dev/null +++ b/.github_changelog_generator @@ -0,0 +1 @@ +release-branch=1.x diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3ec55b0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/vendor/ +composer.lock +grumphp.yml +docker-compose.*.yml diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1ccfe69 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "openeuropa/code-review-drupal", + "description": "OpenEuropa code review drupal component.", + "license": "EUPL-1.2", + "require": { + "php": ">=8.1", + "openeuropa/code-review": "OEL-3328-dev", + "drupal/coder": "^8.3.16", + "phpmd/phpmd": "^2.15", + "mglaman/phpstan-drupal": "^1.2", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan": "^1.12", + "phpstan/extension-installer": "^1.4" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpro/grumphp-shim": true, + "phpstan/extension-installer": true + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e08109f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,31 @@ +version: '2' +services: + web: + image: fpfis/httpd-php-dev:8.1 + working_dir: /var/www/html + ports: + - 8080:8080 + volumes: + - .:/var/www/html # Non Mac users. + # - nfsmount:/var/www/html # Mac Users with the nfsmount volume. + environment: + # Use Composer 2. + COMPOSERVER: "--2" + XDEBUG_CONFIG: "client_host=172.17.0.1" # Non-Mac users. + # XDEBUG_CONFIG: "client_host=host.docker.internal" # Mac users. + XDEBUG_MODE: "develop, debug" + PHP_IDE_CONFIG: "serverName=Docker" + # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. + # XDEBUG_SESSION: 1 + +#### Mac users: uncomment the "volumes" key to enable the NFS file sharing. You can find more information about Docker for Mac here: https://github.com/openeuropa/openeuropa/blob/master/docs/starting/tooling.md#using-docker-on-macos + +#volumes: +# nfsmount: +# driver: local +# driver_opts: +# type: nfs +# o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3 +# device: ":${PWD}/" + +#### End Mac users. From 47bcdf9e7a347ab7b9f5262084f0534ce70f392d Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 3 Sep 2024 17:21:02 +0200 Subject: [PATCH 2/7] OEL-3328: Drop unneeded files. --- .drone.yml | 62 ------------------------------------- .github_changelog_generator | 1 - .gitignore | 2 +- composer.json | 2 -- docker-compose.yml | 31 ------------------- 5 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 .drone.yml delete mode 100644 .github_changelog_generator delete mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 44b5861..0000000 --- a/.drone.yml +++ /dev/null @@ -1,62 +0,0 @@ -clone: - git: - image: registry.fpfis.eu/drone-plugins/git:next - when: - event: [ push, pull_request, tag ] - git: - image: registry.fpfis.eu/drone-plugins/git - when: - event: [ deployment ] - -workspace: - base: /test - path: code-review-drupal - -services: - web: - image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci - environment: - - DOCUMENT_ROOT=/test/code-review-drupal - - COMPOSERVER=--2 - -pipeline: - composer-install-lowest: - group: prepare - image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci - volumes: - - /cache:/cache - commands: - - export COMPOSER=composer.dev.json - - composer self-update --2 - - composer update --prefer-lowest --ansi - when: - matrix: - COMPOSER_BOUNDARY: lowest - - composer-install-highest: - group: prepare - image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci - volumes: - - /cache:/cache - commands: - - export COMPOSER=composer.dev.json - - composer self-update --2 - - composer install --ansi - when: - matrix: - COMPOSER_BOUNDARY: highest - - grumphp: - group: test - image: registry.fpfis.eu/fpfis/httpd-php:${PHP_VERSION}-ci - commands: - - ./vendor/bin/grumphp run - -matrix: - COMPOSER_BOUNDARY: - - lowest - - highest - PHP_VERSION: - - 8.1 - - 8.2 - - 8.3 diff --git a/.github_changelog_generator b/.github_changelog_generator deleted file mode 100644 index 19e64ae..0000000 --- a/.github_changelog_generator +++ /dev/null @@ -1 +0,0 @@ -release-branch=1.x diff --git a/.gitignore b/.gitignore index 3ec55b0..da3594e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /vendor/ composer.lock grumphp.yml -docker-compose.*.yml +phpstan.neon diff --git a/composer.json b/composer.json index 1ccfe69..1eb0adc 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,8 @@ "php": ">=8.1", "openeuropa/code-review": "OEL-3328-dev", "drupal/coder": "^8.3.16", - "phpmd/phpmd": "^2.15", "mglaman/phpstan-drupal": "^1.2", "phpstan/phpstan-deprecation-rules": "^1.2", - "phpstan/phpstan": "^1.12", "phpstan/extension-installer": "^1.4" }, "config": { diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index e08109f..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: '2' -services: - web: - image: fpfis/httpd-php-dev:8.1 - working_dir: /var/www/html - ports: - - 8080:8080 - volumes: - - .:/var/www/html # Non Mac users. - # - nfsmount:/var/www/html # Mac Users with the nfsmount volume. - environment: - # Use Composer 2. - COMPOSERVER: "--2" - XDEBUG_CONFIG: "client_host=172.17.0.1" # Non-Mac users. - # XDEBUG_CONFIG: "client_host=host.docker.internal" # Mac users. - XDEBUG_MODE: "develop, debug" - PHP_IDE_CONFIG: "serverName=Docker" - # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. - # XDEBUG_SESSION: 1 - -#### Mac users: uncomment the "volumes" key to enable the NFS file sharing. You can find more information about Docker for Mac here: https://github.com/openeuropa/openeuropa/blob/master/docs/starting/tooling.md#using-docker-on-macos - -#volumes: -# nfsmount: -# driver: local -# driver_opts: -# type: nfs -# o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3 -# device: ":${PWD}/" - -#### End Mac users. From be002c5d42632b520ff5ba1b318c0ef18ae50d39 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 3 Sep 2024 17:54:10 +0200 Subject: [PATCH 3/7] OEL-3328: Add conventions. --- dist/drupal-conventions.yml | 49 +++++++++++++++++++++++++++++++ dist/oe-component-conventions.yml | 19 ++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 dist/drupal-conventions.yml create mode 100644 dist/oe-component-conventions.yml diff --git a/dist/drupal-conventions.yml b/dist/drupal-conventions.yml new file mode 100644 index 0000000..19de2d0 --- /dev/null +++ b/dist/drupal-conventions.yml @@ -0,0 +1,49 @@ +imports: + - { resource: /vendor/openeuropa/code-review/dist/base-conventions.yml } + +grumphp: + + tasks: + + # PHP Code Sniffer. + phpcs: + standard: '%tasks.phpcs.standard%' + ignore_patterns: '%tasks.phpcs.ignore_patterns%' + triggered_by: '%tasks.phpcs.triggered_by%' + whitelist_patterns: '%tasks.phpcs.whitelist_patterns%' + warning_severity: '%tasks.phpcs.warning_severity%' + exclude: + - 'Drupal.Commenting.Deprecated' + metadata: + priority: 300 + + # PHP Stan. + phpstan: + autoload_file: '%tasks.phpstan.autoload_file%' + configuration: '%tasks.phpstan.configuration%' + level: '%tasks.phpstan.level%' + force_patterns: '%tasks.phpstan.force_patterns%' + ignore_patterns: '%tasks.phpstan.ignore_patterns%' + triggered_by: '%tasks.phpstan.triggered_by%' + memory_limit: "-1" + use_grumphp_paths: true + + # Commit message format. + git_commit_message: + matchers: '%tasks.git_commit_message.matchers%' + case_insensitive: false + enforce_no_subject_trailing_period: false + multiline: false + max_body_width: 0 + max_subject_width: 0 + +parameters: + drupal-conventions.triggered_by: + - php + - module + - inc + - theme + tasks.phpcs.standard: ./vendor/drupal/coder/coder_sniffer/Drupal + tasks.phpcs.triggered_by: '%drupal-conventions.triggered_by%' + tasks.phpstan.triggered_by: '%drupal-conventions.triggered_by%' + diff --git a/dist/oe-component-conventions.yml b/dist/oe-component-conventions.yml new file mode 100644 index 0000000..c9533c2 --- /dev/null +++ b/dist/oe-component-conventions.yml @@ -0,0 +1,19 @@ +imports: + - { resource: drupal-conventions.yml } + +parameters: + oe-component-conventions.triggerend_by: + - inc + - install + - module + - php + - theme + - yml + oe-component-conventions.ignore_patterns: + - build/ + - vendor/ + - node_modules/ + tasks.phpcs.triggered_by: '%oe-component-conventions.triggerend_by%' + tasks.phpcs.ignore_patterns: '%oe-component-conventions.ignore_patterns%' + tasks.phpstan.triggered_by: '%oe-component-conventions.triggerend_by%' + tasks.phpstan.ignore_patterns: '%oe-component-conventions.ignore_patterns%' From 6127500e8d019f12e311d2fa177de4f9fb860c82 Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Tue, 3 Sep 2024 18:16:45 +0200 Subject: [PATCH 4/7] OEL-3328: Fix gitignore. --- .gitignore | 1 - dist/drupal-conventions.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index da3594e..b798760 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /vendor/ composer.lock grumphp.yml -phpstan.neon diff --git a/dist/drupal-conventions.yml b/dist/drupal-conventions.yml index 19de2d0..a4751e7 100644 --- a/dist/drupal-conventions.yml +++ b/dist/drupal-conventions.yml @@ -46,4 +46,3 @@ parameters: tasks.phpcs.standard: ./vendor/drupal/coder/coder_sniffer/Drupal tasks.phpcs.triggered_by: '%drupal-conventions.triggered_by%' tasks.phpstan.triggered_by: '%drupal-conventions.triggered_by%' - From 3a34e9ed848c3b0d727a385517cbf6f36577969b Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 4 Sep 2024 13:15:24 +0200 Subject: [PATCH 5/7] OEL-3328: Fix path. --- dist/drupal-conventions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/drupal-conventions.yml b/dist/drupal-conventions.yml index a4751e7..a009860 100644 --- a/dist/drupal-conventions.yml +++ b/dist/drupal-conventions.yml @@ -1,5 +1,5 @@ imports: - - { resource: /vendor/openeuropa/code-review/dist/base-conventions.yml } + - { resource: ./vendor/openeuropa/code-review/dist/base-conventions.yml } grumphp: From 0b80715a8150d802371c19a0699a2d60c1cbad1c Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 4 Sep 2024 14:56:22 +0200 Subject: [PATCH 6/7] OEL-3328: Update documentation. --- CONVENTIONS.md | 30 +++++++++++++++++++ README.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 CONVENTIONS.md diff --git a/CONVENTIONS.md b/CONVENTIONS.md new file mode 100644 index 0000000..3c301e3 --- /dev/null +++ b/CONVENTIONS.md @@ -0,0 +1,30 @@ +# Conventions + +Information about conventions for OpenEuropa projects and components. + +## Available conventions + +These conventions can be used in your projects: + +* [Drupal](dist/drupal-conventions.yml) for Drupal projects. +* [OE Component](dist/oe-component-conventions.yml) for oe component projects. + +## PHP Code Sniffer + +- [Drupal coding standards](https://www.drupal.org/docs/develop/standards) + except: + - `Drupal.Commenting.Deprecated` because this rule only makes sense for core and projects in drupal.org. + +## PHP Stan + +- [mglaman/phpstan-drupal](https://github.com/mglaman/phpstan-drupal): allows to understand how to read code in a Drupal. +- [phpstan/phpstan-deprecation-rules](https://github.com/phpstan/phpstan-deprecation-rules): this extension emits deprecation warnings on code. +- [phpstan/extension-installer](https://github.com/phpstan/extension-installer): package autoconfigures PHPStan to load the previous packages. + +## Commit messages + +Valid default commit messages: `Issue #123: My commit.` or `OPENEUROPA-123: My commit.` + +- Must start with GitHub issue reference or a Jira-like ticket ID. +- Must have a colon followed by a space after the issue reference. +- Must start with capital letter and end with a period. diff --git a/README.md b/README.md index 296df09..39004eb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,80 @@ # code-review-drupal +[![Packagist](https://img.shields.io/packagist/v/openeuropa/code-review-drupal.svg)](https://packagist.org/packages/openeuropa/code-review-drupal) + Coding standard dependencies for Drupal components. + +### Installation +Install the code review component via Composer: + +```bash +composer require --dev openeuropa/code-review-drupal +``` + +In your project root create the following `grumphp.yml.dist`: + +```yaml +imports: + - { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } +``` + +### Commands + +GrumPHP tasks will be run at every commit, if you wish to run them without performing a commit use the following command: + +```bash +./vendor/bin/grumphp run +``` + +If you want to simulate the tasks that will be run when creating a new commit: + +```bash +./vendor/bin/grumphp git:pre-commit +``` + +Check [GrumPHP documentation](https://github.com/phpro/grumphp/tree/master/doc) for more. + +### Customization + +This component offers a variety of ready conventions that all projects need to follow. +This list of default conventions can be found in [CONVENTIONS.md](CONVENTIONS.md). + +Since GrumPHP uses the [Symfony Dependency Injection component](http://symfony.com/doc/current/components/dependency_injection.html) +you can override specific parameters in your project's `grumphp.yml.dist` file as follows: + +```yaml +imports: + - { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } + +parameters: + tasks.git_commit_message.matchers: ['/^JIRA-\d+: [A-Z].+\./'] +``` + +Below the list of task parameters can that be overridden on a per-project basis: + +- `tasks.phpcs.standard` +- `tasks.phpcs.ignore_patterns` +- `tasks.phpcs.triggered_by` +- `tasks.phpcs.whitelist_patterns` +- `tasks.phpcs.warning_severity` +- `tasks.phpstan.autoload_file` +- `tasks.phpstan.configuration` +- `tasks.phpstan.level` +- `tasks.phpstan.force_patterns` +- `tasks.phpstan.triggered_by` +- `tasks.git_commit_message.matchers` + +It is also possible to extend the list of tasks to be run by adding tasks under the `tasks:` tree as shown below: + +```yaml +imports: + - { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } + +grumphp: + tasks: + phpparser: ~ +``` + +GrumPHP already has a series of tasks that can be used out of the box, you can find the complete list in the +[GrumPHP tasks page](https://github.com/phpro/grumphp/blob/v2.x/doc/tasks.md). + +If you wih you can create your own tasks as explained in the [GrumPHP extensions page](https://github.com/phpro/grumphp/blob/v2.x/doc/extensions.md). From e184c0a5d2e41655c44c51fb2edace4626fc50eb Mon Sep 17 00:00:00 2001 From: AaronGilMartinez Date: Wed, 4 Sep 2024 16:10:33 +0200 Subject: [PATCH 7/7] OEL-3328: Add transition documentation. --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index 39004eb..2ca0b1b 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,39 @@ GrumPHP already has a series of tasks that can be used out of the box, you can f [GrumPHP tasks page](https://github.com/phpro/grumphp/blob/v2.x/doc/tasks.md). If you wih you can create your own tasks as explained in the [GrumPHP extensions page](https://github.com/phpro/grumphp/blob/v2.x/doc/extensions.md). + +### Transition from code-review 2.x + +If you wish to transition to code-review-drupal from code-review version 2.x, please replace the package via Composer: + +```bash +composer remove --dev openeuropa/code-review +composer require --dev openeuropa/code-review-drupal +``` + +Besides replacement of the package, some adjustments are needed in `grumphp.yml` file. + +This component removes ExtraTasks extension. Any aditional task previously declared in `extra_tasks` will need to be placed inside `tasks` under `grumphp` tree. + +```diff yaml + +- extra_tasks: +- phpparser: +- ignore_patterns: +- - vendor/ +- +- grumphp: +- extensions: +- - OpenEuropa\CodeReview\ExtraTasksExtension + ++ grumphp: ++ tasks: ++ phpparser: ++ ignore_patterns: ++ - vendor/ + +``` + +In addition, PHP Mess Detector is no longer available as part of the configured tasks. The task and related parameters have been removed. If you wish to continue using PHP Mess Detector, you can add it as part of GrumPHP as previously described. + +All other conventions and parameters remain the same.