Skip to main content

GitHub Action for setting up Drupal for testing

Published on

I have written my first GitHub Action – bluehorndigital/setup-drupal. In my phpstan-drupal and drupal-check projects I have various GitHub Actions workflows that build a Drupal project via Composer.

 

There are actually a few quirks with changes in Drupal 9, so I made an action to simplify setting up a Drupal project.

As of 9.1.0, the drupal/recommended-project template now specifies a minimum stability of "stable". Why does this matter? With this setting the following versions would not be installable:

  • ^1.0@rc
  • ^1.0@beta
  • ^1.0@alpha
  • 1.0.x-dev

So, if you are testing a package in your GitHub Action workflow – it will be rejected! It is a development release, technically.

There is another quirk, as well. If you use drupal/core-dev vs drupal/core-dev-pinned to install development dependencies (ie: PHPUnit) you will get PHPUnit 9. This requires the phpspec/prophecy-phpunit package or else you will receive a fatal error. It is documented in a change record, but it wasn't easily searchable when I first encountered it.

The setup-drupal action checks if you are installing Drupal 9 and includes this dependency for you.

I just updated phpstan-drupal to use this action: https://github.com/mglaman/phpstan-drupal/pull/171

I plan to provide an example of testing a Drupal module via Github Actions with this module with the CiviCRM Webform or CiviCRM Entity modules.

I'm available for one-on-one consulting calls – click here to book a meeting with me 🗓️