Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# CI

This context covers the checks that verify a change, and the machines that run
them. It covers the GitHub Actions workflows of `cipherstash/stack`. It also
covers the CI spend of the other repositories that share its budget.

## Language

**CI budget**:
The most that the repositories sharing it may spend on CI in one calendar
month. Vendor invoices measure it, including fixed costs such as licences and
cloud infrastructure. When an invoice also covers other repositories, only the
part for these repositories counts. List-price estimates track it between
invoices, but do not replace it.
_Avoid_: build minutes, runner minutes

**PR push**:
A new head commit on a pull request's branch. Each one starts the push checks
again.
_Avoid_: PR run, CI run

**Push check**:
A check that runs on every PR push, so the author learns of a failure while
still working on the change.
_Avoid_: fast check, PR check

**Gate check**:
A check that runs when a pull request is in a merge queue, instead of on every
PR push. `main` and `next` each have a merge queue. An author can ask for a
gate check to run earlier on the pull request. A failed gate check blocks the
merge.
_Avoid_: heavy check, full CI, merge check

**Early run**:
A run of the gate checks on a pull request before it joins a merge queue. An
author asks for one by adding the `ci:full` label. Each time the label is
added gives one early run.
_Avoid_: full run, ci:full run

**Queue commit**:
The commit GitHub builds for a pull request in a merge queue. It contains
the entry ahead of it, plus the pull request. Checks in the queue test this commit.
_Avoid_: merge group commit, temporary branch

**Trigger paths**:
The paths whose change makes a check run, on PR pushes and in the merge queue.
Every check has them, or a written reason for running on every change.
_Avoid_: path filter, relevance filter, affected checks

**Selector job**:
The first job of a workflow. It selects the checks that run, by comparing the
files a change touches with each check's trigger paths. When it cannot decide,
it fails. The change then cannot merge until someone runs it again.
_Avoid_: path-filter job, decider, router

**Summary job**:
The last job of a workflow. It passes when every check that the selector job
selected has passed. It is the only job of the workflow that branch rules
require.
_Avoid_: required job, status job

**Failsafe**:
The test that fails when the selector job does not decide whether a job runs.
A job with a written exemption passes. The failsafe reads workflow files. It
does not act while a workflow runs.
_Avoid_: lint, selector guard, path-filter lint

**Light job**:
A job that runs acceptably on a GitHub-hosted standard runner. Whether a job is
light says where it runs, not when: a light job can be a gate check.
_Avoid_: small job, cheap job

**Heavy job**:
A job that needs more machine than a GitHub-hosted standard runner gives it,
and runs on a self-provisioned cloud runner instead. Whether a job is heavy
says where it runs, not when: a heavy job can be a push check.
_Avoid_: big job, 16-core job

## Relationships

- Three separate choices apply to each check. Its trigger paths decide whether
it runs at all. Being a push check or a gate check decides when it runs.
Being a light job or a heavy job decides where it runs.
- The fuzz regression replay, for example, is a light job and a gate check.
- Mutation testing is expensive but important. So it runs only once the
design and implementation of a change are settled. Its failures must be
fixed before the change merges. That makes it a heavy job and a gate check.
133 changes: 117 additions & 16 deletions .github/workflows/mutants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@ name: Mutants
#
# The sticky comment needs `pull-requests: write`, which is registered in
# scripts/__tests__/workflow-publish-permissions.test.mjs `REPO_WRITE_JOBS`.
# Pull requests only, so `push` has no filter to mirror; recorded in
# scripts/__tests__/workflow-paths-filter-parity.test.mjs.
#
# The `selector` job decides whether the gate runs, and `summary` reports the
# result (ADR 0003). `summary` is the one job of this workflow that branch
# rules require.

on:
# No branch filter: a stacked PR (a feature branch as base) must run this
# gate too.
pull_request:
paths:
- packages/stack-auth/**
- packages/stack-encrypt/**
- Cargo.toml
- Cargo.lock
- mise.toml
- mise.test.toml
- .cargo/mutants.toml
- .github/workflows/mutants.yml
# Keep these excludes last so docs-only changes are skipped.
- "!**.md"
- "!**.example"
# gate too. No path filter either: a workflow that a path filter skips leaves
# its required checks pending, and GitHub's documentation on required status
# checks says that blocks a merge. The trigger paths are in the `selector`
# job instead.
pull_request: {}
workflow_dispatch: {}

defaults:
Expand All @@ -62,8 +55,88 @@ env:
CARGO_NET_GIT_FETCH_WITH_CLI: true

jobs:
# The selector job: it decides whether `mutants` runs. It runs on every event
# and is never skipped, because `mutants` needs it. When it cannot decide it
# fails, and that fails `summary`: a selector that answered nothing would
# skip the gate, and `summary` counts a skipped job as passed (ADR 0003).
#
# On a GitHub-hosted runner because the gate waits for it, and a
# self-provisioned machine takes longer to start. No checkout: on a pull
# request, dorny/paths-filter lists the changed files through the GitHub API.
selector:
name: Selector
runs-on: ubuntu-latest
timeout-minutes: 10
# Each output is named after the filter that decides it.
# `scripts/__tests__/workflow-selectors.test.mjs` follows a job's `if:` to
# its filter by that name.
outputs:
mutants: ${{ steps.decide.outputs.mutants }}
steps:
# Only on a pull request, which has a base to compare with. Other events
# select every job in the step below.
#
# `every` makes a file count only when it matches every rule. That is what
# makes the two `!` rules exclude documentation: under dorny's default,
# `some`, a `!` rule matches every other file in the repository. So the
# trigger paths are one brace pattern, written across lines: YAML drops a
# line break that ends in `\`, with the next line's indent.
- id: filter
if: github.event_name == 'pull_request'
uses: dorny/paths-filter@0e4a8c6effa4802afeda77dc8d303f8176d7dfad # v3
with:
predicate-quantifier: every
filters: |
mutants:
- "{\
packages/stack-auth/**,\
packages/stack-encrypt/**,\
Cargo.toml,\
Cargo.lock,\
mise.toml,\
mise.test.toml,\
.cargo/mutants.toml,\
.github/workflows/mutants.yml\
}"
- "!**/*.md"
- "!**/*.example"

# Explicit default, not `|| 'true'`, which trips GitHub's inconsistent
# treatment of the string 'false'. On a pull request, an answer other than
# `true` or `false` means the filter did not decide, so the step fails
# rather than write it.
#
# The event and the answer arrive through `env:`, not through a `${{ }}`
# in the script. That lets `scripts/__tests__/workflow-selectors.test.mjs`
# run this script and read back what it wrote.
- id: decide
env:
EVENT_NAME: ${{ github.event_name }}
MUTANTS: ${{ steps.filter.outputs.mutants }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" != "pull_request" ]; then
MUTANTS=true
fi
answers=("mutants=$MUTANTS")
for answer in "${answers[@]}"; do
case "${answer#*=}" in
true|false) echo "$answer" >> "$GITHUB_OUTPUT" ;;
*)
echo "::error::The path filter answered '${answer#*=}' for ${answer%%=*}. The selector cannot decide which jobs to run."
exit 1
;;
esac
done

mutants:
name: Mutants gate
needs: [selector]
# Written as an exclusion, not a list of events: every event other than a
# pull request runs the gate.
if: >-
github.event_name != 'pull_request'
|| needs.selector.outputs.mutants == 'true'
runs-on: blacksmith-16vcpu-ubuntu-2204
timeout-minutes: 120
permissions:
Expand Down Expand Up @@ -208,3 +281,31 @@ jobs:
;;
esac
echo "No surviving mutants in the PR diff."

# The summary job: the one job of this workflow that branch rules require. It
# has the same name on every event. It passes when every needed job passed or
# was skipped. Skipped counts as passed because the selector skips the gate
# on a change it does not read. A failed gate still fails this job, because
# the gate is in `needs` and reports its failure.
summary:
name: Mutants summary
needs: [selector, mutants]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check that every needed job passed or was skipped
env:
RESULTS: ${{ join(needs.*.result, ' ') }}
run: |
set -euo pipefail
echo "Needed results: $RESULTS"
for result in $RESULTS; do
case "$result" in
success|skipped) ;;
*)
echo "::error::A needed job reported '$result'."
exit 1
;;
esac
done
Loading
Loading