Release gates
Block a merge or a release until your suite passes, using the Cofactor CLI in CI and the proofs check.
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.
cofactor test-suite run --suite "Checkout" --at <commit sha>
--suitetakes the suite's name or id. List your suites withcofactor test-suite suites.--atruns 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:
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 code | Meaning |
|---|---|
0 | Every test passed. |
1 | A 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. |
2 | No 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
-
Create an API key for CI. An organization admin runs this once. The command prints the secret one time.
bashcofactor api-key create --name "CI suite runs" --scope test-run:run --scope test-run:read
test-run:runstarts the suite.test-run:readlets the command follow it. Add--expires-at <date>if you want the key to expire. See API keys. -
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. -
Add
.github/workflows/cofactor.yml:yamlname: 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_TOKENon its own, so there is no login step.head.shais 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
- Open the pull request once so the job runs. GitHub lists a check only after it has run.
- In your repository, open Settings, then Branches, and add or edit the rule for your main branch.
- 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
- Open a pull request that breaks one of the suite's tests.
- The
Cofactor suitejob fails with exit code1, and the merge button stays blocked. - Fix the test or the code and push. The job runs again on the new commit and the merge unblocks.
Go deeper
- Triage explains a failed run.
- Suites and schedules covers building the suite.
- CLI in CI covers other CI systems and triage steps.
- Proofs covers the
cofactor / proofscheck on pull requests.