Metadata-Version: 2.4
Name: pubrules
Version: 0.49.0
Summary: The setup every package shares: managed files, reusable CI, the Rust crate standard and the Gherkin rule.
Author-email: David Schryer <schryer@gmail.com>
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/Sustenaut/pubrules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML>=6
Dynamic: license-file

# pubrules

The testing and quality setup every package shares:
- the pin of pubtest, the pytest-bdd plugin and Gherkin steps every suite loads;
- the files each repository must hold, kept in step by a command;
- reusable CI workflows;
- the Rust crate standard, with a Claude Code agent that audits crates
  against it.

Every package tests its behaviour the same way: Gherkin feature files, run
by pytest-bdd (or cucumber-js and quickpickle in Node), with pubtest's steps,
driving the built program as a user would. pubrules is that setup, written once.

## The steps: pubtest

The pytest plugin and the Gherkin steps every suite loads are
[pubtest](https://github.com/Sustenaut/pubtest)'s: one grammar
([GRAMMAR.md](https://github.com/Sustenaut/pubtest/blob/main/GRAMMAR.md)), a
pytest-bdd plugin and an npm package for cucumber-js and quickpickle, on PyPI as
`pubtestrules` (PyPI's `pubtest` is another project; the package imported is still
`pubtest`). The managed `tests/requirements-pubrules.txt` names the oldest pubtest whose
steps pubrules' own files use (`pubtestrules>=X`, which `sync --check` holds the pin to)
and pins pubrules itself by name (`pubrules==X`), and each repository's
`tests/requirements.txt` pins `pubtestrules==X`, which its lock holds with every
published hash and the nightly moves to the newest release on PyPI (or the PyPI
mirror, `mirror.pypi`), so a pubtest release needs no pubrules release. `pubrules sync`
pins the one the lock has where `tests/requirements.txt` pins none (`sync --check`
fails), and pins by name the release a wheel pin of pubrules 0.48.0 and before
names; `pubrules lock` refuses any package named `pubtest`. So every suite gets `ctx`, `binary(name)`, `run(...)`, the tag markers and the steps
(`it succeeds`, `it prints "…"`, `the result is "V"`, the files, stand-ins, HTTP and
secrets steps) without writing them. pubrules carried the plugin itself until 0.42.0;
a suite that imported `pubrules.plugin` imports `pubtest.core` instead.

## Other packages' releases

pubrules holds no version of pubrel, pubtest, pubsec or pubdeploy. Each
repository pins them: pubrel in `ci.release.pubrel` (or the release workflow
sync wrote), pubtest in `tests/requirements.txt`, pubsec and pubdeploy in
`deploy.providers` (or the launcher sync wrote). The nightly moves each to
its latest release, as it moves any other pin. Only where a repository has
no pin yet (`pubrules new`, `pubrules init`, a launcher written for the
first time) is one read: from the release-state file `PUBRULES_RELEASES`
names, when its `releases` block lists the package, otherwise from the
package's latest GitHub release.

```json
{"releases": {"pubrel": "0.8.0", "pubtest": "0.2.2",
              "pubsec": {"version": "0.3.0", "sha256": "…"}}}
```

A version alone, or with its wheel's sha256 (without it, the wheel is
fetched and hashed). With neither, the command stops and says so.

## Keeping the files in step

```sh
pubrules init --kind=rust --bin=pub   # or --kind=utility, --kind=service --project=NAME, or --kind=content
pubrules lock                         # pin tests/requirements.txt, with hashes
pubrules sync --check                 # CI: fail if a managed file drifted
pubrules sync                         # after bumping pubrules: rewrite them
```

A repository is one of four kinds, named in `pubrules.json`:

| Kind | What it is |
|---|---|
| `rust` | A released Rust package, held to the Rust crate standard (below) |
| `utility` | A released tool or library in any language, or several, without the Rust package's extra checks |
| `service` | A repository that deploys rather than releases, and runs its secret-needing commands through `./with-secrets` (below) |
| `content` | An authored-content repository, private: pubrules neither releases nor deploys it; its own tooling builds and checks it through the ci tests job (below) |

The kind `python` (before 0.10.0) and `python-utility` (0.10.0) are now
`utility`: a package's language doesn't decide its kind. `sync` says so
when `pubrules.json` still names an old one.

Files are **managed**, owned by pubrules and rewritten by `sync`, or
**seeded**, written once by `init` and the repository's own after that.

- **Managed:** `tests/requirements-pubrules.txt` (the shared pins and the pubrules wheel), `pubrules` (below), and `AGENTS.md`, the working rules agents and people follow in every repository, starting with when a pull request is draft (below). For a Rust package, also `pubrules.mk`, `rust-toolchain.toml`, and the crate standard with its agent (below). For a Python package (a utility whose CI is Python's), `pubrules-python.mk`: the make targets every Python package shares (`venv`, `functional`, `lint`, `fmt`, `lock`, `sync-check`, `wheel`, `clean`, `help`), with the suite on every core (`PYTEST_ARGS ?= -n auto`) and its coverage in `coverage/coverage.xml`. Set `PYTEST_ARGS`, `FUNCTIONAL_ENV` (variables the suite needs, such as `PYTHONPATH=$(CURDIR)/src`) or `EDITABLE` (what `venv` installs editable; empty for nothing) in the Makefile, before the include. `sync --check` fails until the Makefile includes it and `pyproject.toml`'s `[tool.coverage.run]` sets `patch = ["subprocess"]` and `parallel = true`, so the coverage of xdist's workers and of the programs the suite starts is combined. For a service, `with-secrets`. For a Python package or a service whose ci block gives a `lint` command, `pubrules-ruff.toml`, the Python standard (below). A content repository has the common files only.
- **Seeded:** `tests/requirements.txt` (includes the managed one), `tests/pytest.ini`, `.github/workflows/ci.yml`, for a Rust package a `Makefile` that includes `pubrules.mk` (for a Python package, one that includes `pubrules-python.mk` and adds `check`), and for a service `with-secrets.json`.
- **Healed:** `.gitignore` is the repository's own, but it must ignore `.env`, where local tools read secrets (`./with-secrets` its Bitwarden token). `init` and `sync` append `.env` when it's missing, with a comment above it, and leave the rest of the file as it is; `sync --check` fails until it's there. A pattern that already covers it, such as `/.env` or `.env*`, counts, and a later `!.env` takes it back.

Extensions go in the seeded files, so nothing managed is ever edited by
hand. `sync --check` also fails when `tests/requirements.lock` pins another
pubrules, and in a Rust repository it runs `pubrules conform` (below).

Run as any release but the one `tests/requirements.lock` pins, pubrules
refuses the commands that judge or write the repository by its standard
(`sync`, `lock`, `supply-chain`, `doc-coverage`, `required`, `conform`,
`audit`, `record`) and says to run `make venv`, use `./pubrules`, or, when
it is the newer one, `pubrules bump`. `PUBRULES_ANY_VERSION=1` runs it anyway.
In a Rust repository, each `pubrules.mk` target that runs a tool from `.venv`
rebuilds `.venv` first when the lock has changed since `make venv` last
ran, so a moved pin never runs the old pubrules.
Its `functional` and `coverage` run the Gherkin suite on every core
(`PYTEST_ARGS ?= -n auto`, pytest-xdist, which the shared requirements
pin); `PYTEST_ARGS =` in the Makefile runs it on one. pubrules' own
`make functional` does the same.

**`./pubrules`** runs the pubrules this repository pins, whichever (if any) is
installed: `./pubrules sync --check`. It
runs `uvx` on that release's wheel, which uv fetches once and caches, in
the repository's root, from whichever directory it is called. Without uv
it says how to install it. It is managed, so `pubrules sync` moves it with
the rest when a repository moves to a new pubrules.

## Services: `./with-secrets` and `service-ci.yml`

A service runs every command that needs a secret through `./with-secrets`,
which reads its Bitwarden project, as `with-secrets.json` says, and runs the
command with the secrets in its environment only:

```sh
./with-secrets terraform plan
./with-secrets scripts/setup-backup.sh
```

That script, managed in every repository with a `with-secrets.json`, is one
line: `./pubsec run --cwd "$PWD" -- COMMAND`. Holding a secret's value is
[pubsec](https://github.com/Sustenaut/pubsec)'s, not pubrules', so `pubrules
sync` writes `./pubsec` beside it, which runs the repository's pubsec
(`deploy.providers`' entry, or where a repository has no deploy block the one
`./pubsec` already fetches, which the nightly moves to pubsec's latest release), its wheel checked against its sha256 on every run. pubsec's README, "Services:
./with-secrets", explains `with-secrets.json` and `pubsec run`.

`service-ci.yml` is a service's CI: `pubrules sync --check` and shellcheck,
`terraform fmt`, `init -backend=false` and `validate` when `terraform-dir`
is given, the repository's own tests when `test` is, and SonarQube Cloud's
scan (below). No job but the scan has secrets. Its `passed` job is the one check a ruleset would require; private
repositories on GitHub Free have no rulesets, so there it is a summary.

### Sending secrets to a repository

`pubrules.json`'s `github_app` and `secrets` blocks name the values a
repository needs from Bitwarden and where each goes on GitHub, and `pubrules
sync --check` refuses one it can't use. Sending them is pubsec's:
`./with-secrets ./pubsec app-secrets [--check]` (pubsec's README, "Sending
secrets to a repository"). `pubrules app-secrets` says so, and is removed in
the next minor.

### Creating a GitHub App

`./pubsec github-app create MANIFEST` makes an app with GitHub's manifest
flow and puts its three values in Bitwarden, where `./pubsec app-secrets`
finds them (pubsec's README, "Creating a GitHub App"). `pubrules github-app
create` says so, and is removed in the next minor.

### Making a service account key

`./pubsec service-account-key create` makes a Google Cloud service account
key and writes it to Bitwarden from memory (pubsec's README, "Making a
service account key"). `pubrules service-account-key create` says so, and is
removed in the next minor.

## Content repositories

A content repository holds authored information, documents or data, and is
private. pubrules neither releases nor deploys it: it has no release, no
release tags and no secrets wrapper, and any versioning of what it holds is
its own tooling's, never pubrules' or pubrel's. What that looks like depends
on the content: one body of content with no versions, or a monorepo of
content projects, each versioned on its own (as publets are, each a version
of its project). pubrules sees one repository either way, and its CI runs
whatever checks the content's tooling gives it. The line between them:
pubrules, the packages split off it and pubrel converge and version code,
configuration and state; the content's own publet packages manage the
content itself, its versioning, publication and state. `pubrules init --kind=content`
writes the common managed files only (`./pubrules`, `AGENTS.md`,
`tests/requirements-pubrules.txt`, `tests/install-lock`) and the seeded test
files, and needs no `--project`.

- **CI:** `checks` (the managed files in step, and shellcheck on the
  repository's `**/*.sh` unless `with` gives `shellcheck`) and, when `with`
  gives a `test`, `tests`, which runs the checks the repository's own tooling
  makes, after `setup`. There is no scan: SonarQube Cloud has no code to
  analyse, and does not analyse a private repository for free. A `release`
  in the ci block stops sync.
- **Protect:** main's ruleset as for any repository; its protect block's
  `tags` defaults to false, since there are no release tags to keep, and
  `"tags": true` or a `release_app` stops sync.
- **Nightly:** governed like any other repository: the nightly moves its
  pubrules, its lock, the workflows' and actions' pins, any release wheel
  its requirements files pin and any pub* package they pin by name.

## The Python standard: Ruff, and the lint job

A Python package or a service turns the Python standard on with one setting, a
lint command in its ci block:

```json
"ci": {"with": {"setup": "make venv", "test": "make functional", "lint": "make lint"}}
```

Then:

- the CI `pubrules sync` writes runs a `lint` job (`job-python-lint.yml`,
  `ci / lint`, part of `ci / passed`): `setup` (by default `make venv`), then the
  lint command, with Ruff's findings shown on the pull request's lines;
- `pubrules-ruff.toml` is managed: the shared rules, Ruff's defaults (pyflakes
  and pycodestyle's errors) with flake8-bugbear (`B`), flake8-simplify (`SIM`),
  pyupgrade (`UP`), isort (`I`) and pylint's size limits (`PLR0911`, `PLR0912`,
  `PLR0913`, `PLR0915`, at pylint's own limits), a line length of 120, and Ruff's
  formatter;
- `tests/requirements-pubrules.txt` pins the Ruff those rules are written for,
  so the rules and the tool move together, with pubrules, and `sync --check`
  fails until `tests/requirements.lock` pins it (`pubrules lock`);
- `sync --check` fails until `pyproject.toml` takes the rules in, and while it
  loosens them:

```toml
[tool.ruff]
extend = "pubrules-ruff.toml"
```

A repository may make the rules stricter (`lint.extend-select`) and name the
files a rule does not fit (`lint.per-file-ignores`). It may not set
`line-length`, `lint.select`, `lint.ignore` or `lint.extend-ignore` (or their
top-level spellings): those are the standard's. A single exception is a
`# noqa: CODE` on its line, with the reason beside it.

`pubrules-python.mk` gives every Python package `make lint` (`ruff check .`,
then `ruff format --check .`, as CI runs them) and `make fmt` (Ruff's safe
fixes, then the formatter). A service writes the same two targets in its own
Makefile. CI is the gate: there are no pre-commit hooks. Without a lint
command, nothing here applies, so each repository turns the standard on when
its code is ready for it. A Node, Rust or content repository has no lint job.

## Hosting

A repository's hosting is [pubhost](https://github.com/Sustenaut/pubhost)'s: the
Terraform modules that turn `pubrules.json`'s `hosting` block into DNS, mail,
DNSSEC, Cloud Run and bucket resources, `terraform.yml`, which applies a stack
from CI, the `deploy-static` and `docker-build` actions, and `pubhost dns check`
and `pubhost site check`. Each is used from there by commit:
`Sustenaut/pubhost/actions/docker-build@<commit> # vX.Y.Z`,
`source = "github.com/Sustenaut/pubhost//terraform/hosting?ref=<commit>" # vX.Y.Z`.
pubhost's README describes every setting of the hosting block.

pubrules keeps the block's shape: `pubrules sync` (and `sync --check`, in CI) checks
it (`src/pubrules/hosting.py`) and stops on anything it does not know, since
Terraform drops a setting its types do not name. A new provider type is learnt
here first, then by pubhost's modules. pubrules also keeps
`job-service-terraform.yml`, which checks a stack without a backend, and the
`ci / site` job ("Generated CI" below).

## pubrules' actions

- **`actions/apt-install`:** installs the apt packages `packages` names
  (separated by any whitespace, so a YAML block of lines will do;
  `no-install-recommends` is `true` by default), keeping the package lists
  and the .deb files in the Actions cache under
  `apt-<ImageOS>-<ImageVersion>-<arch>-<sha256 of the sorted packages and
  the flag>-<run id>-<attempt>` (off a hosted runner, the release's
  codename and `self-hosted`), restored by all but the run, so the newest
  entry wins. On a hit the packages are installed with `--no-download` and
  no `apt-get update`, so nothing is fetched; a hit that will not install,
  or a miss, updates the lists and installs, tried as retry tries a script,
  and saves this run's entry, so a stale cache mends itself even where
  `ImageVersion` never changes. GitHub evicts the older entries once no
  run has used them for 7 days. A cache service that refuses,
  as for a self-hosted runner whose billing is blocked, only means the
  packages come from the mirror.

  ```yaml
  - uses: Sustenaut/pubrules/actions/apt-install@<commit> # vX.Y.Z
    with: { packages: gcc-s390x-linux-gnu libc6-dev-s390x-cross qemu-user }
  ```
- **`actions/cache`:** keeps what a build fetched or made between runs,
  by the entries of pubrules.json's `cache` block (see "Caching a build"
  below). Call it with `step: restore` before the build and `step: save`
  after it, which also drops what no run used; `fresh: true` restores no
  fetched entry, and `refresh: true` restores no entry at all.
- **`actions/pr-label`:** says whether the pull request a run is for
  carries a label, `refresh cache` by default (`label` names another),
  as its output `present`. The pull request is the event's own, the one a
  merge queue group is for, or, on a push, the ones merged into the pushed
  commit, which needs `pull-requests: read`. One label a person puts on a
  pull request can so steer what its deploy does once it merges, such as
  rebuilding everything:

  ```yaml
  permissions: { contents: read, pull-requests: read }
  steps:
    - id: refresh
      uses: Sustenaut/pubrules/actions/pr-label@<commit> # vX.Y.Z
    - uses: Sustenaut/pubrules/actions/cache@<commit> # vX.Y.Z
      with: { step: restore, refresh: "${{ steps.refresh.outputs.present }}" }
  ```
- **`actions/retry`:** runs a bash script (`run`) with `bash -ec` up to
  `tries` times (3), for a step a flaky download can fail. After each
  failed try but the last it warns "`<what>` failed (attempt N of T)"
  (`what` is `setup` by default) and waits `pause` seconds (15); it fails
  when every try did. The inputs reach the script through its
  environment, so the script runs exactly as given.
- **`actions/terraform-init`:** `terraform -chdir=<dir> init <args>`
  (`dir` `.`, `args` `-input=false`, `terraform` the binary), tried as
  retry tries a script, then once more with every provider from
  pubrules.json's `mirror.terraform`, when it names one (see "A wheel
  mirror"); the lock's hashes still check what the mirror gives.

  ```yaml
  - uses: hashicorp/setup-terraform@<commit> # vX.Y.Z
  - uses: Sustenaut/pubrules/actions/terraform-init@<commit> # vX.Y.Z
    with: { dir: infra, args: -backend=false -input=false }
  ```

pubrules' own reusable workflows run their setup and terraform init through
these two, pinned by a release's commit as any caller pins them: a reusable
workflow runs in the caller's checkout, where `./actions/` is the caller's.
So a change to either action reaches the workflows one release later, when
their pins move to the release that has it.

## Deploying a service to k3s

The deploy walk is [pubdeploy](https://github.com/Sustenaut/pubdeploy)'s:
`k8s-deploy.yml`, the kustomize component `k8s/components/app`, `pubdeploy k8s
preflight` and `diagnose`, and the scheduled `deploy-check.yml`. A caller pins
`Sustenaut/pubdeploy/.github/workflows/k8s-deploy.yml@<commit> # vX.Y.Z`;
pubdeploy's README, "Deploying a service to k3s", says what it takes.
`actions/deploy-ssh` is pubdeploy's too.

## Declaring what a service needs

pubrules.json's `deploy` block says what a service needs before it deploys,
and `./pubdeploy walk` checks and makes it (pubdeploy's README, "Declaring
what a service needs", "Making what a service needs" and "Provider
contract"). pubrules keeps three things of it:

- **`deploy.providers`** lists pubsec and pubdeploy, each the repository's
  own pin, which `pubrules bump` and the nightly move through pubdeploy's
  hook: `pubrules sync` adds one where none is listed (the one its launcher
  already runs, or else the latest release, below), changing nothing else of
  pubrules.json, and `sync --check` fails without one. pubrules holds no
  version of either.
- **The launchers.** In a repository with a deploy block, `sync` writes
  `./pubdeploy`, which runs the listed pubdeploy with every other
  `deploy.providers` wheel, and `./pubrules` runs with every wheel, pubdeploy's
  too, each fetched once into the user's cache and checked against its
  sha256 on every run.
- **The hooks.** `pubrules sync` calls each `sustenaut.sync` hook,
  `check(root, config, check) -> (lines, failed)`, after its own work, and
  `--check` fails when one says so; `pubrules bump` calls each
  `sustenaut.bump` hook, `bump(root) -> lines`, before it writes the
  launchers. pubdeploy's are the deploy block's offline check and the
  scheduled walk's caller, and moving deploy.providers and the uses of
  pubdeploy's workflows to their latest releases. A hook that fails is said
  by its name and its error's type alone. With a deploy block and no
  pubdeploy installed, `sync --check` fails, saying so: CI's environment
  installs it from the lock, since `tests/requirements-pubrules.txt` lists
  every deploy.providers wheel, and `./pubrules` runs with each.

## A service's needs from GitHub Actions

A step that used to be a per-repository `scripts/go-live*.sh` is a declared need
(pubdeploy's README), and the convergence engine
([Sustenaut/convergence-engine](https://github.com/Sustenaut/convergence-engine))
checks it, or fulfils it once a person approves the plan on the engine's page. In a
repository with a deploy block, `pubrules sync` writes `.github/workflows/service-needs.yml`:
run by hand (Actions, "service-needs", Run workflow) with an `action`, `check` (the
default) or `fulfil`, and a `unit` chosen from the block's units, it calls pubrules'
reusable `service-needs.yml` at this release, which runs `pubrules service-needs` in two
steps:

1. **ask the engine.** It asks GitHub for the run's OIDC token for the engine's address
   (`id-token: write`, the one permission the caller grants; no secret), masks it, and
   asks the engine, `POST /requests {"kind": "check"|"fulfil", "unit": U}`. The engine
   takes a run on the default branch of a repository of an owner it lists, and walks the
   unit read-only for its plan; this step follows the request until that walk ends. When a
   fulfil awaits a person, it writes a box to the job summary, "Approval needed", with the
   link to the request on the engine's page and the plan's needs, and an `Approval needed`
   notice, then ends: the box shows on the run's page while the next step waits.
2. **the needs of U.** It polls `GET /requests/ID` every 15 seconds, with a fresh token
   each time; after a 5xx or no answer it waits 15, 30, 60, then 120 seconds before asking
   again. At the end every need of the unit is shown on a line of its own: a log group
   titled with an icon, the need and its state (holding what the walk found and, for a
   fulfil, what it changes), an error annotation for a need missing, drifted or blocked and
   a warning for one unknown, and a row of the summary's table (icon, need, type, grade,
   state, found).

How the run ends:

| Action | The request ends | The run |
| --- | --- | --- |
| check | done | fails when a need is missing, drifted or blocked, naming them; otherwise succeeds |
| fulfil | done | succeeds, with each need's end state |
| fulfil | declined, expired or failed (a plan that changed since its approval, or one with nothing the engine can fulfil, among them) | fails, with the engine's reason |
| fulfil | still awaiting, or still running, when `timeout-minutes` (300) is up | succeeds, saying so: the engine runs it once approved |

A check asks no one and changes nothing. Nothing the run prints holds an email or other
value: the engine names no approver to a caller, the needs come by name, state and what
was found, and any email-shaped text is taken out. `sync` also lists the caller under
`github.actions-oidc` in integrations.json, removes the `go-live.yml` pubrules 0.43.2
wrote, and `sync --check` fails when the caller differs or is left behind without a deploy
block. pubrules.json's `service-needs` block, all optional, reaches the caller:

```json
"service-needs": {"engine": "https://convergence.sustenaut.eu", "timeout-minutes": 300, "claude-dispatch": false}
```

`engine` is the engine's address (and the token's audience), `timeout-minutes` how long a
run waits, and `claude-dispatch` whether Claude may start the workflow too. The engine does
not enforce `claude-dispatch` yet: a run's OIDC token names who started it (`actor`), and a
dispatch by Claude through a person's token reads as that person, so telling them apart
needs its own mark first. ci.runs-on's default label is the job's runner. The scheduled
`deploy-check.yml` (pubdeploy's) stays until a check from here serves in its place.

## Terraform from CI

`terraform.yml`, the reusable workflow that applies a stack from the default
branch, is [pubhost](https://github.com/Sustenaut/pubhost)'s
(`Sustenaut/pubhost/.github/workflows/terraform.yml@<commit> # vX.Y.Z`).

## Caching a build

A build that downloads slow-changing data, or makes many outputs one by
one, can keep both between runs by entries the repository states in
pubrules.json. The cache block is one map of named entries, each with the
same keys:

```json
"cache": {
  "data": { "path": "data", "refresh": "week" },
  "packs": { "path": ".packcache", "unit": "data/areas/{unit}/",
             "inputs": ["data/boundaries.geojsonl", "mapbuild/*.py"],
             "tools": ["tippecanoe --version"] },
  "overview": { "path": ".packcache/overview",
                "inputs": ["data/national/", "data/boundaries.geojsonl", "mapbuild/*.py"],
                "tools": ["tippecanoe --version"] }
}
```

| Key | What |
|---|---|
| `path` | the file or directory kept between runs |
| `refresh` | `run`, `day`, `week` (ISO week), `month` or `never` |
| `version` | a free string; changing it fetches anew |
| `inputs` | files, directories or globs the key depends on |
| `tools` | commands whose output counts, such as `tippecanoe --version` |
| `unit` | one pattern with `{unit}`, filled from `--unit`, so each unit gets its own fingerprint |

An entry needs `refresh` or `inputs` (or both). An unknown key fails
`pubrules sync`, naming it. Each entry gets its own cache key, and a block
holds at most eight entries.

- A **fetched** entry (`refresh` other than `run`, and no `inputs` or
  `unit`) is kept for its period: the first run of a period fetches it,
  and later runs restore it. A fresh run restores none.
- A **made** entry (`inputs`, `unit` or `refresh: run`) is restored from
  the latest run. The build makes it through

  ```sh
  pubrules cache run packs --unit north/alpha --output pack.pmtiles -- bin/build-pack ...
  ```

  which fingerprints the unit (the entry's name, the unit, the `unit`
  pattern filled in, each `inputs` entry, each `tools` command's output,
  and the version), copies the outputs when that fingerprint was made
  before, and otherwise runs the command and keeps what it wrote. It
  prints `reused packs north/alpha` or `built packs north/alpha`; the
  command's own output goes to stderr.

In a workflow, `actions/cache` restores before the build and saves after
it. Saving first drops what no run used, so a made entry keeps one
build's worth (`pubrules cache prune` does the same by hand). With
`refresh: true` (`pubrules cache plan --refresh`) the restore step restores
nothing, so the build fetches and makes everything anew; `actions/pr-label`
sets it from a `refresh cache` label on the pull request.

```yaml
- uses: Sustenaut/pubrules/actions/cache@vX.Y.Z
  with: { step: restore, fresh: "${{ inputs.fresh || false }}" }
- run: bin/build
- uses: Sustenaut/pubrules/actions/cache@vX.Y.Z
  with: { step: save }
```

## Checking a public site

`pubhost site check` and its WEB- rules are
[pubhost](https://github.com/Sustenaut/pubhost)'s, and its `deploy-static` runs
it before every deploy. Their exceptions are declared in `pubrules.json`'s
`exceptions`, beside the Rust standard's, which `pubrules conform` reads alone.

## The supply-chain report

`pubrules supply-chain CRATE...` writes each crate's `SUPPLY-CHAIN.md` beside
its manifest, from the repository's `cargo vet` files (`supply-chain/`).
The report lists every crate it builds, for any target, and marks build
scripts and procedural macros. It says how each is vouched for: an imported
audit, a trusted publisher, or an exemption with its evidence. `pubrules.mk`
runs it as `make supply-chain`, and `make supply-chain-check` fails when a
committed report is stale. Set `SUPPLY_CHAIN_CRATES` in the Makefile to the
crates that are published.

## The checks the standard requires

Every `[checked]` rule in the Rust crate standard has a stable ID and names
what checks it: `[checked: RS-DOC-04, make doc-coverage-check, library]`.
`make standard` generates `standard.json` from those tags, and it ships in
pubrules. `pubrules required` reads it, and the repository's crates, and prints
the make targets each `rust-ci.yml` job must run:

```sh
$ pubrules required
gates=fmt-check lint doc doc-coverage-check publish-check
functional=functional vectors-check supply-chain-check
msrv=msrv
fuzz=fuzz-smoke
audit=deny vet
cross_job=true
...
```

A command-line tool, with no library target, is not held to the library
rules (`doc-coverage-check`). `pubrules.mk` provides every target the
standard names. A repository sets the variables they read in its Makefile:

| Variable | Default | Read by |
|---|---|---|
| `PUBLISHED_CRATES` | `SUPPLY_CHAIN_CRATES` | `doc-coverage`, `publish-check`, `msrv` |
| `VECTORS_GENERATE` | `./tools/vectors/generate.py` | `vectors`, `vectors-check` |
| `VECTORS_DIRS` | `testdata` and `crates/*/testdata`, where present | `vectors-check` |
| `FUZZ_TARGETS` | every `fuzz/fuzz_targets/*.rs` | `fuzz-smoke` |
| `MSRV` | the first `rust-version` in `Cargo.toml` | `msrv` |

`pubrules doc-coverage [--check] [CRATE...]` writes each published library's
`TESTING.md`: every public item, the examples its docs run, and the tests
whose `// covers:` comment names it. With `--check`, it fails on a public
function with no example, a `// covers:` naming no public item, or a stale
`TESTING.md`. It lives here so every repository runs
the same version.

## Conformance, and declared exceptions

`pubrules conform` checks what no make target can, and `pubrules sync --check`
runs it in every Rust repository:

| Rule | Checked |
|---|---|
| RS-DOC-01 | each published library declares `pub mod _documentation` |
| RS-DOC-03 | each published library sets `missing_docs` in its lints |
| RS-SAFE-01 | each published crate sets `unsafe_code = "forbid"` |
| RS-TEST-01 | `testdata/` (or `crates/*/testdata/`) exists |
| RS-FUZZ-01 | `fuzz/fuzz_targets/*.rs` exists |
| RS-SUP-01 | `deny.toml` keeps the shared baseline, and `supply-chain/config.toml` imports the shared audit sets |
| RS-SUP-04 | `SECURITY.md` exists |
| RS-SUP-05 | the release key `release.json` names is labelled for what it releases ("example-crate release key"), not with a person's name: its label is public in every release it signs |
| RS-REL-01 | `release.json` declares `pubrules audit --check` as a security check |

It also checks that every workflow calling `rust-ci.yml` pins the pubrules
version the lock pins, so a repository's CI cannot fall behind the standard
its lock names. The published crates are those that do not set
`publish = false`, or the list `"published"` in `pubrules.json` gives.

A repository that cannot meet a rule yet declares an exception in
`pubrules.json`:

```json
{ "kind": "rust",
  "exceptions": [
    { "rule": "RS-TEST-01", "reason": "no independent source for the version arithmetic yet", "until": "2027-01-01" } ] }
```

An excepted rule's conformance checks are skipped, its make targets leave
`pubrules required`'s plan, and `pubrules conform` lists it as open. An
exception past its `until` date, or naming no rule, fails.

## Every test is a Gherkin scenario

`pubrules sync --check` holds every repository but a content one to the
rule this README opens with, and `pubrules gherkin` runs that check alone:

| Rule | Checked |
|---|---|
| TEST-01 | there is a `.feature` file with a scenario, and no feature file without one |
| TEST-02 | no test runs outside a scenario: a test module's `test*` functions are pytest-bdd bindings (`scenarios(...)`, or an empty function decorated with `@scenario`); there is no `Test*` class, no `unittest.TestCase`, no Node test file (`*.test.js`, `*.spec.ts`, or a script in a `test/` directory that loads a test runner such as `node:test` or `vitest`) and no test shell script (`test-*.sh`, `*-test.sh`, `*.test.sh`) |
| TEST-03 | every feature file runs: a `scenarios()` or `@scenario` call names it or its directory, resolved as pytest-bdd resolves it (`bdd_features_base_dir` in the nearest `pytest.ini`, or the module's own directory), unless the repository runs a Node Gherkin runner (`@cucumber/cucumber`, `quickpickle` or `@amiceli/vitest-cucumber` in its own or a package's package.json, or a `cucumber.*` config), which runs every feature it is given |
| TEST-04 | every scenario has a `When` among its own steps, the one action it tests (an `And` or `But` takes the keyword before it); a `When` in a `Background`, or in a docstring, does not count |

A scenario sets something up (`Given`), takes one action (`When`) and checks
what came of it (`Then`), on the steps of pubtest's GRAMMAR.md: a suite
writes its own Givens and its own When, through `attempt`, and takes every
check from pubtest. A scenario of one `Then` that tests a function in one go
was the first step onto Gherkin, and TEST-04 retires it. TEST-04 came after
the repositories had suites, so the move from a pubrules before the release
that brings it (0.43.3), or from any pubkit (its name before 0.43.0),
(`pubrules bump`, or the nightly's pins) writes its exception, until 2026-12-31, into a
repository that fails it, with the count of scenarios that have no When;
one that passes gets none, and no later move adds one.

Fixtures, steps, fakes and setup files are not tests: a Node file that loads a Gherkin runner holds steps or their
support, even beside node:test's `mock`. A Rust crate's `#[test]`s and doc tests are the Rust crate
standard's (RS-DOC-02, RS-TEST-02), and stay. `pubrules init` seeds
`tests/features/repository.feature` and its steps, so a new repository
starts in step.

A repository that cannot meet a rule yet declares an exception, read as
the Rust crate standard's are:

```json
{ "exceptions": [
    { "rule": "TEST-02", "reason": "the worker's node:test tests move to cucumber-js", "until": "2027-01-31" } ] }
```

`sync --check` lists each open exception, and fails on one past its date.

## A release cites a current audit

The judged rules need a reader, so a release needs a report by the
rust-crate-quality agent (RS-REL-01). For a release, the agent writes it to
`audit/<package>-<version>.md`, with a header:

```
---
package: example-crate
version: 0.1.1
standard: <pubrules audit --standard>
blocking: 0
date: 2026-10-13
auditor: rust-crate-quality
---
```

`pubrules audit --check [PACKAGE VERSION]` passes only on a report for that
release, made against the standard this pubrules ships, with no finding that
blocks a release and no rule left unjudged. Without arguments it reads the release `pubrel prepare` is
cutting from `PUBREL_PACKAGE` and `PUBREL_VERSION`. A repository declares it
in `release.json`:

```json
{ "name": "quality audit current", "run": ".venv/bin/pubrules audit --check",
  "version": ".venv/bin/pubrules --version" }
```

`pubrel prepare` runs every declared check before it changes anything, so it
cuts no release without a current audit. It records each check's last line
in the release's signed security record, so the release cites its report.
Changing the standard makes earlier reports stale: a release after that
needs a new audit.

### Preparing the report

```sh
./pubrules audit prepare --package example-crate        # audit/example-crate-<next>.md
with-secrets ./pubrules audit draft --package example-crate   # optional: Claude drafts the judged rules
```

`pubrules audit prepare --package NAME` writes the report for the release
`pubrel next --package NAME` gives (or `--version`). It decides every rule a
machine can decide, and leaves the rest for a person:

- **The header**, as above, adds `commit` (the commit audited) and
  `last-release` (the package's last release tag).
- **Each finding** goes under its severity, with its rule, file and line.
  Builds and lints:
  - `cargo doc` and `cargo clippy` warnings for the package, and its
    doctests;
  - a library's docs built from the packaged crate on nightly, as docs.rs
    builds them;
  - `cargo publish --dry-run`, and the build on the package's
    `rust-version`;
  - the make targets the standard names: `doc-coverage-check`,
    `supply-chain-check`, `vectors-check`, `deny` and `vet`.

  The docs and the manifest:
  - public functions with no example, or returning a `Result` with no
    `# Errors`;
  - examples that unwrap, or use `?` without the hidden `Ok`;
  - public error enums that are not `#[non_exhaustive]`;
  - crate-root sections that are missing or out of order, and
    features, MSRV and versioning against `Cargo.toml` and `release.json`;
  - each "Related crates" row's version against `Cargo.lock`;
  - the README's sections, the `Cargo.toml` metadata, and unanchored
    `include` patterns;
  - each tool `SECURITY.md` names, against the workflows that run it and
    when, and its imported audit sets against `supply-chain/config.toml`;
  - for a command-line tool, `--help` run: does it exit 0 to stdout?
- **Each rule that needs judgement** is under "Needs review", marked
  `[needs review]`, with what the machine found for it. Examples: the
  hidden setup lines, the functions that can panic, `usize` in
  signatures, the Related crates rows, the test vectors' sources, the
  entry points beside the fuzz targets, and the sentences section 10
  rules out.

The judged rules have no IDs in the standard. `standard.json` keys them by
section and place (`1.6` is Related crates), which holds while the
standard's text does, and a report names that text's sha256. `--check`
fails while any `[needs review]` mark remains. A person judges each rule,
moves what they find into the sections above, counts `blocking` again, and
removes the mark. `--quick` skips what takes minutes (the docs.rs, MSRV and
publish builds, and the make targets). An existing report is written over
only with `--force`, since it may hold a review.

`pubrules audit draft --package NAME` asks Claude to draft those rules. It
sends the Messages API:

- the package's diff since its last release tag, without lockfiles and
  generated files;
- the rules still marked, each with what the machine found;
- the last release's report, when there is one.

It asks for JSON matching a schema: per rule a verdict, findings with file
and line, and the reasoning. It merges each draft into the report, marked
`[machine-drafted by MODEL: needs human review]`, and adds the drafted
findings that block to `blocking`. `--check` refuses that mark too, so a
person still reads every draft. The key is `ANTHROPIC_API_KEY`: run it
through a `with-secrets` whose Bitwarden project holds a secret of that
name, or export it. The model is `--model`, `PUBRULES_AUDIT_MODEL`, or
`claude-opus-5-5`. `ANTHROPIC_BASE_URL` points it elsewhere, as the tests
do. A refusal, an error or an answer cut short writes nothing.

## The Rust crate standard, and an agent that audits against it

[**The Rust crate standard**](plugins/rust-crate-quality/rust-crate-standard.md)
is what a crate published from these repositories is held to, whether a
library or a command-line tool. It covers:
- crate and item docs in the style of BurntSushi's crates;
- test vectors and `// covers:` links;
- fuzzing and packaging;
- Cargo's version convention, with API checks;
- the supply-chain record;
- cross-platform CI;
- plain writing.

Each rule is marked *checked* (a tool enforces it) or *judged* (it needs
reading). The standard ends with what was deliberately not adopted.

The **`rust-crate-quality` agent** audits a crate against that standard, and
writes or fixes its docs to meet it. pubrules' repository is a Claude Code
plugin marketplace, so the agent installs once for every repository, and
none of them needs a `.claude/` folder. In Claude Code:

```
/plugin marketplace add Sustenaut/pubrules
/plugin install rust-crate-quality@pubrules
```

Then ask for it by name, in any repository:

- "Use rust-crate-quality to audit example-crate." It returns a report and
  edits nothing.
- "Use rust-crate-quality to fix the docs of pubrel." It edits
  documentation, then re-runs the checks.

Claude Code also offers it unprompted when you ask whether a crate is ready
to publish.

What it does:

1. Reads the standard. It ships with the agent, so the agent never works
   from memory.
2. Runs the checks the repository has (`make doc`, `lint`, `msrv`,
   `publish-check`, `doc-coverage-check` and the like) and reports what they
   say. It doesn't judge those rules again.
3. Builds the docs as docs.rs will: from the packaged crate, on nightly,
   with no warnings.
4. Reads the docs and code for the judged rules. It verifies claims, such
   as each "Related crates" row, rather than trusting them.
5. Reports each finding with its rule, file and line, from what blocks a
   release down to what is worth considering.

**What it changes:** documentation only. That means doc comments, the
README and `SECURITY.md`. Anything that needs a code change, such as
`#[non_exhaustive]` or a `u64` for a peer-supplied size, comes back as a
finding for you to decide.

**What it never does:** edit generated files, which it regenerates instead,
or record the change. Commit its edits as usual, with `pubrel add internal
"..."`.

`/plugin marketplace update pubrules` picks up a newer standard.

## Starting a package

    pubrules new --name=pubfoo --tag=PKG-PUBFOO-10-2026 [--description=TEXT]

In an empty repository, writes a crate that passes every check from its
first commit: the managed and seeded files, docs, test vectors, a fuzz
target, Gherkin scenarios, `deny.toml`, `supply-chain/`, `SECURITY.md`,
`release.json` with its security checks (the quality audit among them), and
a release key labelled "pubfoo release key", its secret in the gitignored
`corpus/.publet`. It pins pubrel (`ci.release.pubrel`) and pubtest
(`tests/requirements.txt`) at the releases the release state lists, or
else at their latest GitHub releases ("Other packages' releases", above).
Its repository is `--owner`'s, by default the owner the
`origin` remote names; without either it stops. It refuses a `pubrel` older
than 0.5.3 or a `pub` older than 0.2.1, and prints the steps it does not take
itself: the protect block to add to `pubrules.json`, and switching the repository
on in the release app.

## Backing up signing keys

A repository names every signing key it uses, and where it is backed up, in
`pubrules.json`:

```json
"signing_keys": [
  {"path": "corpus/.publet/signing.key",
   "bitwarden": {"project": {"id": "PROJECT-UUID", "name": "Pub"},
                 "name": "pub-signing-key-example"}}
]
```

The project is found by its `id`; `name` is a label for people, and a run
warns when Bitwarden's name for the project has changed. A plain string is
taken as an id when it is a UUID, else as a name, in any case.

`path` is from the repository's root, or from the home directory when it
starts with `~/`: a key kept outside any repository, such as one under
`~/.config`, is declared by the repository whose tools use it. `pubrules sync
--check` refuses a block it can't use.

Backing them up is pubsec's: `./pubsec signing-key backup [--under DIR]
[--dry-run]` writes each declared key on this machine that its project lacks,
from memory, never overwriting one (pubsec's README, "Backing up signing
keys"). `pubrules signing-key backup` says so, and is removed in the next minor.

## Protecting main and the release tags

Every repository's default branch carries the same ruleset,
[`src/pubrules/ruleset.json`](src/pubrules/ruleset.json), which ships in the
wheel: it cannot be deleted or force-pushed, it changes only by pull
request (no approval needed), merged by GitHub's merge queue, and nobody
may bypass it. "Merge when ready" puts a pull request in the queue, which
merges it into main as it stands then, together with the pull requests
ahead of it, runs the required checks on that merge (the `merge_group`
event, which the CI `pubrules sync` writes runs on), and merges only when
they pass. So the tree the checks passed is the tree main holds after the
merge, the run on main repeats the queue's, and tagging a release needs no
tests of its own, yet nobody has to bring a branch up to date by hand:
pull requests stacked behind one another merge one at a time. GitHub
offers a merge queue only to an organization's public repositories (and to
private ones on Enterprise Cloud); a repository without one, `"queue":
false` in its entry or `--no-queue`, instead merges only after the checks
pass on a branch that is up to date with main. `pubrules protect` works this
out itself: it reads each repository's owner and visibility (and a private
one's organization plan) and leaves the queue out, with a note, for a
personal account's repository or a private one off Enterprise Cloud, and
should GitHub still refuse the `merge_queue` rule, it warns and tries once
more without it. The generated `pr.yml`'s `merge_group` trigger then never
fires, and does no harm. Which repositories carry it, and the checks each
requires, is local configuration, not part of pubrules:

    pubrules protect [--check] [--no-tags] [--no-queue] [--repos FILE | --require CHECK...] [REPO...]

creates the ruleset in each repository, or updates the ruleset already on
the default branch to match, renaming it. It does the same for the release
tags' ruleset, [`src/pubrules/tag-ruleset.json`](src/pubrules/tag-ruleset.json):
nobody may create, move or delete a `v*` tag, and only GitHub Actions may
bypass it. GitHub refuses the GitHub Actions app as a bypass actor in an
organization's repository, so such a repository names its release GitHub App
with `"release_app": ID` in its entry, and its tags let that app through
instead (without it, a repository of the one owner pubrules still knows gets that
owner's app, with a warning): installed on the organization, with contents
write only, and its id and private key as the organization secrets
`RELEASE_APP_ID` and `RELEASE_APP_KEY`, which the CI `pubrules sync` writes
passes to pubrel's release workflow (pubrel 0.6.1 and later), where `pubrel
tag` uses the app's token. So the one way to release is the signed one:
`pubrel prepare` on your machine, then merging the release pull request,
after which CI runs `pubrel tag` on main. Put the tag ruleset on a
repository only once its CI passes the two secrets, or `pubrel tag` is
refused there. A tag pushed by hand is refused. A repository
that releases no tags, such as a site, goes without the tag ruleset:
`"tags": false` in its entry, or `--no-tags`. It calls the GitHub API through
`gh`, signed in as the repositories' owner, since only an admin may change
a ruleset. `--check` changes nothing: it prints how each repository
differs, a setting GitHub adds with its own default aside, and fails when
one does. When GitHub rejects a ruleset, it prints GitHub's reasons.

The repositories come from one of:

- a repos file, with `--repos FILE` ([The repos file](#the-repos-file)): the
  repositories it marks to protect, each with the checks its own `pubrules.json`
  says;
- `--require CHECK`, repeated, and the `REPO` arguments, with no file:
  `pubrules protect --require "ci / passed" example-org/newrepo`.
- the repository's own `pubrules.json`, which says how it is protected:
  `"protect": {"checks": ["ci / passed"], "tags": false, "queue": false, "release_app": 12345}`
  (`tags` and `queue` default to true). A `REPO` is read from the `pubrules.json`
  on its default branch, and `pubrules protect` with no list and no `REPO`,
  run inside a repository, reads `./pubrules.json` for the repository
  `origin` points at. The block takes only `checks`, distinct non-empty
  names, `tags`, `queue` and `auto_merge`, true or false, and `release_app`, a positive integer;
  anything else, or a pubrules.json that is not JSON, is refused before GitHub is asked, and `pubrules
  sync --check` refuses it too.

`pubrules sync` also holds `checks` to what the repository's workflows report
where the ruleset waits for them: on the merge queue's commit (`merge_group`),
or, with `"queue": false`, on the pull request's. A required check nothing
reports there is never passed, so the queue waits for it forever, and sync
fails, naming it. A check counts as reported when a job of a workflow that runs
on that event has it as its name (or id), or, for a check `PREFIX / job`, when
such a job named `PREFIX` calls a reusable workflow (whose own job names sync
does not read). `SonarCloud Code Analysis`, which SonarQube Cloud's app posts,
counts only when such a workflow scans on every run: no workflow sync writes
scans in the merge queue, which SonarQube Cloud refuses, so a repository with
a merge queue drops it from `checks`. `ci / sonar`
still fails `ci / passed` on the quality gate, on the pull request.

It also turns on secret scanning and push protection on each public repository, unless
its block says `"secret_scanning": false`. It never turns them off, and leaves a private
repository alone, since they need GitHub Advanced Security there. Reading them needs
Administration read, and a token without it changes nothing and fails nothing.
Each public repository's dependency graph and Dependabot alerts are turned on too:
the review job's dependency review fails without them, and GitHub leaves them off on a
new repository. `protect --check` reports them off.

`auto_merge` is the repository's "Allow auto-merge" setting, which lets a
pull request be set to merge by itself once the ruleset's required checks
pass (`gh pr merge --auto`). It loosens nothing: the ruleset still decides
what may merge, and without the merge queue the branch must still be up to
date with main. `true` turns it on, `false` off, and without it protect
leaves the setting as it is; `--check` reports a setting that differs.

Here, `make protect` (or `make protect-check`, or `make protect
REPOS=example-org/example-site`) runs it, making the venv first if there is none.

### Pull requests: ready, or draft

A pull request opens **ready for review** by default: the required checks
above gate the merge, and `ci / passed` fails when any CI job does,
SonarQube Cloud's quality gate included (below), so draft adds no safety.
It is **draft** only when something else must happen first -- another
pull request merged, a release published, a pin moved, someone's decision
-- and its description says what it waits on. The managed `AGENTS.md`
carries this rule into every repository, where coding agents read it.

### Branches: up to date with main

Before each push, a branch takes in `origin/main`: rebased onto it if it
was never pushed, `origin/main` merged into it if it was pushed or has a
pull request, so no force push moves a reviewer's view. A conflict is
resolved only when the resolution is clear; otherwise the push waits and
says what conflicts. A folder that only follows main fast-forwards. It
runs when the branch gets new code, never on a timer, so a pull request
arrives as up to date as the ruleset requires. The managed `AGENTS.md`
carries this rule too.

## The release board

The board that grades every repository A to E, and the commands a control
plane runs across many repositories (state files, their GitHub variables,
freshness, and the nightly's loop), are
[pubfleet](https://github.com/Sustenaut/pubfleet)'s. It grades protection
against this pubrules' rulesets, as `pubrules protect --check` does.

## The repos file

Which repositories `pubrules protect` acts on can come from outside it, in one file:

```json
{ "repositories": [
    { "repo": "example-org/some-tool", "protect": true, "govern": true, "project": "tools" },
    { "repo": "example-org/some-site", "protect": true, "govern": false }
] }
```

`protect` says it should carry pubrules' rulesets, and `govern` that a nightly
keeps it current; each is false when left out. `project`, optional, labels it on
the board. How a repository is protected stays in its own `pubrules.json`'s
protect block. `pubrules protect [--check] --repos FILE` reads it; pubfleet reads
the same file, and makes it from an owner's state file.

A repository's `pubrules.json` may name the GitHub variables it reads, never their
values, and the workflow that takes them in:

```json
"variables": { "names": ["SOME_SETTING", "SOME_MAP"], "deploy": "deploy.yml" }
```

`pubrules sync --check` refuses a block of the wrong shape. The values are in the
owner's state file, which pubfleet keeps GitHub to.

## The nightly

`pubrules nightly --pubrel V --body FILE`, run in one repository's checkout,
moves it and its dependencies on to this pubrules, in up to five commits on the
current branch, and writes the pull request's body. pubfleet's `nightly.yml`
runs it in each repository a control plane governs, and keeps one pull
request per repository on its `pubrules-nightly` branch. The commits:

1. every outdated pub* pin (`pubrules pins`): the latest pubrules in any of its
   `*-ci.yml` workflows, pubrel's release workflow and `pubrel-version`,
   each tool `ci.tools` pins by tag, to the latest release of
   its git repository, every other repository's reusable workflow or
   action a hand-written workflow pins at a release
   (`OWNER/REPO/.github/workflows/...@`, `OWNER/REPO/actions/...@`) and
   every other repository's Terraform module a `.tf` file sources at a
   release (`source = "github.com/OWNER/REPO//PATH?ref=..."`), to that
   repository's latest release, except a `deploy.providers` package's,
   which its own bump hook moves, and the crates `nightly.pins.crates`
   names in `Cargo.lock`. A pin moves to the commit of the new release's
   tag, with its version in a comment (for a module source, after the
   closing quote: `?ref=<commit>" # vX.Y.Z`), and one still pinned by tag
   moves to its commit. A pin of a pubrules action, workflow or module this
   pubrules does not ship stays where it is, and `sync --check` fails on it
   until it is taken from the repository it moved to;
2. every third-party GitHub Action (`pubrules actions`) a hand-written
   workflow or one of the repository's own composite actions (`action.yml`,
   outside `node_modules` and `target`) pins by commit with its version in
   a comment, as `uses: actions/checkout@<commit> # v5.1.0`, moved forward
   to its repository's latest release, by the commit of its tag. This
   replaces Dependabot's version updates, whose pull requests can add no
   pubrel row and get no SonarQube Cloud token, so they failed `pubrel
   check` and the sonar job. Major releases come too, gated on CI like
   everything else here. A pin by tag, to a branch (`# main`) or of a
   pre-release stays, as does one whose latest release or tag cannot be
   read, with a warning. The workflows `pubrules sync` writes move with
   pubrules;
3. the other crates' updates (`pubrules crates`) that `cargo vet` covers
   with an audit, adding no exemption, and that `cargo deny` passes. The
   body lists each update skipped with what `cargo vet suggest` says it
   needs;
4. the npm packages, each to the newest version its range in
   `package.json` allows (`npm update --package-lock-only
   --ignore-scripts`);
5. `tests/requirements.lock`, re-resolved from `requirements.txt` (`pubrules
   lock`).

Each commit regenerates `SUPPLY-CHAIN.md` where there is one and records an
`internal` pubrel row for each package it changes. An open pull request is
updated, never a second one opened, by pubfleet's loop.

### Update and security settings

A repository chooses what its nightly does in `pubrules.json`, per language
(`rust`, `node`, `python`; each applies where the repository has that
ecosystem's lock), and for the third-party GitHub Actions (`actions`):

```json
{
  "kind": "utility",
  "update": { "rust": true, "node": true, "python": false },
  "nightly": { "pins": { "crates": ["some-crate"] } },
  "security": {
    "fuzz": { "rust": true },
    "dependabot": { "schedule": "weekly", "ecosystems": ["github-actions"] },
    "sonar": { "args": "-Dsonar.exclusions=vendor/**" }
  }
}
```

| Setting | Default | Off means |
|---|---|---|
| `update.<language>` | `true` | the nightly pull request leaves that language's dependencies alone; `"update": false` turns every language off, and the actions, leaving the pub* pins alone |
| `update.actions` | `true` | the nightly leaves the third-party GitHub Actions alone, and the managed `dependabot.yml` keeps Dependabot's version updates of them |
| `nightly.pins.crates` | three crates, with a warning | the crates the nightly moves with the pins, whatever `cargo vet` says, rather than one at a time; `[]` is none. `pubrules sync --check` refuses any other key in `nightly` or `nightly.pins` |
| `security.fuzz.<language>` | `true` | a scheduled run fuzzes as briefly as any other: `rust-ci.yml` runs cargo-fuzz for `fuzz-seconds` instead of `fuzz-seconds-scheduled`, and `python-ci.yml` and `node-ci.yml` give each property test `fuzz-runs` inputs instead of `fuzz-runs-scheduled` (see [Property tests](#property-tests)) |
| `security.dependabot` | weekly, `github-actions` | `pubrules sync` writes `.github/dependabot.yml` from `schedule` (`daily`, `weekly` or `monthly`), `ecosystems` (names, at the root, or Dependabot's own `{"package-ecosystem", "directory"}`) and `options` (any other Dependabot setting, on every entry). `false` leaves the file to the repository. The languages are the nightly's to update, so the default leaves them out. Every `github-actions` entry ignores the owner's `pubrules/*` and `pubrel/*` workflows and actions, whose pins move with `pubrules bump` alone; ignores in `options` are kept. While the nightly moves the actions (`update.actions`), every `github-actions` entry also sets `open-pull-requests-limit` to 0: Dependabot opens no version updates of them, and its security updates still come |
| `security.sonar` | none | `args` adds SonarQube Cloud properties to every sonar job's scan, after the `sonar-args` input; `organization` is the SonarQube Cloud organization key, by default the GitHub owner in lower case |

A setting pubrules does not know stops the nightly with a message, rather
than being ignored.

Advisory checks have no setting. Every run of `rust-ci.yml`, `node-ci.yml`
and `python-ci.yml`, the nightly included, checks the advisories and fails
on a finding: OSV-Scanner reads every lockfile in the repository against
the OSV database (RustSec, GitHub, PyPI and npm advisories), and each
language adds its own check: cargo deny, `npm audit` of `package-lock.json`,
or pip-audit of the hash-locked requirements. On a public repository's
pull request, GitHub's dependency review also fails a change that brings
in a vulnerable version. Its license check leaves out the owner's own
reusable workflows and actions, for which GitHub reads no license: `pubrules
sync` lists those the repository's workflows call in
`.github/dependency-review-licenses.txt`, and the review takes only the
owner's from it. The pub* pins also always come,
so a governed repository keeps up with the standard. A repository's own CI
runs on a schedule when its `ci.yml` has a `schedule:` trigger; the
settings say what that run does.

### Property tests

Python and Node fuzz with property tests: a test states what holds for
every input, and the library generates inputs to break it, shrinking any
failure to a small example. Python's is [Hypothesis](https://hypothesis.readthedocs.io),
which `tests/requirements-pubrules.txt` pins for every package; Node's is
[fast-check](https://fast-check.dev), which a package adds to its own
`devDependencies`.

Each property tries `PUBRULES_FUZZ_RUNS` inputs, which `python-ci.yml` and
`node-ci.yml` set: `fuzz-runs` (100) on every push and pull request, and
`fuzz-runs-scheduled` (10000) on a scheduled run unless
`security.fuzz.<language>` is `false`. pubrules' pytest plugin reads it for
Hypothesis, with no deadline. fast-check reads no variable of its own, so a
setup file the test command loads (`node --test --import ./tests/setup.mjs`,
or Vitest's `setupFiles`) does:

```js
import fc from "fast-check";
fc.configureGlobal({ numRuns: Number(process.env.PUBRULES_FUZZ_RUNS) || 100 });
```

A failing property prints the input that broke it; Hypothesis also prints a
`@reproduce_failure` blob that replays it exactly.

## Locking

`pubrules lock` resolves with pip's own resolver (`pip install --dry-run
--report`) and needs nothing else. The lock pins the pubrules wheel by URL and
sha256: a release carries the wheel as an asset, and `pip install
--require-hashes` verifies it.

### A wheel mirror, for when GitHub's release downloads fail

A wheel pinned by a GitHub release URL fails to install whenever GitHub's
release downloads do, and pip retries no 504. `tests/install-lock`, which
every managed install of a lock goes through (pubrules.mk's `venv`, the
reusable workflows' `sync --check` steps), tries the install three times,
15 s apart. With a wheel mirror in pubrules.json, a fourth try takes each
wheel the lock pins by a GitHub release URL from the mirror instead:

```json
"mirror": {"wheels": "https://storage.sustenaut.eu/wheels"}
```

The mirror serves each file at `<base>/f/<sha256>/<file>.whl`, so a lock
line alone gives its address, and the hashes stay as they are: pip checks
every file, and the mirror only has to be there, never trusted.
pip-audit's last try reads the locks rewritten the same way
(`tests/install-lock --rewrite LOCK`), and `./pubrules` fetches its own wheel
(by the sha256 tests/requirements.lock pins for `pubrules==X`) and
deploy.providers' wheels from the mirror when GitHub fails to give them.
Without the setting, the installs only retry, and `./pubrules` takes
`pubrules==X` from PyPI.

With a PyPI mirror too, the fourth try takes every other package from its
simple repository index (PEP 503) instead of PyPI, again checked against
the lock's hashes:

```json
"mirror": {"wheels": "https://storage.sustenaut.eu/wheels", "pypi": "https://storage.sustenaut.eu/pypi"}
```

Filling the mirror is the mirror's own job. For storage.sustenaut.eu, an
hourly workflow in Sustenaut/storage copies every wheel attached to a
release of Sustenaut's public repositories, and the PyPI files and
Terraform providers the repositories' locks pin.

## CI

```yaml
jobs:
  ci:
    uses: Sustenaut/pubrules/.github/workflows/rust-ci.yml@<commit> # v0.1.0   (or python-ci.yml, node-ci.yml)
    secrets: { SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}' }          # by name, not inherit
  release:
    needs: ci
    uses: Sustenaut/pubrel/.github/workflows/release.yml@<commit> # v0.1.0
    with: { pubrel-version: v0.1.0 }
    permissions: { contents: write }
```

Pin each one to the full commit its release's tag names, with the version in a comment, as above, rather than to the tag (`@v0.1.0`), which can be moved: SonarQube Cloud flags a tag pin (S7637). `pubrules bump` and the nightly write pubrules' pins this way, and every reader still takes a pin by tag.

- **`rust-ci.yml`:** runs every check the standard requires. A `plan` job builds the hash-locked venv, runs `make sync-check`, and asks `pubrules required` which make targets each job runs. Then:
  - `gates` runs the required gate targets, then any the `gates` input adds;
  - `test` runs `cargo test` on Linux, macOS and Windows (`test-args` adds arguments);
  - `functional` runs the required functional targets, then any the `functional` input adds, optionally with extra apt packages and a released `pub`;
  - `msrv` runs `make msrv MSRV=<the lowest rust-version stated>` on that toolchain;
  - `fuzz` runs `make fuzz-smoke` on nightly: the inputs that once found a bug, then each target for `fuzz-seconds` (5 s, so the merge queue waits about a minute, as for the other jobs), and for `fuzz-seconds-scheduled` (900 s) on a schedule unless `pubrules.json` sets `"security": { "fuzz": { "rust": false } }`;
  - `cross` runs `cargo test` under qemu on `cross-targets`: i686 and s390x by default, or aarch64 `-unknown-linux-gnu`, with `cross-test-args`;
  - `audit` runs `make deny` and `make vet`, with `cargo-deny-version` and `cargo-vet-version`;
  - when the caller also runs on a `schedule`, those runs test on the latest stable and beta Rust (`scheduled-toolchains`).

  On a pull request that touches no Rust code (`*.rs`), Cargo files (`Cargo.toml`, `Cargo.lock`, the toolchain pin), `fuzz/` or workflow files (`.github/workflows/`), the plan skips `fuzz` and `cross`, the slow emulated jobs: a documentation or `pubrules.json` change does not wait for them. A release pull request (a `release/` branch), a push to main and the nightly run everything. `pubrules required --event E --head-ref B --changed-files F` decides, and says why on stderr.

  The `gates` and `functional` inputs can only add targets. The `msrv` and `fuzz` inputs are ignored: those jobs run because the standard requires them. Every job reports through `passed`, the one check a ruleset needs. The `sonar` job of `node-ci.yml`, `python-ci.yml`, `rust-ci.yml` and `service-ci.yml` waits for SonarQube Cloud's quality gate (`sonar.qualitygate.wait`, for at most 300 seconds), so a failing gate fails the job and `passed` with it, rather than showing only on the SonarCloud app's own check. The one in `job-sonar.yml`, which a `ci` block generates, gets the same result in two steps, so it can tell a failed gate from SonarQube Cloud being down: the scan only uploads, and a `gate` step asks SonarQube Cloud for the result. A gate that is ERROR or NONE, or any refusal (401, 403, 404), fails the job, whatever the pull request carries. When SonarQube Cloud gives no answer (it cannot be reached, answers 5xx, or has not finished the analysis in five minutes, each tried three times), the job fails too, unless the pull request carries the label `sonar-down`: then it passes with a warning and a note in the job's summary that the commit was not analysed. The label is read from GitHub's API when the outage is met (the pull request's own, or for a push to main the pull request merged into it; the sonar job has `pull-requests: read`), never from the event, because "Re-run failed jobs" replays the event as it was: a label added during the outage, followed by a re-run, lets the job through, main's run and the release after it included. A label that cannot be read counts as none. The scan's `.scannerwork` folder is removed before it, and the gate step follows the scanner's report only when it names https://sonarcloud.io, so a report a pull request committed cannot send SONAR_TOKEN elsewhere. The label is read only on an outage, so it cannot hide a finding; the next normal run on main analyses the code. Without a `SONAR_TOKEN` it still passes with a notice.
- **`python-ci.yml`:** takes its commands as inputs (`setup`, `test`, `browser-test`), so a repository with its own entry point keeps it. A non-empty `browser-test` adds a job that installs Playwright's Chromium. The coverage it writes to `browser-coverage-report` (by default `coverage/`) reaches SonarQube Cloud with the functional job's, and the sonar job waits for it. The `audit` job checks `audit-requirements` (by default `tests/requirements.lock`) with pip-audit on every run.
- **`node-ci.yml`:** for a Node package. It installs from `package-lock.json` with `npm ci --ignore-scripts`, so no dependency runs code by being installed, checks pubrules' managed files from `tests/requirements.lock`, and runs `npm test`. The `audit` job runs `npm audit --package-lock-only` on every run and fails on any advisory, development dependencies included. A non-empty `browser-test` adds a job that installs Playwright's Chromium with `npx --no-install`, which runs only what the lock installed. The coverage it writes to `browser-coverage-report` (by default `coverage/`, LCOV) reaches SonarQube Cloud with the test job's, and the sonar job waits for it. The commands are inputs (`setup`, `test`, `browser-test`, `browser-setup`). A repository with a `ci` block in pubrules.json gets the same jobs generated instead (below).

### Generated CI: only the jobs a repository runs

A shared reusable workflow has to skip the jobs a repository doesn't use, and GitHub lists each one as skipped. A repository of any kind avoids that with a `ci` block in `pubrules.json`. `pubrules sync` then writes one workflow per event, and each workflow calls only the jobs that event runs. Each job is its own reusable workflow (`job-node-test.yml`, `job-rust-gates.yml`, `job-sonar.yml` and so on) at this pubrules' release, so the Actions pins still live in pubrules. `pubrules init` writes `"ci": {}`, and `pubrules new` `"ci": {"release": {"pubrel": "X.Y.Z"}}`, at the release above.

Sync pins each one, and pubrel's release workflow, to the full commit of the release's tag, with the version in a comment, so SonarQube Cloud's S7637 (a reusable workflow pinned to a tag, which can move) needs no exception:

```yaml
    uses: Sustenaut/pubrules/.github/workflows/job-rust-test.yml@0f3574a72707a46bae149d3ed7a4644b4837795a # v0.15.2
```

Usually neither needs the network. pubrules' commit is in its wheel: the release CI writes the tag's commit into the package (`release-commit`) before it builds the wheel. A source checkout of pubrules has none, and pins by tag. pubrel's commit is the one the repository's workflows already pin at that version; failing that, sync reads it once from pubrel's tags with `git ls-remote`, and when it cannot, pins by tag with a warning. Workflows written before, pinned by tag, still read and check as before.

Whose pubrules and pubrel these are is set in one place, `OWNER` in `src/pubrules/refs.py`: `Sustenaut`, since both moved there from `schryer`. Every repository moves to it on its next `pubrules sync`, and the nightly moves its hand-written `*-ci.yml` and pubrel pins with `pubrules pins` (`pubrules bump` too). A repository can name another owner first with `"workflows_owner": "sustenaut"` in pubrules.json; it also names the repository `git ls-remote` reads pubrel's tags from. `conform`, the nightly and the audit read a pin under any owner, so one still under the old owner keeps working.

```json
"ci": {
  "events": ["pr", "queue", "main", "nightly"],
  "cron": "17 3 * * *",
  "with": {"browser-test": "npm run test:browser", "coverage-report": "coverage/",
           "sonar-args": "-Dsonar.tests=test"},
  "jobs": {"review": false, "sonar": {"events": ["pr", "main"]}},
  "release": {"pubrel": "0.5.4"},
  "tools": [{"crate": "some-cli", "git": "https://github.com/example-org/some-cli", "tag": "v1.2.3"}]
}
```

- **`events`:** which workflows to write. `pr` writes `pr.yml` (pull requests), `queue` writes `queue.yml` (the merge queue's runs of them, `merge_group`), `main` writes `main.yml` (pushes to main), and `nightly` writes `nightly.yml` (`cron`, or by hand). The default is pr, queue and main, and all four for Rust. The queue runs every job a pull request runs, and the heavy ones besides (Rust's `msrv`, `fuzz` and `cross`), so each push to a pull request gets its answer sooner while nothing merges before the heavy jobs pass. Where the queue would run nothing a pull request does not (Node, Python and service repositories, by default), sync writes no `queue.yml` and `pr.yml` runs on `merge_group` too. A repository without a merge queue (a user's, or a private one) leaves `queue` out, so its pull requests run the heavy jobs themselves.
- **`with`:** the jobs' inputs, the same ones `python-ci.yml`, `node-ci.yml`, `rust-ci.yml` and `service-ci.yml` take. Each input goes to every job that takes it, and one that no job takes stops sync.
- **`jobs`:** narrows the events a job runs on, or drops it with `false` (a private repository drops `review`, since GitHub's dependency graph serves only public ones). By default every job runs on every event, except `review`, which runs on pull requests only, and Rust's `msrv`, `fuzz` and `cross`, which run everywhere but on pull requests. `browser` runs only when `with` gives a `browser-test`.
- **`tools`:** Rust's: what the functional suite drives. Each `crate` is installed from its `git` repository at its `tag` with `cargo install --locked`, and the nightly moves the tag to that repository's latest release.
- **`runs-on`:** the runners, for a repository with self-hosted ones. A label (`"runs-on": "my-runners"`) runs every job there; an object of labels by job name, with `default` for the rest (`{"default": "my-runners", "review": "ubuntu-latest"}`), places them one by one. Sync passes it to each job as its `runs-on` input (every reusable workflow, `python-ci.yml`, `node-ci.yml`, `rust-ci.yml` and `service-ci.yml` too, takes one, `ubuntu-latest` by default) and writes it into `tested`, `passed` and `site`. Rust's `test` runs on its `os-matrix` instead. pubrel's release workflow takes it (`release` places it on its own) from pubrel 0.7.0, which installs Rust on a runner without it. An older pubrel's runs on GitHub's runners. Without it nothing is written, and every job runs on `ubuntu-latest`. The runner must have what `ubuntu-latest` gives these jobs (git, curl, jq, python3 with venv, gh, shellcheck, unzip, a C toolchain, Docker).
- **`language`:** a utility's, `node` or `python`. Without it, a `package.json` with no `pyproject.toml` beside it means Node. A rust, service or content repository's CI is its kind's.
- **`release`:** adds pubrel's release workflow to `pr.yml`, `queue.yml` and `main.yml`, after `passed`. It uses the pubrel `pubrel` names, or where it names none the one the workflows sync wrote already pin, or else pubrel's latest release (below), and `with` adds inputs (Rust's always checks semver, `semver-checks-version: 0.51.0`). `false` leaves it out. A service deploys rather than releases, so it has none, and a content repository, which pubrules neither releases nor deploys, has none either. `{"uses": "local"}` calls the repository's own `.github/workflows/release.yml` in place of pubrel's published one, as pubrel does, so a change to its release workflow is tested before it ships; only `with` goes with it. The nightly moves `release.pubrel` in pubrules.json, writing it there where it named none, then runs `pubrules sync`.

Neither the merge queue nor `main.yml` tests again what an earlier run already tested. A pull request up to date with main merges as the very files its own run tested, and merging moves main to the very commit the queue tested. So `main.yml`, and `pr.yml` where the queue runs it (there is no `queue.yml`), start with `tested` (`job-tested.yml`, `ci / tested`). In the queue and on main, it looks for a successful run of that workflow, on a pull request or in the queue, whose commit has this commit's tree. A run that skipped its own tests names, in a notice, the run it took them from, and that run counts, so long as its artifacts have not expired. When there is one, every job that run ran is skipped (a job only main runs still runs), and `passed` and the release follow. On main, `sonar` still runs, reading the coverage that run uploaded, because SonarQube Cloud measures main from a push to it. The merge queue never scans: SonarQube Cloud analyses pull requests and main, and refuses the queue's `gh-readonly-queue` branch. The pull request's run scanned the change, and main's push scans the merge, so `sonar` does not run on `merge_group` in `pr.yml`, `passed` takes that skip, and a Rust `queue.yml` has no `sonar` at all. So a ruleset with a merge queue must not require SonarQube Cloud's own check, `SonarCloud Code Analysis` (sync refuses it), or the queue waits for that check forever; `ci / sonar` still fails `ci / passed` on a pull request's quality gate. `ci / passed` already takes the skip. When there is none (a pull request's own run, main moved on in between, several pull requests merged together, a repository without the queue, or a commit that reached main some other way) every job runs as it would without `tested`. A Rust crate's `queue.yml` runs jobs its pull requests do not, so its queue tests everything. The nightly always runs everything.

A Rust repository runs the jobs the Rust crate standard asks for here, worked out at sync time from the rules and `pubrules.json`'s exceptions: `gates`, `test`, `functional`, `msrv`, `fuzz`, `cross` and `audit` as required, beside `osv`, `review` and `sonar`, and `toolchains` (the latest stable and beta Rust) on the nightly. Sync writes each job's required make targets into the workflow (`required`), so an exception added or expired shows as a change there, and `make sync-check` in `gates` fails until `pubrules sync` writes it. An empty `cross-targets` (`"[]"`) drops `cross`. `msrv`, `fuzz` and `cross` run in the merge queue rather than on each push to a pull request (unless `events` leaves out `queue`). On a pull request that touches no Rust code, Cargo files, `fuzz/` or workflow files, `fuzz` and `cross` pass at once with a notice (from `pubrules required`, which says `slow=false`) rather than being skipped; release pull requests, pushes and the nightly run them in full.

Uploading a coverage report and restoring or saving a cache only help a run: none of them fails a job. GitHub's artifact and cache services can refuse a run (when the account's Actions billing is blocked they answer with an HTML page, on self-hosted runners too), so every `upload-artifact` of a report and every `actions/cache` step in pubrules' workflows, and every restore and save in `actions/cache`, runs with `continue-on-error`, and the workflow steps stop trying after five minutes. A test that fails still fails its job; a refused upload only leaves the scan without that coverage.

A service runs `checks` (the sync check and shellcheck) and `sonar`, and `terraform` and `tests` when `with` gives a `terraform-dir` and a `test`. Its tests hand `sonar` the coverage they write to `coverage-report` (by default `coverage/`, Cobertura XML or LCOV `lcov.info`). `with`'s `apt-packages` names Ubuntu packages its tests job installs first, through `actions/apt-install`, from the Actions cache when an earlier run installed them (`"apt-packages": "tippecanoe"`); a content repository's tests take it too. A Python package or a service also runs `lint` when `with` gives a `lint` command ("The Python standard" above). A private service drops the scan with `"jobs": {"sonar": false}`. A content repository runs `checks` (shellcheck on `**/*.sh` unless `with` gives `shellcheck`) and, when `with` gives a `test`, `tests`, and has no `sonar`.

A repository that deploys a static site with pubhost's `deploy-static` also gets a `site` job in `pr.yml` (`ci / site`, part of `ci / passed`), so a site that would fail to deploy fails the pull request instead of the deploy after merge. It checks the repository out, builds the site, and runs the `deploy-static` the repository's own deploy workflow pins, as it pins it, with `check-only: 'true'`, which runs its site check and deploys nothing, so it needs no secret. The job comes when any workflow of the repository's own uses `deploy-static`, or pubrules.json has a `site` block, which then needs such a workflow to take the pin from:

```json
"site": {"check_dir": "public", "pr_build": "npm run build:sample", "build": "npm run build",
         "url": "https://example.eu/"}
```

- **`check_dir`:** the directory to check, inside the repository. Without it, the `dir` the deploy workflow gives `deploy-static`.
- **`pr_build`:** the command that builds the site for the check, such as a build from a small sample of its data where the full build is slow. Without it, `build`; without either, the directory is checked as it is in the repository.
- **`url`:** the site's https:// address, so the check finds its og:image files.

Each is one line of text, and sync refuses any other key.

The checks keep the names a ruleset requires: each job is named `ci`, so its checks read `ci / test`, `ci / sonar` and so on. Every workflow ends in `ci / passed`, which passes only when every job succeeded. The generated workflows are managed files, so `pubrules sync --check` fails when one is edited, and also while a hand-written `ci.yml` is still beside them. A repository without a ci block keeps its own `ci.yml`, which can still call `rust-ci.yml`, `python-ci.yml`, `node-ci.yml` or `service-ci.yml`.

### SonarQube Cloud

Public code integrates with SonarQube Cloud, whatever its kind: `rust-ci.yml`, `python-ci.yml`, `node-ci.yml` and `service-ci.yml` each run a `sonar` job, part of `passed`, and so does the CI `pubrules sync` writes for every kind but content, which holds no code. Only a private repository, which SonarQube Cloud does not analyse for free, leaves it out (`"jobs": {"sonar": false}`). Given a `SONAR_TOKEN` secret, passed by name (`secrets: { SONAR_TOKEN: '${{ secrets.SONAR_TOKEN }}' }`, since `secrets: inherit` reaches only a workflow of the caller's own owner and GitHub drops it without a word for pubrules' once the owners differ), it sends the code to SonarQube Cloud as the project `OWNER_REPO` (the owner as GitHub spells it) in the organization whose key is the owner in lower case, or `security.sonar.organization` in pubrules.json, with the full history so it can tell new code from old; `sonar-args` adds properties. Without a token, as in a private repository or a pull request from a fork, it passes with a notice. To turn it on for a public repository:

1. In SonarQube Cloud, analyse the repository as a new project in the organization whose key is its GitHub owner in lower case (or the one `security.sonar.organization` names), keeping the key `OWNER_REPO`.
2. Under the project's Administration, Analysis Method, turn Automatic Analysis off: the two cannot run together.
3. Add the token as the repository's `SONAR_TOKEN` Actions secret.

The default quality gate asks for 80% coverage on new code, and a scan without a coverage report counts it as 0%, so each workflow hands the sonar job one:

| Workflow | Report | Written by |
|---|---|---|
| `rust-ci.yml` | `coverage/lcov.info` | `make coverage`, which the functional job runs in place of `make functional` when there is a token: the Rust tests and the Gherkin suite on a build cargo-llvm-cov instruments (`cargo-llvm-cov-version`) |
| `rust-ci.yml` | `coverage/*.xml` (Cobertura) | any of the `functional` targets, for a repository's Python, such as coverage.py's `coverage xml -o coverage/scripts.xml` (run it after `make coverage`, which empties `coverage/`) |
| `python-ci.yml` | `coverage-report`, by default `coverage/coverage.xml` (Cobertura) | the `test` command, such as coverage.py with `patch = ["subprocess"]`, which also measures the programs the suite starts (pubrules' own `make functional` does this) |
| `node-ci.yml` | `coverage-report`, by default `coverage/lcov.info` | the `test` command, such as `node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info` |
| `service-ci.yml` | `coverage-report`, by default `coverage/`: Cobertura `*.xml` or LCOV `lcov.info` | the `test` command, as for Python or Node |

A test command that writes no report leaves the scan as it was.

In the CI `pubrules sync` writes, the scan also learns which code is tests, so SonarQube Cloud does not warn that files "look like test code" while `sonar.tests` is unset. Sync gives the sonar job a `layout` from the directories the repository has:

| Language | `sonar.sources` | `sonar.tests` |
|---|---|---|
| Python | `src` | `tests` |
| Rust | `src`, `crates` (a workspace) | `tests`, `fuzz`, `benches` |

Each lists only the directories that exist, since the scan fails on one that does not. Without any test directory, and for Node and services, sync gives no layout and SonarQube Cloud keeps its defaults. With tests but no code directory, the code is the whole repository less its tests (`sonar.exclusions`), so no file is read as both. `sonar-args` and `security.sonar.args` come after the layout, and the scanner takes the last value a property is given, so a repository's own `sonar.sources` or `sonar.tests` wins. Set both if you set one, or a file can end up in both.

Every action these workflows use, pubrel's release workflow included, is pinned to a commit, with its version in a comment, and a test fails on one that is not.

## Developing

```sh
make venv     # hash-locked environment, this checkout installed editable
make check    # standard.json current, then the Gherkin suite
```

The suite drives the plugin through pytest's `pytester`. Each scenario
builds a throwaway suite, runs it in a subprocess, and judges what pytest
reports. It drives the command in a scratch repository. pubrules is its own
first consumer: its CI runs through `python-ci.yml` from this checkout, and
it is released with [pubrel](https://github.com/Sustenaut/pubrel). Its
package publet, `pkg.pubrules`, lives in `corpus/`.

## Licence

Apache-2.0: see [`LICENSE`](LICENSE).
