Skip to content

CI: Split BuildInfoCollector into one class per CI service - #14498

Merged
alies-dev merged 20 commits into
vimeo:masterfrom
alies-dev:refactor/build-info-collector
Nov 21, 2026
Merged

alies-dev merged 20 commits into
vimeo:masterfrom
alies-dev:refactor/build-info-collector

Conversation

@alies-dev

@alies-dev alies-dev commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

BuildInfoCollector mixed the environment variable names and logic of every CI service in one 500-line class, which also wrote its results back into the environment it read. That hid several bugs: CircleCI's build number and the GitHub Actions job id were never sent, a tag was sent as the branch, a Bitbucket project on Scrutinizer was sent as a GitHub repository, and when several CI services matched, their keys were merged (Travis CI plus GitHub Actions sent github-actions together with Travis's CI_JOB_ID and TRAVIS_* keys).

Before: one class with fillTravisCi(), fillCircleCi(), … all writing into one array.

After: BuildInfoCollector returns the build info of the first Ci\CiProvider whose collect() recognises the environment: the known services first (GitHub Actions, Scrutinizer, Jenkins, AppVeyor, CircleCI, Travis CI), then any other CI with a GitHub remote. Each provider is a small class with its environment variable names as constants. They read through an immutable Env and return a BuildInfo, whose toArray() is the only place that knows the CI_* keys Shepherd reads.

The first commit pins the full output for every CI service, and the refactor commit passes those tests unchanged. Each bug fix has a test that fails before it. The last two below come from the split itself, so their tests are separate commits:

  • CircleCI sends CI_BUILD_NUMBER.
  • GitHub Actions sends GITHUB_RUN_ID as CI_JOB_ID.
  • A tag (GitHub Actions, Travis CI) is not sent as CI_BRANCH.
  • Only the leading refs/heads/ is stripped from a GitHub ref.
  • A GitHub Actions pull request sends its head branch (GITHUB_HEAD_REF) as CI_BRANCH instead of refs/pull/N/merge (pull_request) or the base branch (pull_request_target).
  • A GitHub Actions pull request from a deleted fork sends no CI_BRANCH. Without a head repository, Shepherd recorded the head commit of a pull_request_target build in the history of the default branch.
  • Scrutinizer sends only GitHub (g/) projects, and a pull request build now sends CI_REPO_* too, so Shepherd can link the report to the pull request.
  • A repository slug that isn't owner/name sends no repository.
  • Only the first matching CI service is sent, not a merge of all of them.

TRAVIS, CIRCLECI, APPVEYOR and SCRUTINIZER set to "false" no longer count as that CI service.

The build info array is also what AfterAnalysisEvent::getBuildInfo() gives plugins. Its shape changes: values that are not known (null, an empty TRAVIS_TAG, ""/"false"/"0" pull request numbers) are no longer included, and keys of several CI services are no longer merged. Shepherd already reads missing and empty values the same way. UPGRADING.md lists the change.

The collector had tests for GitHub Actions and the generic CI only. Add a data
provider with the whole input environment and the whole `build` array for Travis CI,
CircleCI, AppVeyor, Jenkins, Scrutinizer, GitHub Actions (push, tag, pull request,
pull request from a fork and from a deleted fork) and the generic CI, so that the
collector can be refactored without changing what Shepherd receives.
CircleCI sent null for every unset repository, branch and pull request value,
and Travis CI, AppVeyor and Scrutinizer sent "false" or "" as the number of a build that
is not a pull request. Shepherd reads a null, an empty and a missing value alike
(`GithubData::getBuildValue()`, `CI_PR_NUMBER` is ignored when empty or "false"),
and the generic CI already sends no number for these values.

Leave them out, so that the build info can be modelled as optional values.
The expectations of the characterization tests drop those keys in this commit.
`BuildInfoCollector` held the environment variable names and the logic of every CI
service, and wrote its results into the environment it read.

- `Ci\CiProvider` with `detects()` and `collect()`, and one small class per service
  (GitHub Actions, Travis CI, CircleCI, AppVeyor, Jenkins, Scrutinizer, generic CI), each
  with its variable names as constants.
- `Env`, a read-only view of the variables: first non-empty value, flag, `owner/name` slug.
- `BuildInfo`, `Repository` and `PullRequest`: what a service tells, and `BuildInfo::toArray()`
  as the only place that knows the `CI_*` keys.
- `BuildInfoCollector` returns the build info of the first provider that detects its service.
  `detects()` gets the git info too, as the generic CI needs it to tell the repository.

The characterization tests are unchanged. What changes: the key order of the array (every
provider used its own), a slug without exactly one "/" sends no repository instead of an
undefined offset warning, and when the variables of several services are set, only the one that
came last in the old collector (so the one that set CI_NAME) is sent.
The old collector wrote `CI_BUILD_NUMBER` into the environment it read instead of the
build info, so the number (`CIRCLE_BUILD_NUM`) was never sent, unlike the one of AppVeyor and
Jenkins. The characterization expectations of the two CircleCI cases now include it.
The old collector wrote `CI_JOB_ID` into the environment it read, so it was never sent, and
its value would have been `GITHUB_ACTIONS` ("true"), which identifies nothing. Send
`GITHUB_RUN_ID`, the number that is unique per workflow run in a repository and stays the
same when the run is re-run; `GITHUB_JOB` is only the job key of the workflow file.
Without it no job id is sent. The characterization expectations of the GitHub Actions
cases now include it.
`refs/heads/feature/refs/heads/login` became the branch `feature/login`, because
every occurrence of the prefix was removed, not only the one the ref starts with.
GitHub Actions sent `refs/tags/v1.0.0` as the branch `v1.0.0`, and Travis CI sent the tag it
builds as `CI_BRANCH` (`TRAVIS_BRANCH` is the name of the tag for a tag build, the docs add that
git does not store the branch a commit was tagged from). Shepherd compares `CI_BRANCH` with the
default branch of the repository, so a tag called like it was taken for it.

Send no branch for a tag; the tag stays in `GITHUB_REF` and `TRAVIS_TAG`, which are sent as they
are, and the git info built from the push event of a tag has no branch. The characterization
expectations of the two tag cases drop the branch.
`SCRUTINIZER_PROJECT` is "g/owner/name" for a GitHub project and "b/owner/name" for a
Bitbucket one (https://scrutinizer-ci.com/docs/build/environment-variables). The owner and
the name were read from both, so a Bitbucket project was sent as a GitHub repository, which
Shepherd then looked up on GitHub. Send the repository of a "g/" project only.
The old collector split "owner/name" slugs with explode() and read both parts, so a
slug without a "/" (Travis CI, AppVeyor, GitHub Actions) raised an undefined offset warning
and sent the owner without a name. Every slug now goes through `Env::repository()`, which
returns nothing unless it is exactly "owner/name". The new cases fail on the old collector and
pass since the split into one class per CI service; this commit only adds the test.
@alies-dev alies-dev added the release:internal The PR will be included in 'Internal changes' section of the release notes label Nov 21, 2026
@alies-dev alies-dev self-assigned this Nov 21, 2026
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 751 96.6 $\color{gray}{\textsf{+0.8\%}}$ 25 908 53 462 682
✅ symfony 3 600 264.6 $\color{gray}{\textsf{+0.4\%}}$ 50 619 98 465 1 528
✅ doctrine-orm 381 21.1 $\color{gray}{\textsf{+0.6\%}}$ 3 481 6 143 0
✅ psl 617 27.2 $\color{gray}{\textsf{+2.4\%}}$ 1 375 5 615 1
✅ phpunit 455 19.9 1 731 3 410 18
✅ php-parser 226 13.7 $\color{gray}{\textsf{+1.3\%}}$ 17 132 21 025 0
✅ tempest 895 37.2 $\color{gray}{\textsf{+0.6\%}}$ 5 049 10 534 252
✅ amphp-amp 68 1.9 $\color{gray}{\textsf{-2.1\%}}$ 29 49 0
✅ webmozarts-assert 272 4.7 577 2 720 0
✅ guzzle-promises 44 1.6 $\color{gray}{\textsf{-0.6\%}}$ 155 434 2
✅ monolog 135 5.7 $\color{gray}{\textsf{+0.4\%}}$ 913 2 479 10
✅ drupal 4 841 236.1 $\color{gray}{\textsf{-1.6\%}}$ 97 594 169 302 583
Total 13 285 730.2 $\color{gray}{\textsf{-0.1\%}}$ 204 563 373 638 3 076
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head 9235ff0 · base f18e993 (merge-base) · workflow run

@alies-dev alies-dev changed the title Split BuildInfoCollector into one class per CI service CI: Split BuildInfoCollector into one class per CI service Nov 21, 2026
`collect()` returns null when the environment is not the one of the CI service, so that
the generic CI no longer looks up the GitHub remote twice and needs no exception for a
state that cannot happen.
A build that is not a tag build sent `TRAVIS_TAG` as an empty string, although a value that is not
known is not sent. Shepherd never reads it. The expectations of the two Travis CI cases that are
not tag builds drop it.
CircleCI and the GitHub Actions pull request built a repository from an owner and a name that
can be missing in the same way. Both use `Repository::fromParts()` now, which also
returns null for an empty owner or name.
The comment told which CI_NAME used to win in the old collector. It now says what the order means:
known services first, the generic one last. Remove a leftover section marker.
A pull request build sent only `CI_PR_REPO_OWNER` and `CI_PR_REPO_NAME`, so Shepherd, which needs
`CI_REPO_*` to name the repository (`GithubData::getRepositoryForCommitAndPayload()`), could not link the
report to the pull request.

`SCRUTINIZER_PROJECT` is the inspected project, so `CI_REPO_*` is sent from it on every build, and on a
pull request build `CI_PR_REPO_*` is the same repository: Scrutinizer does not expose the repository a pull
request comes from. This is what the generic CI sends for a pull request.

`SCRUTINIZER_BRANCH` is the target branch of a pull request, which is usually the default one, but
Shepherd records a commit in the history of the default branch only when no `CI_PR_REPO_*` is sent
(`PsalmData::linkToGithub()`), so a pull request commit does not end up there. The expectation of the
Scrutinizer pull request case now includes `CI_REPO_*`.
`CI_BRANCH` of a `pull_request` or `pull_request_target` event was `refs/pull/N/merge`, the ref of the
merge commit. Send `GITHUB_HEAD_REF`, the branch the pull request comes from, when it is set.

Shepherd compares `CI_BRANCH` with the default branch only when no `CI_PR_REPO_*` is sent
(`PsalmData::linkToGithub()`, `GithubData::getRepositoryForCommitAndPayload()`), so for a pull request
from a repository it does not change what is recorded. A pull request from a deleted fork has no
repository to send, and a head branch called like the default one would be taken for a commit of it,
so there the ref stays. Without `GITHUB_HEAD_REF` (or empty) the ref stays too.
The expectations of the pull request cases now have the head branch.
A pull request from a deleted fork kept `GITHUB_REF` as `CI_BRANCH`. For a `pull_request_target` event
that ref is the base branch, so the build sent the default branch, the pull request number and no
`CI_PR_REPO_*`. Shepherd then recorded the head commit of the pull request in the history of the
default branch (`PsalmData::linkToGithub()`).

Without the repository a pull request comes from, no branch is sent, for both events.
Splitting the collector into providers stopped merging the keys of several CI services, but no test
set the variables of two known ones. On the base, Travis CI with Jenkins sent `CI_NAME=jenkins` together
with the `CI_JOB_ID`, `CI_REPO_*` and `CI_PR_NUMBER` of Travis CI.
The providers read their flag with `Env::isTruthy()`, so `TRAVIS`, `CIRCLECI`, `APPVEYOR` and
`SCRUTINIZER` set to "false" no longer detect the service; on the base, PHP took the string "false"
as true. A GitHub Actions environment with only `GITHUB_ACTIONS` sends its name and nothing else,
where the base sent an empty branch and repository. Pin both, and that a flag without the build
variable the service needs is no CI service.
…nd tests

The collector reads `GITHUB_HEAD_REF` and `GITHUB_RUN_ID` now, so on a GitHub Actions pull request
run the tests that fake a GitHub Actions environment picked up the real branch and run id.
`AfterAnalysisEvent::getBuildInfo()` gives plugins the keys of one CI service, without the values
that are not known.
@alies-dev
alies-dev merged commit 7bfe967 into vimeo:master Nov 21, 2026
71 checks passed
@alies-dev
alies-dev deleted the refactor/build-info-collector branch November 21, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:internal The PR will be included in 'Internal changes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant