Docs/Release gates
#

Release gates

Block a merge or a release until your suite passes, using the Cofactor CLI in CI and the proofs check.

Block merges on my Cofactor suite

A release gate stops a merge until your tests pass. You build one from two parts: a command that runs your suite and fails when a test fails, and a GitHub rule that blocks the merge when that command fails.

Run a suite from anywhere

cofactor test-suite run runs a suite and streams the results to your terminal. It exits with a code that any CI system can act on.

bash
cofactor test-suite run --suite "Checkout" --at <commit sha>
  • --suite takes the suite's name or id. List your suites with cofactor test-suite suites.
  • --at runs the suite on a sandbox of your application at that version. For an application built from GitHub, pass the full 40-character commit SHA. For a pushed image, pass a push id or tag. See Build from GitHub and Build from a pushed image.

The suite's tests must run on a sandbox, or the command refuses to pin and exits 1.

Without --at, each test runs on its own default environment, not on your change. Always pass --at when you gate a pull request.

The command prints each test as it finishes, then a verdict:

text
Starting remote workflow tests...

Starting test suite: Checkout
  Env mode: mixed
  Pinned at: 0123456789abcdef0123456789abcdef01234567 (never feeds visual baselines)

  ✓ Add to cart
  ✓ Pay with a card
──────────────────────────────────────────────────
PASSED: 2 of 2 workflows passed
Pinned at: 0123456789abcdef0123456789abcdef01234567

When a test fails, the verdict reads FAILED: 1 of 2 workflows failed. The command then lists the failed tests and prints a cofactor triage wait command that starts diagnosis.

Exit codeMeaning
0Every test passed.
1A test failed, timed out or was canceled. The command also exits 1 when the run could not start, for example a suite with no tests, or when the result stream ended early.
2No test failed, but a platform error meant some tests never got a verdict, so the suite proved nothing.

Any non-zero code fails a CI step.

Run it in GitHub Actions on every pull request

  1. Create an API key for CI. An organization admin runs this once. The command prints the secret one time.

    bash
    cofactor api-key create --name "CI suite runs" --scope test-run:run --scope test-run:read
    

    test-run:run starts the suite. test-run:read lets the command follow it. Add --expires-at <date> if you want the key to expire. See API keys.

  2. In your repository, open Settings, then Secrets and variables, then Actions, and add the secret as COFACTOR_API_TOKEN. Keep it out of chat and files.

  3. Add .github/workflows/cofactor.yml:

    yaml
    name: cofactor
    on: pull_request
    jobs:
      suite:
        name: Cofactor suite
        runs-on: ubuntu-latest
        env:
          COFACTOR_API_TOKEN: ${{ secrets.COFACTOR_API_TOKEN }}
        steps:
          - run: npm install -g @runcofactor/cli
          - run: cofactor test-suite run --suite "Checkout" --at ${{ github.event.pull_request.head.sha }}
    

    The job needs no checkout. The CLI reads COFACTOR_API_TOKEN on its own, so there is no login step. head.sha is the latest commit on the pull request branch, so each push runs the suite on the code under review.

Pull requests from forks receive no repository secrets, so the job cannot run for them.

Block merges on it

  1. Open the pull request once so the job runs. GitHub lists a check only after it has run.
  2. In your repository, open Settings, then Branches, and add or edit the rule for your main branch.
  3. Turn on Require status checks to pass before merging, then add Cofactor suite.

From now on a pull request cannot merge until the Cofactor suite job passes.

Check it worked

  1. Open a pull request that breaks one of the suite's tests.
  2. The Cofactor suite job fails with exit code 1, and the merge button stays blocked.
  3. Fix the test or the code and push. The job runs again on the new commit and the merge unblocks.

Go deeper