Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions config/drupal-module/php/.phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!-- This file is copied from config/drupal-module/php/.phpcs.xml.dist in https://github.com/itk-dev/devops_itkdev-docker. -->
<!-- Feel free to edit the file, but consider making a pull request if you find a general issue with the file. -->

<ruleset name="PHP_CodeSniffer">
<description>The coding standard.</description>

<file>.</file>

<!-- Exclude generated files -->
<exclude-pattern>node_modules</exclude-pattern>
<exclude-pattern>vendor</exclude-pattern>
<exclude-pattern>*.css</exclude-pattern>
<exclude-pattern>*.js</exclude-pattern>

<arg value="p"/>

<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>

<config name="drupal_core_version" value="11"/>

<rule ref="Drupal">
<!-- <exclude name="Drupal.Files.TxtFileLineLength.TooLong"/> -->
<!-- We want to be able to use "package" and "version" in our custom modules -->
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
<exclude name="Drupal.NamingConventions.ValidEnumCase.NoUpperAcronyms" />
<exclude name="Drupal.NamingConventions.ValidEnumCase.NoUnderscores" />
</rule>
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
</ruleset>
16 changes: 16 additions & 0 deletions config/drupal-module/twig/.twig-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
// This file is copied from config/drupal-module/twig/.twig-cs-fixer.dist.php in https://github.com/itk-dev/devops_itkdev-docker.
// Feel free to edit the file, but consider making a pull request if you find a general issue with the file.

// https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md#configuration-file

$finder = new TwigCsFixer\File\Finder();
// Check all files …
$finder->in(__DIR__);
// … that are not ignored by VCS
$finder->ignoreVCSIgnored(true);

$config = new TwigCsFixer\Config\Config();
$config->setFinder($finder);

return $config;
61 changes: 60 additions & 1 deletion docs/github-actions-templates.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- DO NOT EDIT THIS FILE!

It was automatically created at 2025-05-09T09:39:45+02:00
It was automatically created at 2025-05-20T13:49:11+02:00
by task/scripts/github-documentation-update
based on /app/task/scripts/../templates/github-actions-templates.md
-->
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions github/workflows/drupal-module/javascript.yaml
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions github/workflows/drupal-module/php.yaml
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions github/workflows/drupal-module/styles.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 10 additions & 4 deletions task/scripts/github-actions-link
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/changelog.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/composer.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/javascript.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/markdown.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/php.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/styles.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.github/workflows/twig.yaml
1 change: 1 addition & 0 deletions templates/drupal-module/.markdownlint.jsonc
1 change: 1 addition & 0 deletions templates/drupal-module/.markdownlintignore
1 change: 1 addition & 0 deletions templates/drupal-module/.phpcs.xml.dist
1 change: 1 addition & 0 deletions templates/drupal-module/.twig-cs-fixer.dist.php
19 changes: 19 additions & 0 deletions templates/drupal-module/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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