diff --git a/CHANGELOG.md b/CHANGELOG.md index d68152a..08d0862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [PR-108](https://github.com/itk-dev/devops_itkdev-docker/pull/108) + Added Drupal module template + ### Changed - Updated to PHP 8.3 diff --git a/config/drupal-module/php/.phpcs.xml.dist b/config/drupal-module/php/.phpcs.xml.dist new file mode 100644 index 0000000..a97dd83 --- /dev/null +++ b/config/drupal-module/php/.phpcs.xml.dist @@ -0,0 +1,31 @@ + + + + + + The coding standard. + + . + + + node_modules + vendor + *.css + *.js + + + + + + + + + + + + + + + + + diff --git a/config/drupal-module/twig/.twig-cs-fixer.dist.php b/config/drupal-module/twig/.twig-cs-fixer.dist.php new file mode 100644 index 0000000..35cf531 --- /dev/null +++ b/config/drupal-module/twig/.twig-cs-fixer.dist.php @@ -0,0 +1,16 @@ +in(__DIR__); +// … that are not ignored by VCS +$finder->ignoreVCSIgnored(true); + +$config = new TwigCsFixer\Config\Config(); +$config->setFinder($finder); + +return $config; diff --git a/docs/github-actions-templates.md b/docs/github-actions-templates.md index de4e388..e83b81f 100644 --- a/docs/github-actions-templates.md +++ b/docs/github-actions-templates.md @@ -1,6 +1,6 @@ @@ -61,6 +61,65 @@ Validates composer.json and checks that it's normalized. --- +[github/workflows/drupal-module/javascript.yaml](github/workflows/drupal-module/javascript.yaml) + +### Drupal module JavaScript (and TypeScript) + +Validates JavaScript files. + +#### Assumptions + +1. A docker compose service named `prettier` for running + [Prettier](https://prettier.io/) exists. + +--- + +[github/workflows/drupal-module/php.yaml](github/workflows/drupal-module/php.yaml) + +### Drupal module PHP + +Checks that PHP code adheres to the [Drupal coding +standards](https://www.drupal.org/docs/develop/standards). + +#### Assumptions + +1. A docker compose service named `phpfpm` can be run and `composer` can be + run inside the `phpfpm` service. +2. [drupal/coder](https://www.drupal.org/project/coder) is a dev requirement +in `composer.json`: + + ``` shell + docker compose run --rm phpfpm composer require --dev drupal/coder + ``` + + Clean up and check code by running + + ``` shell + docker compose run --rm phpfpm vendor/bin/phpcbf + docker compose run --rm phpfpm vendor/bin/phpcs + ``` + +> [!NOTE] +> The template adds `.phpcs.xml.dist` as [a configuration file for +> PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) +> and this makes it possible to override the actual configuration used in a +> project by adding a more important configuration file, e.g. `.phpcs.xml`. + +--- + +[github/workflows/drupal-module/styles.yaml](github/workflows/drupal-module/styles.yaml) + +### Drupal module Styles (CSS and SCSS) + +Validates styles files. + +#### Assumptions + +1. A docker compose service named `prettier` for running + [Prettier](https://prettier.io/) exists. + +--- + [github/workflows/drupal/javascript.yaml](github/workflows/drupal/javascript.yaml) ### Drupal JavaScript (and TypeScript) diff --git a/github/workflows/drupal-module/javascript.yaml b/github/workflows/drupal-module/javascript.yaml new file mode 100644 index 0000000..54ef6e2 --- /dev/null +++ b/github/workflows/drupal-module/javascript.yaml @@ -0,0 +1,36 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/drupal-module/javascript.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Drupal module JavaScript (and TypeScript) +### +### Validates JavaScript files. +### +### #### Assumptions +### +### 1. A docker compose service named `prettier` for running +### [Prettier](https://prettier.io/) exists. + +name: JavaScript + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + javascript-lint: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v4 + + - run: | + docker network create frontend + + - run: | + docker compose run --rm prettier 'js/**/*.js' --check diff --git a/github/workflows/drupal-module/php.yaml b/github/workflows/drupal-module/php.yaml new file mode 100644 index 0000000..4218f4d --- /dev/null +++ b/github/workflows/drupal-module/php.yaml @@ -0,0 +1,55 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/drupal-module/php.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Drupal module PHP +### +### Checks that PHP code adheres to the [Drupal coding +### standards](https://www.drupal.org/docs/develop/standards). +### +### #### Assumptions +### +### 1. A docker compose service named `phpfpm` can be run and `composer` can be +### run inside the `phpfpm` service. +### 2. [drupal/coder](https://www.drupal.org/project/coder) is a dev requirement +### in `composer.json`: +### +### ``` shell +### docker compose run --rm phpfpm composer require --dev drupal/coder +### ``` +### +### Clean up and check code by running +### +### ``` shell +### docker compose run --rm phpfpm vendor/bin/phpcbf +### docker compose run --rm phpfpm vendor/bin/phpcs +### ``` +### +### > [!NOTE] +### > The template adds `.phpcs.xml.dist` as [a configuration file for +### > PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) +### > and this makes it possible to override the actual configuration used in a +### > project by adding a more important configuration file, e.g. `.phpcs.xml`. + +name: PHP + +env: + COMPOSE_USER: root + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + coding-standards: + name: PHP - Check Coding Standards + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: | + docker network create frontend + docker compose run --rm phpfpm composer install + docker compose run --rm phpfpm vendor/bin/phpcs diff --git a/github/workflows/drupal-module/styles.yaml b/github/workflows/drupal-module/styles.yaml new file mode 100644 index 0000000..0d5cdc0 --- /dev/null +++ b/github/workflows/drupal-module/styles.yaml @@ -0,0 +1,36 @@ +# Do not edit this file! Make a pull request on changing +# github/workflows/drupal-module/styles.yaml in +# https://github.com/itk-dev/devops_itkdev-docker if need be. + +### ### Drupal module Styles (CSS and SCSS) +### +### Validates styles files. +### +### #### Assumptions +### +### 1. A docker compose service named `prettier` for running +### [Prettier](https://prettier.io/) exists. + +name: Styles + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + styles-lint: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v4 + + - run: | + docker network create frontend + + - run: | + docker compose run --rm prettier 'css/**/*.css' --check diff --git a/task/scripts/github-actions-link b/task/scripts/github-actions-link index 5b71f4c..e7ec275 100755 --- a/task/scripts/github-actions-link +++ b/task/scripts/github-actions-link @@ -11,8 +11,8 @@ cd "$project_dir" || exit function strip-project-type() { name=$1 - if [[ "$name" =~ ^(drupal|symfony)/(.+) ]]; then - name="${BASH_REMATCH[2]}" + if [[ "$name" =~ ^(drupal(-module)?|symfony)/(.+) ]]; then + name="${BASH_REMATCH[3]}" fi echo "$name" @@ -27,7 +27,9 @@ for template_dir in templates/*; do echo project_type="" - if [[ "$template_name" =~ ^drupal- ]]; then + if [[ "$template_name" =~ ^drupal-module ]]; then + project_type="drupal-module" + elif [[ "$template_name" =~ ^drupal- ]]; then project_type="drupal" elif [[ "$template_name" =~ ^symfony- ]]; then project_type="symfony" @@ -39,7 +41,11 @@ for template_dir in templates/*; do for f in $(find github/workflows/ -name '*.yaml' | sort); do source_file_name='' # Note: / is NOT a regex delimiter here, but an actual /, i.e. a directory separator. - if [[ "$f" =~ /drupal/ ]]; then + if [[ "$f" =~ /drupal-module/ ]]; then + if [[ "$project_type" == "drupal-module" ]]; then + source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")" + fi + elif [[ "$f" =~ /drupal/ ]]; then if [[ "$project_type" == "drupal" ]]; then source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")" fi diff --git a/templates/drupal-module/.github/workflows/changelog.yaml b/templates/drupal-module/.github/workflows/changelog.yaml new file mode 120000 index 0000000..5ffe5c3 --- /dev/null +++ b/templates/drupal-module/.github/workflows/changelog.yaml @@ -0,0 +1 @@ +../../../../github/workflows/changelog.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/composer.yaml b/templates/drupal-module/.github/workflows/composer.yaml new file mode 120000 index 0000000..2395564 --- /dev/null +++ b/templates/drupal-module/.github/workflows/composer.yaml @@ -0,0 +1 @@ +../../../../github/workflows/composer.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/javascript.yaml b/templates/drupal-module/.github/workflows/javascript.yaml new file mode 120000 index 0000000..09fb93c --- /dev/null +++ b/templates/drupal-module/.github/workflows/javascript.yaml @@ -0,0 +1 @@ +../../../../github/workflows/drupal-module/javascript.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/markdown.yaml b/templates/drupal-module/.github/workflows/markdown.yaml new file mode 120000 index 0000000..ab3eafa --- /dev/null +++ b/templates/drupal-module/.github/workflows/markdown.yaml @@ -0,0 +1 @@ +../../../../github/workflows/markdown.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/php.yaml b/templates/drupal-module/.github/workflows/php.yaml new file mode 120000 index 0000000..405a186 --- /dev/null +++ b/templates/drupal-module/.github/workflows/php.yaml @@ -0,0 +1 @@ +../../../../github/workflows/drupal-module/php.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/styles.yaml b/templates/drupal-module/.github/workflows/styles.yaml new file mode 120000 index 0000000..31ec030 --- /dev/null +++ b/templates/drupal-module/.github/workflows/styles.yaml @@ -0,0 +1 @@ +../../../../github/workflows/drupal-module/styles.yaml \ No newline at end of file diff --git a/templates/drupal-module/.github/workflows/twig.yaml b/templates/drupal-module/.github/workflows/twig.yaml new file mode 120000 index 0000000..649f1cd --- /dev/null +++ b/templates/drupal-module/.github/workflows/twig.yaml @@ -0,0 +1 @@ +../../../../github/workflows/twig.yaml \ No newline at end of file diff --git a/templates/drupal-module/.markdownlint.jsonc b/templates/drupal-module/.markdownlint.jsonc new file mode 120000 index 0000000..1a3d9af --- /dev/null +++ b/templates/drupal-module/.markdownlint.jsonc @@ -0,0 +1 @@ +../../config/markdown/.markdownlint.jsonc \ No newline at end of file diff --git a/templates/drupal-module/.markdownlintignore b/templates/drupal-module/.markdownlintignore new file mode 120000 index 0000000..0a61367 --- /dev/null +++ b/templates/drupal-module/.markdownlintignore @@ -0,0 +1 @@ +../../config/markdown/.markdownlintignore \ No newline at end of file diff --git a/templates/drupal-module/.phpcs.xml.dist b/templates/drupal-module/.phpcs.xml.dist new file mode 120000 index 0000000..040c94d --- /dev/null +++ b/templates/drupal-module/.phpcs.xml.dist @@ -0,0 +1 @@ +../../config/drupal-module/php/.phpcs.xml.dist \ No newline at end of file diff --git a/templates/drupal-module/.twig-cs-fixer.dist.php b/templates/drupal-module/.twig-cs-fixer.dist.php new file mode 120000 index 0000000..3f9471f --- /dev/null +++ b/templates/drupal-module/.twig-cs-fixer.dist.php @@ -0,0 +1 @@ +../../config/drupal-module/twig/.twig-cs-fixer.dist.php \ No newline at end of file diff --git a/templates/drupal-module/docker-compose.yml b/templates/drupal-module/docker-compose.yml new file mode 100644 index 0000000..cb456c1 --- /dev/null +++ b/templates/drupal-module/docker-compose.yml @@ -0,0 +1,19 @@ +# itk-version: 3.2.3 + +services: + phpfpm: + image: itkdev/php8.4-fpm:latest + user: ${COMPOSE_USER:-deploy} + volumes: + - .:/app + + prettier: + # Prettier does not (yet, fcf. + # https://github.com/prettier/prettier/issues/15206) have an official + # docker image. + # https://hub.docker.com/r/jauderho/prettier is good candidate (cf. https://hub.docker.com/search?q=prettier&sort=updated_at&order=desc) + image: jauderho/prettier + profiles: + - dev + volumes: + - ./:/work