Skip to content

Architecture / Decision records / ADR-HIS-046

ADR-HIS-046 Pull request pipeline: jobs by changed folder, logic in scripts, scanners pinned

Status Accepted
Decided 2026-11-24 by session FN-S05
Record Drafted 2026-11-24; approved 2026-11-25 by the Enterprise Architecture Board
Where the rule lives platform/delivery-pipeline/ (its README.md, bin/, lib/plan.py, tools.env); .github/workflows/pipeline.yml and docs.yml; the agent instruction file CLAUDE.md, section 3

Context

Every change must pass automated CI validation before merge: static analysis, dependency and vulnerability scanning, secret scanning, and unit, integration and contract tests (FR-ISE-REL-001). Every build must also produce a software bill of materials (FR-ISE-SUP-001, DEP-004). Technology stack row 14 names the tools: Trivy for dependencies and images, Semgrep for static analysis, Gitleaks for secrets, and CycloneDX for the SBOM. During development the pipeline runs in GitHub Actions. Before production it moves to the hospital's self-managed GitLab (ADR-HIS-038).

The repository holds many independent builds side by side (ADR-HIS-039), and many sessions open pull requests at once. FN-S05 asks for three things:

  • each job runs only when the files it covers change;
  • a documentation-only change runs the documentation jobs and nothing else;
  • the logic lives in scripts, so that the move to GitLab is small.

The launcher merges a pull request when every check run has completed and none has failed (ADR-HIS-040). The pipeline's verdict is therefore the merge gate.

Options considered

  • One workflow per build kind, filtered by paths, in the manner of the earlier web.yml. The selection would live in YAML that GitLab writes differently. A change to a shared package could not reach the packages that depend on it.
  • Third-party marketplace actions for the scanners. Each would be one more dependency outside the repository, which GitLab cannot run.
  • A dispatcher script that names the jobs a change needs, a workflow that only wires the scripts together, and scanners run from container images pinned by digest.

Decision

The third option.

  • Selection. platform/delivery-pipeline/lib/plan.py maps the files changed since the base to the build folders of ADR-HIS-039. It also says how each folder is built: java (Gradle unit), node (pnpm package), opentofu, script (the folder's own ci.sh), environment (the integration environment) or contracts. The first job of pipeline.yml runs it, and the other jobs use its answer as their matrix.
  • A change to the design system or the shell rebuilds every web package.
  • A change to a screen workspace also rebuilds the shell, which bundles every screen.
  • A folder that holds only a README builds nothing.
  • Documentation. The files of docs/, mkdocs.yml, requirements-docs.txt and every *.md file are documentation.
  • pipeline.yml ignores them, and docs.yml starts on them.
  • A documentation-only change starts docs.yml alone.
  • A self-test checks that the two workflow filters and plan.py agree.
  • The jobs:
  • changes;
  • secret-scan;
  • static-analysis;
  • build, one per folder: build and tests, then the dependency scan and SBOM, the image scan and SBOM for a unit with a Dockerfile, and the report on the integration environment's images;
  • protected-files, on every change outside the documentation;
  • link-check, when a change deletes or moves a file: such a change can break a link in the documentation, and docs.yml does not run on it;
  • pipeline-self-test, when the pipeline itself changes;
  • in docs.yml, docs-check: the link check, the site build and the secret scan of the documentation files.
  • The logic is in platform/delivery-pipeline/bin/.
  • Each script takes a folder, or a base and head, and runs the same on a developer's host as on a runner.
  • The workflow passes the values that come from the change (folder and file names) through environment variables, never through expressions in a script.
  • Actions are pinned by commit, and the workflow token can only read.
  • The scanners run from container images pinned by digest in tools.env: Trivy 0.76.1, Gitleaks 8.30.1 and Semgrep 1.183.0. A host needs Docker and nothing else.
  • The rules are the security rules of Semgrep's open rule repository at a pinned commit, for the languages in use, without the audit rules, plus the project's own rules in semgrep/.
  • No scanner sends results or usage data out.
  • A scanner that cannot run fails its job, so the pipeline fails closed (FR-ISE-REL-001, section 10).
  • The scanners use only the pipeline's own settings. Gitleaks gets its config and an empty ignore list from bin/secret-scan, and reads commits from the git directory without the checkout. Semgrep analyses a copy of the targets, which leaves out every .semgrepignore of the change and carries the pipeline's own ignore list. A change cannot switch off its own scans with a settings file. A false positive is marked on its own line, where the review sees it.
  • What stops a change (FR-ISE-REL-001: PR-REL-001-1, PR-REL-001-2, PR-REL-001-3, AC-02 and AC-04):
  • a failing build or test;
  • a secret in any changed file;
  • a Semgrep finding of severity ERROR or WARNING;
  • a critical or high vulnerability in a folder's locked dependencies, development and test dependencies included, or in a unit's image, unless an approved exception covers it.
  • Exceptions. They live beside the code, in <folder>/security-exceptions.toml, so they are reviewed with the change.
  • Each names the finding, the component, the reason, the Security Engineer who approved it, the approval date and an expiry.
  • An exception that is incomplete, not yet in effect or past its expiry is refused, and the finding blocks again (FR-ISE-SUP-002, rule 6).
  • The scan names each exception it applied.
  • No session writes an approval: only a Security Engineer approves an exception (FR-ISE-REL-001, section 3).
  • The approved_by line is text that no scanner can verify. So the protected-files job stops any change from a session branch (session/*, where every agent works) that adds or changes a line of such a file, and it allows removals.
  • A Security Engineer enters the exception in a pull request of their own, from another branch, and a person merges it.
  • The end-to-end harness (e2e/harness, ADR-HIS-047) is built and tested with its own scenario selftest, in its pinned Playwright runner image, as FN-S07 asks. Its lockfile is scanned, and its runner image is treated like the integration environment's images.
  • The integration environment's images are third-party images that run only on development hosts and runners, with synthetic data, and are part of no release. They are scanned and get an SBOM, and their findings are reported but do not stop a change.
  • The SBOM. Each build job writes a CycloneDX JSON document for each folder and each image, with every component's version, licence, package URL and known vulnerabilities, and keeps it as a build artifact.
  • The dependency scan runs after the build, so licences are read from the installed packages and the Gradle cache.
  • Archiving the SBOM with each release belongs to the release pipeline (FR-ISE-REL-002), not to this card.
  • The contract check is FN-S04's tool his-contract, in contracts/common (ADR-HIS-045). For every changed contract folder, and for every one when contracts/common changes, the build job runs it against the pull request's base commit: conventions, compatibility within a major version, and stubs up to date. For contracts/common it also runs the tools' own build and tests. A folder that holds no contract yet has nothing to check.
  • The secret scan reads the files and the commits. Session pull requests are squash-merged, so what reaches main is the net diff from the point where the branch left the base (base...head). The secret scan reads the whole of every file that diff adds or modifies. It also reads every commit the change brings (base..head). A secret committed and then removed in the same pull request is missing from the net diff, but it stays readable in the pull request's commits.
  • Such a secret stops the change until it is rotated and its commit is taken out of the branch's history.
  • Each scope reads only its own paths: the documentation job reads documents, and secret-scan reads everything else.
  • The web.yml workflow of ADR-HIS-042 is replaced by the build job. Each web package is still built and tested with pnpm install --frozen-lockfile, pnpm build and pnpm test.

Rationale

  • Portability. The selection and every job are scripts that know nothing of GitHub. The GitLab version is rules:changes on the same documentation patterns and one parallel:matrix job fed by bin/changes. Pinned images mirror to Harbor (DEP-008).
  • Exact selection. One dispatcher knows how the folders depend on one another, which a paths filter cannot express. A documentation-only change does not start the pipeline at all.
  • The specification decides the gate. FR-ISE-REL-001 blocks unapproved critical and high findings and admits approved exceptions. FR-ISE-SUP-002 makes acceptances time-bound. The gate does exactly that, and leaves the approval to the person the requirement names.
  • The secret scan of documentation is a documentation job. A secret pasted into a document leaks as surely as one in code. Scanning the documentation files inside the documentation job keeps "a documentation-only change runs the documentation jobs and nothing else" true without leaving documents unscanned.
  • Audit rules are left out of the gate. They mark patterns that are only sometimes faults, and their noise would teach agents to suppress findings. The security rules that remain had no finding on the code base, apart from mutable action tags, which this session pinned.

Consequences

  • The first scans find real findings that block until they are fixed or a Security Engineer approves an exception:
  • every web package, and the contract tools in contracts/common: CRITICAL in tinypool 1.1.1, through Vitest;
  • the service template, and every unit made from it: HIGH in lz4-java 1.11.2 and snappy-java 1.1.10.7, through the Kafka client.

The FN-S05 handover lists them as follow-ups. A screen session may not change its workspace's package.json, so the web upgrade needs a session that owns the web packages. - Each Java build job starts the light profile of the integration environment under a session name of its own (ci-<folder>-<run>), and resets it at the end. A developer who sets HIS_SESSION keeps their own environment. - Severities are the scanner's. The severity rule of CFG-ISE-030 (CVSS v4.0 bands, raised for internet-facing and Tier 1 components, Critical for known exploited vulnerabilities) belongs to the vulnerability register of MOD-ISE-010, which a Security Engineer confirms. - Branch protection is not enforced on the free tier of a private repository (ADR-HIS-038). The checks gate the merge because the launcher waits for them. - Not yet in the pipeline, for the sessions that bring them: - validation of clinical schemas, FHIR profiles, terminology bindings and templates (FR-ISE-REL-001, item 3; TEST-ISE-023); - the release steps: signing with cosign, Harbor and the release SBOM archive (FR-ISE-REL-002); - policy checks on infrastructure code (item 6).