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's: one grammar
(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.
{"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
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:
./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'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. An app has its id,
installation_id and key, and may have its client_id, a variable, which
actions/create-github-app-token takes as client-id in place of the
deprecated app-id: a value that starts Iv. 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:
"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:
[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'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).
Actions
The composite actions pubrules' workflows run are
pubactions': actions/retry
(a bash script tried up to three times), actions/apt-install (apt
packages from the Actions cache), actions/terraform-init (terraform init, tried again, then once from a provider mirror its mirror input
names) and actions/pr-label (whether a run's pull request carries a
label). Each is used from there by commit:
Sustenaut/pubactions/actions/retry@<commit> # vX.Y.Z. pubactions' README
describes their inputs.