Drupal extension template for development and testing in CI of your choice with mirroring to Drupal.org
Perform extension development in GitHub with testing in CI, and push code
committed only to main branches (1.x
, 2.x
etc.)
to drupal.org.
- Turnkey CI configuration with artifacts and test results support.
- Tools:
- Develop locally using PHP running on your host using
identical
.devtools
scripts as in CI.- Uses drupal-composer/drupal-project
to create drupal site structure. Providing a custom fork of
drupal-project
is also supported. - Additional development dependenices provided in
composer.dev.json
. These are merged during the codebase build. - The extension can installed as a module or a theme: modify
type
property set in theinfo.yml
file. - Additional dependencies can be added for integration testing
between extensions: add dependency into
suggest
section ofcomposer.json
.
- Uses drupal-composer/drupal-project
to create drupal site structure. Providing a custom fork of
- Codings standards checking:
- PHP code standards checking against
Drupal
andDrupalPractice
standards. - PHP code static analysis with PHPStan (including PHPStan Drupal).
- PHP deprecated code analysis with Drupal Rector.
- Twig code analysis with TwigCS.
- PHP code standards checking against
- Drupal's Simpletest testing support - runs tests in the same way as
drupal.org's Drupal CI
bot (
core/scripts/run-tests.sh
). - Renovate configuration to keep your repository dependencies up-to-date.
- Develop locally using PHP running on your host using
identical
- Deployment:
- Mirroring of the repo to drupal.org (or any other git repo) on release.
- Deploy to a destination branch different from the source branch.
- Tags mirroring.
- This template is tested in the same way as a project using it.
- Create your extension's repository on GitHub.
- Download this extension's code by pressing 'Clone or download' button in GitHub UI.
- Copy the contents of the downloaded archive into your extension's repository.
- Adjust the codebase:
- Replace
your_extension
with the machine name of your extension: - Update
type: theme
in theinfo.yml
file if your extension is a theme. - Adjust several lines in
.gitattributes
. - Remove
.github/test-scaffold.yml
file. - Remove this content from
README.md
file.
- Replace
- Commit and push to your new GitHub repo.
- Login to your CI and add your new GitHub repository. Your project build will start momentarily.
- Configure deployment to drupal.org (see below).
Configure deployment (click to expand)
The CI supports mirroring of main branches (1.x
, 10.x-1.x
etc.) to
drupal.org mirror of the project (to keep both repos in
sync).
The deployment job runs when commits are pushed to main branches
(1.x
, 2.x
, 10.x-1.x
etc.) or when release tags are created.
Example of deployment repository: https://github.com/AlexSkrypnyk/drupal_extension_scaffold_destination
- Generate a new SSH key without pass phrase:
ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"
- Add public key to your drupal.org account: https://git.drupalcode.org/-/profile/keys
- Add private key to your CI:
- CircleCI:
- Go to your project -> Settings -> SSH Permissions
- Put your private SSH key into the box. Leave Hostname empty.
- Copy the fingerprint string from the CircleCI User Interface. Then,
replace the
deploy_ssh_fingerprint
value in the.circleci/config.yml
file with this copied fingerprint string. - Push the code to your repository.
- In CI, UI add the following variables:
DEPLOY_USER_NAME
- the name of the user who will be committing to a remote repository (i.e., your name on drupal.org).DEPLOY_USER_EMAIL
- the email address of the user who will be committing to a remote repository (i.e., your email on drupal.org).DEPLOY_REMOTE
- your extensions remote drupal.org repository ( i.e.[email protected]:project/myextension.git
).DEPLOY_PROCEED
- set to1
once CI is working, and you are ready to deploy.
Below is a content of the README.md
file that will be added to your project.
The content above this line should be removed.
Few lines describing your project.
- Your first feature as a list item
- Your second feature as a list item
- Your third feature as a list item
Provided that you have PHP installed locally, you can develop an extension using the provided scripts.
Run .devtools/build-codebase.sh
(or ahoy build-codebase
if Ahoy is installed) to start inbuilt PHP
server locally and run the same commands as in CI, plus installing a site and
your extension automatically.
Run tools individually (or ahoy lint
to run all tools
if Ahoy is installed) to lint your code
according to
the Drupal coding standards.
cd build
vendor/bin/phpcs
vendor/bin/phpstan
vendor/bin/rector --clear-cache --dry-run
vendor/bin/phpmd . text phpmd.xml
vendor/bin/twigcs
- PHPCS config:
phpcs.xml
- PHPStan config:
phpstan.neon
- PHPMD config:
phpmd.xml
- Rector config:
rector.php
- TwigCS config:
.twig_cs.php
Run .devtools/test.sh
(or ahoy test
if Ahoy is installed) to run all test for
your extension.
To browse the contents of created SQLite database
(located at /tmp/site_[EXTENSION_NAME].sqlite
),
use DB Browser for SQLite.