Git And Collaboration Workflows

Remote Quality Gates

Remote quality gates provide shared enforcement after code leaves one developer's machine.

Why This Matters

Local hooks can be missing or bypassed. Required CI checks, protected branches, merge rules, and controlled receive hooks provide repository-level evidence and policy.

Working Model

Hosted platforms normally enforce policy through branch rules, status checks, approvals, and merge queues. Self-hosted bare repositories can use receive-side hooks, but those hooks require operational ownership and careful availability design.

Practical Rules

  • Run committed commands in CI rather than reimplementing checks in workflow YAML.
  • Protect the main branch from direct unreviewed pushes.
  • Require checks that are deterministic and relevant to the changed code.
  • Use least-privilege tokens and isolate untrusted pull-request code.
  • Treat deployment approval separately from source merge approval.

Failure Modes

  • Making a flaky check mandatory without an owner or repair plan.
  • Passing secrets to workflows from untrusted forks.
  • Depending on a self-hosted receive hook without monitoring or rollback.
  • Allowing administrators to bypass policy routinely.

Verification

  • Open a test pull request that deliberately fails each gate.
  • Confirm direct push and force-push behavior.
  • Audit who can change workflow and branch-rule configuration.
  • Record evidence required for emergency bypasses.

What You Should Be Able To Do

After this lesson, you should be able to explain the difference between local feedback and authoritative remote enforcement, choose a suitable approach for a real PHP project, and verify the result instead of relying on assumptions.

Remote Gates Are The Shared Source Of Confidence

Remote quality gates run in infrastructure controlled by the repository or organization. They are the checks everyone can see and trust before code merges. Local hooks are helpful, but remote gates are where policy becomes enforceable: tests, static analysis, security checks, required review, branch protection, signed commits, merge queues, and deployment approvals.

A good remote gate answers a specific question. Do unit tests pass? Does static analysis still hold? Does the application build? Are migrations compatible? Are secrets absent? Did required reviewers approve? Vague gates that run unknown scripts are hard to maintain and hard to debug.

Required Checks Should Match Real Risk

Not every check deserves to block every pull request. A syntax or unit-test failure should block. A flaky browser test may need quarantine until it is trustworthy. A long nightly performance suite can inform maintainers without blocking every typo fix. Required checks should be fast enough and reliable enough that developers treat failures seriously.

For PHP projects, common required gates include Composer install validation, PHP syntax or lint, static analysis, coding standard checks, unit tests, integration tests where dependencies are available, migration checks, and web build/typecheck. Security-sensitive repositories may also require dependency audits and secret scanning.

Branch Protection And Review Policy

Branch protection should encode the workflow. Protect main and release branches from direct pushes when review and CI are required. Require up-to-date branches or merge-queue validation when concurrent merges often break the base. Require code-owner review for security, infrastructure, or database paths where specialized knowledge matters.

Avoid bypasses that are invisible. If administrators can override protection, require a reason and follow-up. Emergency paths are sometimes necessary, but they should leave an audit trail and trigger later cleanup.

CI Environment Design

A remote gate is only as useful as its environment. Pin PHP versions, extension sets, Composer options, service containers, environment variables, and build commands. If production runs PHP 8.4 with specific extensions, a gate running a different runtime may miss deployment failures.

Cache dependencies carefully. Caches speed builds but can hide broken dependency declarations if the cache key is too broad. Include lock files and relevant platform information in cache keys. Periodically test from a cold cache so the project remains reproducible.

Secrets in CI need least privilege. A pull request from an untrusted fork should not receive production credentials. Separate checks that need secrets from checks that can run safely on external contributions.

Merge Queues And Race Conditions

A branch can be green when tested alone and still break after another branch merges first. Merge queues solve this by testing the exact candidate merge or a queue of candidate merges before updating the protected branch. They are especially useful when many developers merge frequently or when tests are expensive enough that developers do not constantly rebase.

Merge queues change feedback timing. Developers need to know whether a failure belongs to their branch, another queued branch, or the combined result. Good queue tooling reports the tested commit and keeps the pull request state understandable.

Security And Supply Chain Gates

Dependency audits, secret scanning, license checks, and provenance checks can run remotely. Treat their output as triage, not noise. A dependency advisory may require an immediate update, a compensating control, or a documented non-applicability decision. An abandoned package may be acceptable temporarily but should have an owner.

Do not let security gates auto-fix production dependencies without review. Automated pull requests are useful, but the project still needs tests and human attention for breaking changes.

Failure Handling

Remote gate failures should be actionable. Logs should show the command, environment, and failure reason. If a check flakes, label it and fix the root cause. Re-running until green without investigation teaches the team that red does not matter.

When a required gate is down because infrastructure is unavailable, the team needs a policy. Bypassing may be acceptable for an urgent fix, but the bypass should be recorded and the skipped evidence should be recreated afterward where possible.

Measuring Gate Health

Track build duration, queue time, flake rate, failure categories, and bypass frequency. A slow gate delays feedback. A flaky gate erodes trust. A gate nobody understands becomes ritual. The goal is reliable evidence before merge, not ceremony.

After this lesson, you should be able to design remote quality gates that enforce shared policy, choose required checks based on risk, configure branch protection and merge queues, protect CI secrets, respond to flaky failures, and measure whether gates improve confidence rather than merely slowing work.

Designing A Gate Set

Build gates in layers. The first layer should fail fast: dependency installation, syntax, static configuration validation, and focused unit tests. The next layer can run slower integration or browser checks. Deployment packaging and smoke tests belong near release. This order gives quick feedback while still collecting deeper evidence before merge or deployment.

Each gate should have an owner and a failure playbook. If PHPStan fails, who updates baselines? If dependency audit fails, who decides whether to update, ignore, or compensate? If browser tests fail, how is flakiness distinguished from a product regression? A gate without ownership becomes a red icon people route around.

Remote gates should also publish artifacts when helpful: coverage reports, static-analysis output, built assets, test logs, and deployment previews. Keep artifacts retained long enough for review but not so long that they leak data or waste storage.

Required Gate Review

Review required gates periodically. A project that added a check years ago may no longer understand what it proves. Remove gates that no longer protect a meaningful risk, repair flaky gates, and add coverage where incidents show a missing signal.

For PHP repositories, compare gates with production requirements. If production requires a specific extension, the gate should use it. If deployment builds assets, the gate should build them. If migrations are part of release risk, the gate should at least validate migration syntax or run them against a disposable database.

Make bypass exceptional and visible. An administrator merge during a CI outage should include the skipped checks, the reason, and the follow-up command or deployment verification that restored confidence.

Environment And Data Safety

Remote gates often create databases, queues, build artifacts, preview deployments, and logs. Those resources need cleanup and data rules. Test data should be synthetic unless the environment is explicitly approved for sensitive data. Preview URLs should not expose private features without authentication.

When gates run migrations or integration tests, isolate them from shared developer resources. A pull request should not be able to delete a staging database or publish real emails because a test command reused production-like credentials. Use short-lived credentials, least privilege, and disposable resources wherever possible.

Document which artifacts are retained and for how long. Build logs can contain environment names, paths, and occasionally secrets if commands are careless. Redaction is part of gate design. A gate should also explain ownership in its name or documentation. Developers need to know whether a failure belongs to application code, test infrastructure, security policy, package maintenance, or deployment configuration. Clear ownership shortens outages and prevents random reruns from becoming the default response. For long-running suites, publish partial progress and timing. Developers should know whether a build is compiling, testing, waiting for a service, or stuck. Observability for CI itself is part of making gates trustworthy. Store enough history to compare failures across branches and releases. Use that history during incident review. Make the responsible maintainer explicit in documentation.

Practice

Practice: Design A Required Check Set

Choose required checks for a PHP web application without turning every optional job into a merge blocker.

Your answer must:

  • state the intended outcome;
  • show the commands, data flow, or implementation shape;
  • identify at least one unsafe alternative;
  • explain how the result will be verified.
Show solution

Require deterministic syntax, formatting, static analysis, focused test, and dependency checks. Keep expensive advisory jobs visible but non-blocking until their reliability and ownership justify enforcement.

The important part is not memorising one command or vendor screen. The solution makes the invariant, failure behavior, and verification evidence explicit.

Practice: Secure Forked Pull Requests

A public repository accepts pull requests from forks. Design the CI trust boundary.

Your answer must:

  • state the intended outcome;
  • show the commands, data flow, or implementation shape;
  • identify at least one unsafe alternative;
  • explain how the result will be verified.
Show solution

Run untrusted code without write tokens or deployment secrets, restrict cache poisoning paths, require trusted approval before privileged follow-up jobs, and never expose production credentials to fork-triggered workflows.

The important part is not memorising one command or vendor screen. The solution makes the invariant, failure behavior, and verification evidence explicit.

Practice: Plan Receive-Side Enforcement

A self-hosted Git server needs a fast-forward-only protected branch.

Your answer must:

  • state the intended outcome;
  • show the commands, data flow, or implementation shape;
  • identify at least one unsafe alternative;
  • explain how the result will be verified.
Show solution

Use an update or pre-receive hook to inspect proposed old and new object IDs, reject non-descendant updates with a clear message, test atomic multi-ref pushes, and monitor hook failures as server operations.

The important part is not memorising one command or vendor screen. The solution makes the invariant, failure behavior, and verification evidence explicit.