drupalspoons/composer-plugin

This package is abandoned and no longer maintained. No replacement package was suggested.

Composer Plugin to prepare Drupal project for CI and/or local tests.

Installs: 13 831

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Forks: 8

Type:composer-plugin

2.10.16 2022-11-28 18:52 UTC

README

This project needs a new name and a new home (ideally managed by the Drupal Association). This plugin has 2 goals:

  • CI template. Provide a golden path (see Spotify's definition of this term) that Drupal contrib projects can use with Gitlab CI.
  • Local development. Standardize scripts and a matching codebase assembly for local Drupal development.

Together, these goals ensure that tests run on local environment have same outcome as on the Gitlab CI platform (to a large extent).

CI

  • Add a .gitlab-ci.yml in the project root dir. A good starting point is KeyCDN. Commit and push the file. Pipelines should start running after each push. Click Gitlab's CI/CD link to see them.
  • Optional
    • Add a phpcs.xml file to customize how phpcs checks your source code.
    • You may add services to your .gitlab-ci.yml file if you want to test with memcache, elasticsearch, redis, etc.
    • To disable a job, see the DCI_SKIP environment variables in the table below.
    • Add patches as per usual in composer.json if you need changes in other packages (for example).
    • (maintainers only). Go to CI/CD => Schedules and add any important build permutations to a weekly schedule. Example permutations would be a non-default Drupal core version, DB backend, etc. For example, see KeyCDN's schedules. See Environment Variables below.

Environment Variables

Use the Run Pipeline button on your Pipelines listing to test any branch with alternate versions of Drupal core, PHP version, or DB driver. The recognized variables and default values are:

NameDefaultNotes
DRUPAL_CORE_CONSTRAINT^9
PHP_TAG7.4
DCI_SKIP_COMPOSER0Set to 1 to skip job
DCI_SKIP_VALIDATE0Set to 1 to skip job
DCI_SKIP_PHPCS0Set to 1 to skip job
DCI_SKIP_STYLELINT0Set to 1 to skip job
DCI_SKIP_ESLINT0Set to 1 to skip job
DCI_SKIP_PHPUNIT0Set to 1 to skip job
DCI_PHPUNIT_EXTRAExample: --group=devel_generate
DB_DRIVERmysqlAllowed: mysql, sqlite, or pgsql
MARIADB_TAG10.3
POSTGRES_TAG0
COMPOSER_PLUGIN_CONSTRAINT^2For testing composer-plugin MRs
COMPOSER_PLUGIN_PREPAREtrueFor skipping codebase symlink step
WEB_ROOTweb

Local Development

  • Clone the contrib project via git
  • Install this plugin (syntax depends on your shell):
    • BASH or ZSH: bash <(curl -s https://gitlab.com/drupalspoons/composer-plugin/-/raw/master/bin/setup)
    • FISH: bash (curl -s https://gitlab.com/drupalspoons/composer-plugin/-/raw/master/bin/setup | psub)
  • Configure a web server to serve the /web directory as docroot. Either of these works fine:
    • composer webserver
    • Setup Apache/Nginx/Other. A virtual host works fine. Any domain name works.
  • Configure a database server and create a database. Do this by defining SIMPLETEST_DB environment variable (e.g. SIMPLETEST_DB=mysql://admin:admin@127.0.0.1/dbname )
  • Install Drupal composer si -- --db-url=mysql://user:pass@localhost/db. Adjust as needed.
  • Run tests composer unit.
  • Customize these composer scripts via environment variables and args/options. See the table above.

This plugin is compatible with any Docker local development platform like DDEV, Lando, etc. Further, this plugin doesn't assume Docker so native is great too. A convenient way to set environment variables on native is Direnv (and see the .envrc file thats written into your project root). Alternatively, prefix all Composer commands with spoon like spoon update or spoon drush core:status

Handling project changes

  • If the project's composer.json changes or if files are added/removed from project root: composer drupalspoons:rebuild
  • If new or updated dependencies are available composer update

More example commands

  • Run all tests - composer unit.
  • Run a suite: composer unit -- --testsuite functional
  • Skip slow tests: composer unit -- --exclude-group slow
  • Use a different URL: SIMPLETEST_BASE_URL=http://example.com composer unit

How this plugin works

  • This plugin writes a composer.spoons.json file that includes the specified version of Drupal core.
  • The plugin assumes that composer.spoons.json is in effect when running composer commands. This is done automatically for CI. For local development, COMPOSER=composer.spoons.json environment variable must be set. You can do that manually or via Direnv, or Docker, or spoon.
  • This plugin assembles a codebase using symlinks similar to:

Folder tree

Contributing

Contributions to this project are welcome! Please file issues and merge requests.

  • All merge requests are automatically tested via GitLab CI. A maintainer must manually trigger the pipeline (due to permissions in the downstream project).
  • A downstream pipeline is triggerred in cache_metrics project (any project would work), and will propagate pass/fail status back to this project.