specgate/docs v1.8.0

The gate in CI#

A gate that only runs on laptops is a suggestion. At the end of this page the gate runs on every pull request in your CI, a red gate blocks the merge, and you know what each line of the generated job does and how to keep it current.

You need: the gate passing on your machine (On your machine) and a repository on GitHub, GitLab, Azure DevOps or Jenkins.

A pull request through the gate in CI You push a branch and open its pull request against the base branch. The CI job checks the repository out with its whole history, fetch-depth 0, so the requirement ids can be compared with the base, and runs the gate: specgate check with --base origin/base, on Ubuntu, macOS and Windows; then quality run --stage ci, the ci-stage quality checks, on Ubuntu. The gate's stages run in order: ids, changes, validate, architecture, tests, scenarios, acceptance and quality. If a stage fails, the job is red and the merge is blocked: the first failing stage names its code and its fix, for example id_taken_on_base — REQ-012 means something else on origin/main — with the fix to renumber it to the next id free on both sides; you fix it and push again. If every stage passes, a person reviews: the delta in docs/specs/changes, and what the branch changes in the controls — the guard, gate.yaml, approvals and evidence — reported as controls_changed_on_branch, a warning for the reviewer, not a block. Then the branch merges. A red job blocks the merge only once spec-gate is a required check of the branch. THE GATE'S STAGES, IN ORDER 1 Push a branch, and open its pull request against the base: main, develop… 2 The CI job runs the gate checkout with fetch-depth: 0, so the ids meet the base; then check . --base origin/<base> on Ubuntu, macOS and Windows quality run --stage ci the ci-stage checks, on Ubuntu 01ids 02changes 03validate 04architecture 05tests 06scenarios 07acceptance 08quality 08: harness.config.yaml; in CI, the ci ones too Red — the merge is blocked the first stage that fails names its code and its fix: id_taken_on_base REQ-012 means something else on origin/main fix: renumber REQ-012 on this branch to the next id free on both sides Green — a person reviews the delta, in docs/specs/changes/<id>/, and what the branch changes in the controls: controls_changed_on_branch the guard, gate.yaml, approvals, evidence — a warning for the reviewer, not a block Merge once the reviewer is satisfied and spec-gate is green a stage fails all green fix, push again A red job blocks the merge only once spec-gate is a required check of the branch.
On every pull request the CI job runs the gate against the base branch: red blocks the merge with the code and its fix, green hands the delta and any change to the controls to a reviewer.

Write the job#

specgate init and specgate adopt already wrote it, for the CI the repository shows. Write it again, or for another CI:

bash
specgate ci init                       # the provider the repository shows
specgate ci init --provider gitlab     # github | gitlab | azure | jenkins
specgate ci init --stdout              # print it, write nothing
specgate ci init --force               # overwrite the file that is there
ProviderFilePaste-in
GitHub Actions.github/workflows/spec-gate.ymlits own workflow
GitLab CI.gitlab-ci.ymla spec-gate job — paste it into yours if you have one
Azure Pipelinesazure-pipelines.ymlsteps — paste them into yours if you have one
JenkinsJenkinsfilea Spec gate stage — paste it into yours if you have one

Then ask what it checks, and what it lacks:

bash
specgate ci status
text
  ◆ specgate · ci status   .github/workflows/spec-gate.yml

  ✔  the specification (validate --strict)
  ✔  the project's tests (check runs test_cmd)
  ✔  the architecture check (check runs arch_cmd)
  ✔  Ubuntu, macOS and Windows
  ✔  the requirement ids against the base branch (check --base)
  ✔  the quality checks (quality run)
  ✔  the pack drift (validate --against-lock)
  ✔  the pending-work plan (plan --format json)

  ✔  Everything specgate can check runs in CI.

GitHub Actions, step by step#

The GitHub job is the complete one. Each step says in the YAML what it checks and what to delete to remove it:

StepWhat it doesRemove it?
Ubuntu, macOS, WindowsThe same gate on the three, because paths, line endings and shells differDelete two entries of os: to keep one
checkout with fetch-depth: 0The whole history, so the ids can be compared with the base branchOnly with --base below
Toolchain and dependenciesNode, or a JDK for Maven and Gradle, and the project's dependencies, for its testsNo
The gatecheck --base origin/<base>: ids, specification, architecture, tests; and what the branch changes in the controls, as controls_changed_on_branch for the reviewerNever — this is the gate
Quality checksquality run --stage ci, on Ubuntu only, because the checks run in Docker. Not configured: says how, and passesDelete the step
Pack driftvalidate --against-lock: the domain packs still match .specops.lock. No packs: skippedDelete the step
Pending-work planplan --format json, kept as the spec-plan artifact of the runDelete both steps

A step whose tool is not configured yet — no test_cmd, no quality checks, no packs — says so in the log and passes, so the job is green on day one and checks more as you configure more.

One job on Ubuntu running only the gate, if that is all you want — GitHub only, and with no --base, so no id comparison and no controls report, no pack drift and no plan:

bash
specgate ci init --provider github --minimal --force

GitLab, Azure and Jenkins#

Their jobs run the gate, the pack drift and the plan, on one Linux image. This is GitLab's, as specgate ci init --provider gitlab --stdout writes it:

yaml
spec-gate:
  image: node:22
  stage: test
  script:
    - npm install
    # The gate: the specification and the project's tests.
    - |
      npx @rsaglobaltech/specgate@1.8.0 check .
    # Supply-chain gate: fails when rendered pack content no longer matches the
    # digest pinned in .specops.lock. Skipped when no packs are installed.
    - >
      if [ -f .specops.lock ]; then
        npx @rsaglobaltech/specgate@1.8.0 validate . --against-lock;
      else
        echo "No .specops.lock — no packs installed, nothing to check.";
      fi
    - npx @rsaglobaltech/specgate@1.8.0 plan --project-dir . --format json > spec-plan.json
  artifacts:
    when: always
    paths:
      - spec-plan.json

Azure's runs the same three as steps on ubuntu-latest, publishing the plan as a build artifact; Jenkins' as a declarative pipeline in a node:22 container, archiving the plan in post { always }.

What they do not do yet, compared with GitHub's: compare the ids with the base branch, and run the ci-stage quality checks. Add both by hand: fetch the branch the merge request targets, then pass it as --base. In GitLab, in a merge request pipeline:

yaml
spec-gate:
  variables:
    GIT_DEPTH: 0
  script:
    - npm install
    - git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
    - npx @rsaglobaltech/specgate@1.8.0 check . --base "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
    - npx @rsaglobaltech/specgate@1.8.0 quality run --stage ci --base "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"

The target branch is $(System.PullRequest.TargetBranchName) in Azure Pipelines and $CHANGE_TARGET in a Jenkins multibranch pipeline; fetch it the same way. The quality checks run in Docker, so the job needs one: a docker:dind service in GitLab, a Docker-capable agent in Jenkins; Azure's ubuntu-latest has it.

Make it a required check#

A failing job does not stop a merge on its own:

ProviderWhereWhat to turn on
GitHubSettings → Rules → Rulesets (or Branches)Require status checks to pass and select spec-gate (ubuntu-latest), spec-gate (macos-latest) and spec-gate (windows-latest) — the job runs on three systems (--minimal: plain spec-gate). Push a branch once first, so GitHub has seen the job.
GitLabSettings → Merge requestsPipelines must succeed
Azure DevOpsRepos → Branches → your branch → Branch policiesBuild validation with the pipeline, set to Required
JenkinsYour SCM's branch protectionRequire the status Jenkins reports for the Spec gate stage — the GitHub or Bitbucket Branch Source plugin reports it

With --base, the job's log also names what the branch changes in the controls — the guard, .specgate/gate.yaml, approvals, evidence — as controls_changed_on_branch, a warning by default (rule controls). It is for the reviewer: make .specgate/ and docs/specs/changes/*/approvals.json code-owned, so that a change to them needs their review.

Protect develop too if you merge features into it. Your team's first pull request covers what the author and the reviewer do once the check is in place.

Pin the version, and move it on purpose#

Every generated command runs @rsaglobaltech/specgate@<version>, the version that wrote it. A release can make the gate stricter, and a pipeline must not change under a green branch. To move to a new version:

  1. Upgrade locally and run specgate check. Fix what the new version finds, or record it (Adopt it without a red build).
  2. Change the version in the CI file — one search and replace — or write the job again with specgate ci init --force if you never edited it.
  3. Open a pull request with both: CI proves the new gate on the same code.

specgate update refreshes the agent files after an upgrade; it does not touch the CI file, which is yours.

Secrets and caches#

  • Private domain packs: a SPECOPS_TOKEN secret with read access to their repository. The GitHub job passes it to the pack-drift step.
  • Quality checks get environment variable names through env: in harness.config.yaml — SONAR_TOKEN, a registry token — and read their values from the CI's secrets. A value written in the file is refused.
  • Docker images: specgate quality doctor --pull fetches every check's image ahead of the run. Cache them, or the dependency volumes (specgate-m2, specgate-gradle, specgate-npm), with your CI's cache.

Several projects#

  • A monorepo: list its projects under projects: in specops.config.yaml, and validate at the root validates each one and fails with a summary per project.
  • Several repositories of one product: one gate across them — see Workspace.

Your own pipeline#

Every gate command takes --json: one document on standard output with each stage, its command, its result and its findings, each with a stable code and a fix. Branch on code, never on the message. Exit codes are 0, 1 and 2. The full contract: The JSON contract.

bash
npx @rsaglobaltech/specgate@1.8.0 check . --ci --json > gate.json

Next#