The projects in src/ are tested on several PHP versions, and some on
several framework versions. matrix.php decides which: each
combination it builds is a cell. This directory holds the script, its
tests, and the rules below for configuring a project's cells.
Each project has its own workflow, .github/workflows/project-<slug>.yml,
so each has its own status and run history. <slug> is the project's
path under src/, lowercased, with / as -. The workflow's name is
the path, so the Actions sidebar lists projects by name.
The project workflows are generated by matrix.php --generate. Don't
edit them. Each calls php-project.yml, which has two jobs:
cellsrunsmatrix.php --project <path>, which prints the project's cells. It fails on that project's ownextra.ciproblems, and no others, so one broken project doesn't stop the rest.testruns one job per cell. It installs the project and runs its style check, Phan, Psalm, PHPStan and PHPUnit, each only if the project has the config file for it. Experimental cells can fail without failing the run.
Each cell installs fresh, with composer update, or composer require
for a framework version. Only Composer's downloads are cached, so a
cell always tests the newest releases its constraints allow.
Xdebug is loaded only in coverage cells. They run PHPUnit a second
time, on the unit and integration suites only, and upload the
result to Codecov. Codecov carries each project's last upload forward,
so a run that skips a project leaves its coverage as it was.
GitHub's paths filter decides. A project's workflow runs on a pull
request or push to main that changes:
- a file under
src/<project>/ - its own
project-<slug>.yml php-project.yml,matrix.php,composer.jsonorsrc/in this directory. These run every project.docker-compose.yaml, ordocker/<service>/, if the project lists services (below)
It also runs weekly, against new dependency releases, and from the Actions tab with "Run workflow".
GitHub checks only the first 300 changed files against paths. A pull
request changing more, such as a style fix across the repository, may
not run every project it touches. The weekly run catches those.
Each project's README has a CI badge for its workflow on main. It
links to this repository's runs, since the split repositories publish
the same README. The root README lists every project with its badge,
generated between two marker comments by matrix.php --generate.
In the Actions tab, the sidebar lists each project's workflow by path. "Run workflow" on one reruns that project alone, on any branch.
.github/workflows/ci.yml runs on every pull request and push to
main, whatever the change touches. It:
- validates the root
composer.json - runs the PHPUnit tests in
tests/. They checkmatrix.phpon small repositories built in a temp directory, never onsrc/, so they fail only whenmatrix.phpitself is broken. - runs
matrix.php --checkon the real repository. A contributor's mistake, such as a project missing from.gitsplit.yml, fails here. Without this, a project with no workflow would never be tested and nothing would say so.
--check fails naming the file at fault when:
- a directory under
src/has acomposer.jsonbut is not inside a.gitsplit.ymlprefix, so CI would never test it - a
.gitsplit.ymlprefix has nocomposer.json extra.cihas an unknown key or a value of the wrong shapeextra.ci.servicesnames a service that isn't indocker-compose.yaml- a project with a
phpunit.xml.disthas no cell on the coverage version, or setsextra.ci.skip - a project has more cells than the 256 jobs GitHub allows in one matrix
- a project has no workflow, a workflow has no project, or a workflow
differs from what
--generatewrites - two projects would get the same workflow, such as
Foo/BarandFoo-Bar - a project's
README.mdhas no CI badge. The error prints the line to add. - the root
README.mdhas no marker comments for the project list, or the list differs from what--generatewrites
A project is a prefix in .gitsplit.yml, unless it sets
extra.ci.skip. It runs on every PHP version in supported and
experimental in matrix.php that its composer.json require.php
allows.
- Create
src/<Category>/<Name>with acomposer.jsonthat setsrequire.php. Copyphpunit.xml.dist,.php-cs-fixer.php,psalm.xml.dist,phpstan.neon.distand.phan/config.phpfrom a similar project. - Add it to
.gitsplit.yml. This is what makes CI test it. - Add it to
autoloadandreplacein the rootcomposer.json. - Add its owners to
.github/component_owners.yml. - If it needs more than the defaults, add
extra.ci(below). - Run
make ci-generate. It writes the project's workflow and adds the project to the root README's list. Commit both. - Add its CI badge to its
README.md, under the title.make ci-checkprints the line if it's missing.
Removing a project, or setting extra.ci.skip, also needs
make ci-generate, which deletes the workflow and the root README's
entry. So does changing extra.ci.services.
Projects that need more than the defaults say so in their own
composer.json, under extra.ci.
composer-requires maps each constraint to the lowest PHP version that
supports it. Each constraint gets its own cells, on PHP versions that
satisfy both this minimum and require.php. The cell installs with
composer require <constraint>.
"extra": {
"ci": {
"composer-requires": {
"laravel/framework:^10": "8.1",
"laravel/framework:^11": "8.2"
}
}
}Every cell installs ast (for Phan) and opentelemetry.
additional-extensions adds to them. It can't remove them, and listing
them again is an error. Names are in the
setup-php
format, which is not always the ext-* name.
"extra": {
"ci": {
"additional-extensions": ["phalcon5"]
}
}ext-opentelemetry doesn't need to be in require. Most projects leave
it out so they can be installed and worked on without the extension,
and _register.php checks for it at runtime instead.
services lists the docker-compose.yaml services a project's tests
need. Each cell starts them with docker compose up --wait before
PHPUnit. Changing docker-compose.yaml, or a file under
docker/<service>/, runs every project that lists that service. Run
make ci-generate after changing services, since it adds those
paths to the project's workflow.
"extra": {
"ci": {
"services": ["mysql"]
}
}The services in use are mysql, postgresql, rabbitmq, kafka and
mongodb. CI starts mongodb with
supercharge/mongodb-github-action
instead of compose, because it sets up a replica set and the compose
service doesn't.
To add a service:
- Add it to
docker-compose.yamlwith ahealthcheck. Without one,--waitreturns as soon as the container starts, and the first tests can fail while the service is still starting. - Publish its port. In CI the tests run on the runner, not in the
compose network, so they reach the service on
localhost. - Put any init files under
docker/<service>/, so changing them runs only the projects using the service. - Add a host variable, such as
MYSQL_HOST, to thephpservice'senvironment, defaulting to the service name. Tests read it, falling back tolocalhost, so the same test works undermakeand in CI. - List it in the project's
extra.ci.services, and runmake ci-generate.
skip leaves a project out of CI entirely: it gets no workflow. Use it
for a prefix whose output isn't a Composer package, and which has its
own CI. Run make ci-generate after setting it.
"extra": {
"ci": {
"skip": true
}
}OperatorPackages/autoinstrumentation-php skips. It builds a Docker
image, and its composer.json only lists what goes in the image. Its
own .github/workflows/build.yml builds the image, in the split
repository.
A project with a phpunit.xml.dist can't skip, since its tests would
never run.
The versions are at the top of matrix.php.
supportedmust pass.experimentalruns but may fail. Use it for a version that isn't released yet, or that projects don't support yet.coverageis the one version whose cells upload coverage. It must be insupported.
To add a version, add it to experimental. Once its cells pass, move
it to supported. Change coverage separately, when every project
passes on the new version.
The Makefile runs the same checks as a CI cell, in the php service
from docker-compose.yaml. It needs Docker with Compose v2. Copy
.env.dist to .env first.
PROJECT is a path under src/, and make projects lists them.
PHP_VERSION picks the image, and defaults to 8.1, the lowest version
CI runs.
make projects
# Start the services in the project's extra.ci.services, if any
PROJECT=Instrumentation/PDO make services
# Install, then style, validate, Phan, Psalm, PHPStan and PHPUnit
PROJECT=Instrumentation/PDO PHP_VERSION=8.4 make all
docker compose downCI skips a check when the project has no config for it, but make all
runs them all. For a project without every config, such as
MetaPackages/opentelemetry, run the targets one at a time, as in
make validate test. make help lists them.
A cell uses composer require for a framework version. To test one
locally, run it in the container:
PROJECT=Instrumentation/Laravel make bash
composer require laravel/framework:^11Locally the tests reach services through the compose network, by
service name. <SERVICE>_HOST in the php service's environment
sets that.
matrix.php is a small Composer project of its own, with its tests in
tests/. It needs PHP 8.5, whichever versions the projects are tested
on. These make targets run it in the php service on 8.5, and install
its dependencies first.
# Tests for matrix.php, as ci.yml runs them
make ci-test
# Rewrite the project workflows and the root README's project list,
# then check the repository as ci.yml does
make ci-generate
make ci-check
# The cells a project's workflow runs, as JSON
PROJECT=Instrumentation/Laravel make ci-cellsWith PHP 8.5 or later on the host, run it directly instead:
composer install --working-dir=.github/ci
.github/ci/vendor/bin/phpunit -c .github/ci/phpunit.xml.dist
php .github/ci/matrix.php --check