Skip to content

Commit 7c03f6d

Browse files
committed
Added Drupal module template
1 parent c01409a commit 7c03f6d

19 files changed

+293
-5
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<!-- This file is copied from config/drupal/php/.phpcs.xml.dist in https://github.com/itk-dev/devops_itkdev-docker. -->
3+
<!-- Feel free to edit the file, but consider making a pull request if you find a general issue with the file. -->
4+
5+
<ruleset name="PHP_CodeSniffer">
6+
<description>The coding standard.</description>
7+
8+
<file>.</file>
9+
10+
<!-- Exclude generated files -->
11+
<exclude-pattern>node_modules</exclude-pattern>
12+
<exclude-pattern>vendor</exclude-pattern>
13+
<exclude-pattern>*.css</exclude-pattern>
14+
<exclude-pattern>*.js</exclude-pattern>
15+
16+
<arg value="p"/>
17+
18+
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
19+
20+
<config name="drupal_core_version" value="11"/>
21+
22+
<rule ref="Drupal">
23+
<!-- <exclude name="Drupal.Files.TxtFileLineLength.TooLong"/> -->
24+
<!-- We want to be able to use "package" and "version" in our custom modules -->
25+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
26+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
27+
<exclude name="Drupal.NamingConventions.ValidEnumCase.NoUpperAcronyms" />
28+
<exclude name="Drupal.NamingConventions.ValidEnumCase.NoUnderscores" />
29+
</rule>
30+
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
31+
</ruleset>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// This file is copied from config/drupal/twig/.twig-cs-fixer.dist.php in https://github.com/itk-dev/devops_itkdev-docker.
3+
// Feel free to edit the file, but consider making a pull request if you find a general issue with the file.
4+
5+
// https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/docs/configuration.md#configuration-file
6+
7+
$finder = new TwigCsFixer\File\Finder();
8+
// Check all files …
9+
$finder->in(__DIR__);
10+
// … that are not ignored by VCS
11+
$finder->ignoreVCSIgnored(true);
12+
13+
$config = new TwigCsFixer\Config\Config();
14+
$config->setFinder($finder);
15+
16+
return $config;

docs/github-actions-templates.md

+60-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- DO NOT EDIT THIS FILE!
22
3-
It was automatically created at 2025-05-05T10:20:02+02:00
3+
It was automatically created at 2025-05-05T13:58:04+02:00
44
by task/scripts/github-documentation-update
55
based on /app/task/scripts/../templates/github-actions-templates.md
66
-->
@@ -61,6 +61,65 @@ Validates composer.json and checks that it's normalized.
6161

6262
---
6363

64+
[github/workflows/drupal-module/javascript.yaml](github/workflows/drupal-module/javascript.yaml)
65+
66+
### Drupal module JavaScript (and TypeScript)
67+
68+
Validates JavaScript files.
69+
70+
#### Assumptions
71+
72+
1. A docker compose service named `prettier` for running
73+
[Prettier](https://prettier.io/) exists.
74+
75+
---
76+
77+
[github/workflows/drupal-module/php.yaml](github/workflows/drupal-module/php.yaml)
78+
79+
### Drupal module PHP
80+
81+
Checks that PHP code adheres to the [Drupal coding
82+
standards](https://www.drupal.org/docs/develop/standards).
83+
84+
#### Assumptions
85+
86+
1. A docker compose service named `phpfpm` can be run and `composer` can be
87+
run inside the `phpfpm` service.
88+
2. [drupal/coder](https://www.drupal.org/project/coder) is a dev requirement
89+
in `composer.json`:
90+
91+
``` shell
92+
docker compose run --rm phpfpm composer require --dev drupal/coder
93+
```
94+
95+
Clean up and check code by running
96+
97+
``` shell
98+
docker compose run --rm phpfpm vendor/bin/phpcbf
99+
docker compose run --rm phpfpm vendor/bin/phpcs
100+
```
101+
102+
> [!NOTE]
103+
> The template adds `.phpcs.xml.dist` as [a configuration file for
104+
> PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file)
105+
> and this makes it possible to override the actual configuration used in a
106+
> project by adding a more important configuration file, e.g. `.phpcs.xml`.
107+
108+
---
109+
110+
[github/workflows/drupal-module/styles.yaml](github/workflows/drupal-module/styles.yaml)
111+
112+
### Drupal module Styles (CSS and SCSS)
113+
114+
Validates styles files.
115+
116+
#### Assumptions
117+
118+
1. A docker compose service named `prettier` for running
119+
[Prettier](https://prettier.io/) exists.
120+
121+
---
122+
64123
[github/workflows/drupal/javascript.yaml](github/workflows/drupal/javascript.yaml)
65124

66125
### Drupal JavaScript (and TypeScript)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Do not edit this file! Make a pull request on changing
2+
# github/workflows/drupal/javascript.yaml in
3+
# https://github.com/itk-dev/devops_itkdev-docker if need be.
4+
5+
### ### Drupal module JavaScript (and TypeScript)
6+
###
7+
### Validates JavaScript files.
8+
###
9+
### #### Assumptions
10+
###
11+
### 1. A docker compose service named `prettier` for running
12+
### [Prettier](https://prettier.io/) exists.
13+
14+
name: JavaScript
15+
16+
on:
17+
pull_request:
18+
push:
19+
branches:
20+
- main
21+
- develop
22+
23+
jobs:
24+
javascript-lint:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- run: |
33+
docker network create frontend
34+
35+
- run: |
36+
docker compose run --rm prettier 'js/**/*.js' --check
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Do not edit this file! Make a pull request on changing
2+
# github/workflows/drupal/php.yaml in
3+
# https://github.com/itk-dev/devops_itkdev-docker if need be.
4+
5+
### ### Drupal module PHP
6+
###
7+
### Checks that PHP code adheres to the [Drupal coding
8+
### standards](https://www.drupal.org/docs/develop/standards).
9+
###
10+
### #### Assumptions
11+
###
12+
### 1. A docker compose service named `phpfpm` can be run and `composer` can be
13+
### run inside the `phpfpm` service.
14+
### 2. [drupal/coder](https://www.drupal.org/project/coder) is a dev requirement
15+
### in `composer.json`:
16+
###
17+
### ``` shell
18+
### docker compose run --rm phpfpm composer require --dev drupal/coder
19+
### ```
20+
###
21+
### Clean up and check code by running
22+
###
23+
### ``` shell
24+
### docker compose run --rm phpfpm vendor/bin/phpcbf
25+
### docker compose run --rm phpfpm vendor/bin/phpcs
26+
### ```
27+
###
28+
### > [!NOTE]
29+
### > The template adds `.phpcs.xml.dist` as [a configuration file for
30+
### > PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file)
31+
### > and this makes it possible to override the actual configuration used in a
32+
### > project by adding a more important configuration file, e.g. `.phpcs.xml`.
33+
34+
name: PHP
35+
36+
env:
37+
COMPOSE_USER: root
38+
39+
on:
40+
pull_request:
41+
push:
42+
branches:
43+
- main
44+
- develop
45+
46+
jobs:
47+
coding-standards:
48+
name: PHP - Check Coding Standards
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
- run: |
53+
docker network create frontend
54+
docker compose run --rm phpfpm composer install
55+
docker compose run --rm phpfpm vendor/bin/phpcs
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Do not edit this file! Make a pull request on changing
2+
# github/workflows/drupal/styles.yaml in
3+
# https://github.com/itk-dev/devops_itkdev-docker if need be.
4+
5+
### ### Drupal module Styles (CSS and SCSS)
6+
###
7+
### Validates styles files.
8+
###
9+
### #### Assumptions
10+
###
11+
### 1. A docker compose service named `prettier` for running
12+
### [Prettier](https://prettier.io/) exists.
13+
14+
name: Styles
15+
16+
on:
17+
pull_request:
18+
push:
19+
branches:
20+
- main
21+
- develop
22+
23+
jobs:
24+
styles-lint:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
fail-fast: false
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- run: |
33+
docker network create frontend
34+
35+
- run: |
36+
docker compose run --rm prettier 'css/**/*.css' --check

task/scripts/github-actions-link

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ cd "$project_dir" || exit
1111
function strip-project-type() {
1212
name=$1
1313

14-
if [[ "$name" =~ ^(drupal|symfony)/(.+) ]]; then
15-
name="${BASH_REMATCH[2]}"
14+
if [[ "$name" =~ ^(drupal(-module)?|symfony)/(.+) ]]; then
15+
name="${BASH_REMATCH[3]}"
1616
fi
1717

1818
echo "$name"
@@ -27,7 +27,9 @@ for template_dir in templates/*; do
2727
echo
2828

2929
project_type=""
30-
if [[ "$template_name" =~ ^drupal- ]]; then
30+
if [[ "$template_name" =~ ^drupal-module ]]; then
31+
project_type="drupal-module"
32+
elif [[ "$template_name" =~ ^drupal- ]]; then
3133
project_type="drupal"
3234
elif [[ "$template_name" =~ ^symfony- ]]; then
3335
project_type="symfony"
@@ -39,7 +41,11 @@ for template_dir in templates/*; do
3941
for f in $(find github/workflows/ -name '*.yaml' | sort); do
4042
source_file_name=''
4143
# Note: / is NOT a regex delimiter here, but an actual /, i.e. a directory separator.
42-
if [[ "$f" =~ /drupal/ ]]; then
44+
if [[ "$f" =~ /drupal-module/ ]]; then
45+
if [[ "$project_type" == "drupal-module" ]]; then
46+
source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")"
47+
fi
48+
elif [[ "$f" =~ /drupal/ ]]; then
4349
if [[ "$project_type" == "drupal" ]]; then
4450
source_file_name="$(basename "$(dirname "$f")")/$(basename "$f")"
4551
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/changelog.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/composer.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/drupal-module/javascript.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/markdown.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/drupal-module/php.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/drupal-module/styles.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../github/workflows/twig.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config/markdown/.markdownlint.jsonc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config/markdown/.markdownlintignore
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config/drupal-module/php/.phpcs.xml.dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../config/drupal-module/twig/.twig-cs-fixer.dist.php
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# itk-version: 3.2.3
2+
3+
services:
4+
phpfpm:
5+
image: itkdev/php8.4-fpm:latest
6+
user: ${COMPOSE_USER:-deploy}
7+
networks:
8+
- app
9+
extra_hosts:
10+
- "host.docker.internal:host-gateway"
11+
environment:
12+
- PHP_XDEBUG_MODE=${PHP_XDEBUG_MODE:-off}
13+
- PHP_MAX_EXECUTION_TIME=30
14+
- PHP_MEMORY_LIMIT=256M
15+
# Depending on the setup, you may have to remove --read-envelope-from from msmtp (cf. https://marlam.de/msmtp/msmtp.html) or use SMTP to send mail
16+
- PHP_SENDMAIL_PATH=/usr/bin/msmtp --host=mail --port=1025 --read-recipients --read-envelope-from
17+
- DOCKER_HOST_DOMAIN=${COMPOSE_DOMAIN}
18+
- PHP_IDE_CONFIG=serverName=localhost
19+
# Let drush know the site uri (makes using --uri redundant)
20+
- DRUSH_OPTIONS_URI=http://${COMPOSE_DOMAIN}
21+
depends_on:
22+
mariadb:
23+
condition: service_healthy
24+
memcached:
25+
condition: service_healthy
26+
volumes:
27+
- .:/app
28+
29+
prettier:
30+
# Prettier does not (yet, fcf.
31+
# https://github.com/prettier/prettier/issues/15206) have an official
32+
# docker image.
33+
# https://hub.docker.com/r/jauderho/prettier is good candidate (cf. https://hub.docker.com/search?q=prettier&sort=updated_at&order=desc)
34+
image: jauderho/prettier
35+
profiles:
36+
- dev
37+
volumes:
38+
- ./:/work

0 commit comments

Comments
 (0)