drupalspoons / composer-plugin
Composer Plugin to prepare Drupal project for CI and/or local tests.
Requires
- php: >=7.1
- composer-plugin-api: ^1.0 || ^2.0
- composer/composer: ^1.0 || ^2.0
- oohology/gitignorewriter: ^1.1
- dev-master
- 2.10.16
- 2.10.15
- 2.10.14
- 2.10.13
- 2.10.12
- 2.10.11
- 2.10.10
- 2.10.9
- 2.10.8
- 2.10.7
- 2.10.6
- 2.10.5
- 2.10.4
- 2.10.3
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.9
- 2.9.8
- 2.9.7
- 2.9.6
- 2.9.5
- 2.9.4
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- dev-avoid-core-recommended
- dev-nightwatch
- dev-self-test
- dev-report-source
- dev-docs-phpcs
- dev-14-add-template-and-script-to-run-scheduled-pipelines-for-build-automation
- dev-handle_phpspec/prophecy-phpunit
This package is auto-updated.
Last update: 2024-01-31 00:27:32 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:
Name | Default | Notes |
---|---|---|
DRUPAL_CORE_CONSTRAINT | ^9 | |
PHP_TAG | 7.4 | |
DCI_SKIP_COMPOSER | 0 | Set to 1 to skip job |
DCI_SKIP_VALIDATE | 0 | Set to 1 to skip job |
DCI_SKIP_PHPCS | 0 | Set to 1 to skip job |
DCI_SKIP_STYLELINT | 0 | Set to 1 to skip job |
DCI_SKIP_ESLINT | 0 | Set to 1 to skip job |
DCI_SKIP_PHPUNIT | 0 | Set to 1 to skip job |
DCI_PHPUNIT_EXTRA | Example: --group=devel_generate | |
DB_DRIVER | mysql | Allowed: mysql , sqlite , or pgsql |
MARIADB_TAG | 10.3 | |
POSTGRES_TAG | 0 | |
COMPOSER_PLUGIN_CONSTRAINT | ^2 | For testing composer-plugin MRs |
COMPOSER_PLUGIN_PREPARE | true | For skipping codebase symlink step |
WEB_ROOT | web |
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)
- BASH or ZSH:
- 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 runningcomposer
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:
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.