diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md new file mode 100644 index 0000000..f2a1145 --- /dev/null +++ b/.gitea/workflows/AGENTS.md @@ -0,0 +1,103 @@ +# Workflow rules + +Every rule for the workflows in `.gitea/workflows/`, in full. Each gives its reason (*Why*) and +how it is held (*Held*): a control names its hook or check; review means a person other than the +author sees the change before it merges (this directory is under `CODEOWNERS`); aspirational +means nothing checks it. "Until X (#N) lands" names a change that is planned and its backlog +issue. + +## Writing a workflow + +- **Never `pull_request_target`.** *Why:* it runs a fork's pull request with the base + repository's secrets and a write token. *Held:* control: the `zizmor` hook. +- **Pass ref, repository and name values to a script through `env:`; never interpolate + `${{ github.* }}` into a `run:` block.** *Why:* a branch name is chosen by whoever pushes it, + and interpolated into a script it becomes shell code. *Held:* control: the `zizmor` hook. +- **Runner labels are `kamino-docker` and `kamino-molecule` only, and expressions use the + `github.*` contexts, which Gitea aliases.** *Why:* the jobs of this repository run only on its + own runners, and actionlint knows no `gitea.*` context. *Held:* control: the `actionlint` hook + with the label list in `.gitea/actionlint.yaml`. +- **A step prints no host sizing, address or network detail.** *Why:* job output is readable + without an account. *Held:* review. + +## Secrets + +- **Each secret is referenced by exactly one workflow:** `image.yml` the registry push + credential, `renovate.yml` the Renovate token, and `release.yml` the release token once that + workflow exists. No other workflow references `secrets.` except the job token + (`secrets.GITHUB_TOKEN`). *Why:* a same-repository pull request gets the organisation's + Actions secrets, so every reference is a way for a branch to reach a credential. *Held:* + review (`CODEOWNERS`). + +## Scripts a workflow runs + +- **Judge scripts:** a script that judges a pull request's own diff runs from `main`'s copy; a + content or artefact check runs from the pull request's copy. `check_bot_pr_diff.py` (Lint) and + `select_molecule_scenarios.py` (Molecule) run from `origin/main`; the pull request that adds + such a script runs its own copy once, with a notice. Exception until #165 removes it: + `check_image_versions.py bump` (Lint) judges the diff but runs from the pull request's copy. + *Why:* a pull request that could edit the rules it is judged by could pass by weakening them, + while a content check must see the content it is given. *Held:* review (`CODEOWNERS`). +- **A pull request from a `renovate/` branch changes only version, tag, digest and pin lines** + (tool pins with their lock entries and hashes, hook `rev:` lines, Dockerfile `FROM` tags and + digests, matrix `version:` lines, `job_image:` pins, consumer image pins). + *Why:* the bot's minor and patch pull requests automerge, so they must not be able to change + anything else. *Held:* control: the Lint check's "Check a bot pull request only moves pins" + step, `scripts/check_bot_pr_diff.py` run from `main`'s copy. The branch name is chosen by the + pusher, so this constrains only the bot's own pull requests. +- **Workflows never mention the image namespace this repository's CI must not use** (the string + is in `scripts/check_image_versions.py`). *Why:* this repository's images are built and pulled + only under its own organisation's namespace. *Held:* control: the Lint check's "Check image + pins" step. + +## Lint and Build + +- **Lint and Build run in the pinned `ci` image and compare the pin files with the checksums + baked into it (`/opt/ci-pins.sha256`).** A pull request that changes `requirements-dev.txt`, + `requirements-dev.lock`, `requirements.yml` or `.pre-commit-config.yaml` takes the slow path, + which installs the pinned tools and collections. *Why:* a pull request is tested on its own + pins, and an unchanged one starts in seconds. *Held:* control: the "Check the baked tooling + against the pins" step. +- **Triggers:** both run on pull requests to `main`, on push to `main` until #166 removes that + trigger, and on manual dispatch; Build also runs on `v*` tags, where it checks the tag against + `galaxy.yml`. *Why:* the tag is what consumers install. *Held:* review. + +## Molecule + +- **Molecule runs on every same-repository pull request, Renovate's included, with no path + filter.** A fork pull request is skipped by the job's `if:`, which is a convenience: a fork + controls its own workflow file. *Why:* a check that always reports can be required, and a new + image is tested by its own pin pull request. *Held:* review. +- **What a pull request runs is chosen by `scripts/select_molecule_scenarios.py`:** the scenarios + of the roles it changes and of the roles that use them (any file naming + `mortis.kamino.`, transitively), none for a diff of only IGNORED paths, a failure for a + changed role with no scenario, and every scenario for any other file. *Why:* a full run takes + the single runner slot for a long time. *Held:* control: the selector and its tests. +- **A role named in an include, import, play `roles:` entry or meta dependency is written out in + full**, never bare or templated. *Why:* the selector finds dependent roles by their FQCN. + *Held:* control: a selector test fails a bare or templated name. +- **A new file outside `roles//` runs every scenario until it is added to IGNORED, and it + belongs there only if no scenario reads it.** *Why:* a file a scenario reads but the selector + ignores would let a breaking change through untested. *Held:* review. +- **Every scenario runs on a manual dispatch and in the nightly run (04:43 UTC, after + Renovate's).** A push to `main` that touches the `push:` `paths:` list runs every scenario + too, until #166 removes that trigger. *Why:* a pull request runs only its selection, so + drift in the other roles shows up here. *Held:* review. +- **A new commit cancels the pull request's running Molecule run, and the run step first removes + the containers a cancelled run left.** Two runs never overlap only because the runner has a + single slot, and the scenarios' container names are fixed; raising the runner's capacity needs + per-run container names first (#166). *Why:* a cancelled run is killed before it can destroy + its instances, and two runs would collide on the same names. *Held:* review. +- **Molecule tests the pull request's pins, as Lint and Build do.** *Why:* the pull request that + raises the ansible-core floor must be behaviour-tested on the new core before it automerges. + *Held:* aspirational until #225 runs Molecule from the `ci` image with the pin comparison + against `/opt/ci-pins.sha256`; today it runs from the runner's own venv. +- **Every scenario sets `scenario.test_sequence` to molecule's default minus the leading + `destroy`;** copy it into a new scenario. *Why:* the workflow clears stale containers first, + and the molecule state lives in the job's own `ANSIBLE_HOME`, so a killed run leaves none + behind. *Held:* review. +- **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that + must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or + `${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in + [images/AGENTS.md](../../images/AGENTS.md). *Why:* the workflow discovers exactly these and pins + both images by digest. *Held:* review. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dad9374..f93a349 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,10 +19,12 @@ vulnerability as [SECURITY.md](SECURITY.md) says, never in an issue. - [setup.md](docs/contributing/setup.md): setting up a clone and an agent tool. - [making-a-change.md](docs/contributing/making-a-change.md): branches, commits, fragments, templates, - third-party material, content from other repositories, dependency and image updates. + third-party material, content from other repositories, testing a Renovate change. - [ai-assistance.md](docs/contributing/ai-assistance.md): working with an agent, disclosure, agent accounts. - [code-style.md](docs/contributing/code-style.md): code style outside roles. - [reviewing.md](docs/contributing/reviewing.md): closing a fork pull request, merging someone else's, running an unmerged branch locally. -Rules for roles are in [roles/AGENTS.md](roles/AGENTS.md). +Rules tied to one directory are in that directory's `AGENTS.md`: [roles/](roles/AGENTS.md), +[scripts/](scripts/AGENTS.md), [.gitea/workflows/](.gitea/workflows/AGENTS.md), +[images/](images/AGENTS.md) and [docs/adr/](docs/adr/AGENTS.md). diff --git a/docs/adr/AGENTS.md b/docs/adr/AGENTS.md new file mode 100644 index 0000000..d90f92b --- /dev/null +++ b/docs/adr/AGENTS.md @@ -0,0 +1,28 @@ +# ADR rules + +Every rule for the architecture decision records in `docs/adr/`, in full. Each gives its reason +(*Why*) and how it is held (*Held*): a control names its check; review means a person other than +the author sees the change before it merges; aspirational means nothing checks it. + +- **An ADR only for a decision that is hard to reverse, surprising without context, and the + result of a real trade-off** (all three). Anything else is a rule in the contributor docs or a + directory's `AGENTS.md`, or a commit message. *Why:* an ADR is read as binding, so one per + small choice buries the few that matter. *Held:* review. +- **Status is `accepted` or `superseded by NNNN`, nothing else.** A proposal lives in an issue or + a pull request and is never committed as "proposed". *Why:* a committed ADR is either in force + or replaced; a draft in the tree reads as a decision. *Held:* review. +- **An ADR is accepted on the maintainer's approval of its pull request, which sets status + `accepted`.** *Why:* an ADR binds every contributor, so the maintainer decides it. *Held:* + control: the `CODEOWNERS` entry for `docs/adr/`, which requires the maintainer's code-owner + approval. +- **One screen at most:** context, decision and reason first; considered options only when a + rejection is not obvious. *Why:* a decision nobody reads to the end does not guide anyone. + *Held:* review. +- **No infrastructure detail:** no hostnames, addresses, runner sizing, account or secret names. + *Why:* this repository is public, and an ADR outlives the infrastructure it would name. + *Held:* review. +- **An accepted risk is an entry in the "Accepted risks" section of + [SECURITY.md](../../SECURITY.md)** (risk, why accepted, trigger, planned reduction), not an + amendment to an ADR; a later decision that accepts a risk adds an entry there. *Why:* one + register shows every risk the repository carries, and an accepted ADR stays as decided. + *Held:* review (`SECURITY.md` is under `CODEOWNERS`). diff --git a/docs/contributing/code-style.md b/docs/contributing/code-style.md index 36fa84b..8019bad 100644 --- a/docs/contributing/code-style.md +++ b/docs/contributing/code-style.md @@ -1,7 +1,9 @@ # Code style Read this before writing or changing a script, a workflow, a hook, a comment or a guidance document. -Rules for roles are in [roles/AGENTS.md](../../roles/AGENTS.md). +Rules for roles are in [roles/AGENTS.md](../../roles/AGENTS.md); rules for scripts, workflows and images +are in [scripts/AGENTS.md](../../scripts/AGENTS.md), [.gitea/workflows/AGENTS.md](../../.gitea/workflows/AGENTS.md) +and [images/AGENTS.md](../../images/AGENTS.md); rules for ADRs in [docs/adr/AGENTS.md](../adr/AGENTS.md). Every rule gives its reason and how it is held: by a control (a named hook or check), by review, or aspirational (checked by nothing and nobody). Links between the contributor docs are held by review diff --git a/docs/contributing/making-a-change.md b/docs/contributing/making-a-change.md index 6f43077..aa2720d 100644 --- a/docs/contributing/making-a-change.md +++ b/docs/contributing/making-a-change.md @@ -5,7 +5,8 @@ Read this before starting a branch, committing, filing an issue or opening a pul Every rule below gives its reason and how it is held: by a control (a named hook or check), by review, or aspirational (checked by nothing and nobody). Links between the contributor docs are held by review until an offline link check exists. Rules for roles are in -[roles/AGENTS.md](../../roles/AGENTS.md); rules for working with an agent, including commit +[roles/AGENTS.md](../../roles/AGENTS.md), and for scripts, workflows, images and ADRs in the +`AGENTS.md` of their directory (below); rules for working with an agent, including commit trailers, are in [ai-assistance.md](ai-assistance.md). ## Branches and pull requests @@ -84,43 +85,16 @@ trailers, are in [ai-assistance.md](ai-assistance.md). *Reason:* copied comments and paths are where private references slip in. *Held by:* review. -## Dependency and image updates +## Dependency, image and workflow changes -Interim section: it moves to `images/AGENTS.md` and `scripts/AGENTS.md`. +The rules for these live next to the files they govern: [scripts/AGENTS.md](../../scripts/AGENTS.md) +(scripts, their tests, tool pins and their lock, hook SHA pins), +[images/AGENTS.md](../../images/AGENTS.md) (image inputs, version bumps, pin pull requests, the layer +limit), [.gitea/workflows/AGENTS.md](../../.gitea/workflows/AGENTS.md) (workflows, secrets, the +bot-diff gate) and [docs/adr/AGENTS.md](../adr/AGENTS.md) (decision records). -- **A pin in `requirements-dev.txt` changes together with its lock `requirements-dev.lock`.** Renovate - does both; by hand, run `scripts/lock-requirements.sh` (`--upgrade` also moves transitive packages; - it needs PyPI and the Python of `.python-version`) and commit the lock in the same pull request. - *Reason:* installs use `pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`, - which refuses an unhashed package and any disagreement between the two files. - *Held by:* control: the Lint and Build checks install that way when a pin file changes. -- **Hook repositories in `.pre-commit-config.yaml` are pinned by commit SHA, with the release in a - `# frozen: vX.Y.Z` comment.** Find the SHA with - `git ls-remote "refs/tags/" "refs/tags/^{}"` (the `^{}` line, when there is one). - *Reason:* a tag can be moved; a commit SHA cannot. - *Held by:* review (`.pre-commit-config.yaml` is under `CODEOWNERS`). -- **A pull request that changes an image input (`requirements-dev.txt`, `requirements-dev.lock`, - `requirements.yml`, `.pre-commit-config.yaml`, `images/**`) raises that image's `version:` in - `.gitea/workflows/image.yml`** (`python3 scripts/bump_image_versions.py` makes the edit). - *Reason:* a published image version is never rebuilt, so a changed input needs a new version. - *Held by:* control: the Lint check's `Check image versions were bumped` step. -- **After the merge builds the image on `main`, a second pull request moves the - `image:@sha256:` pins in `lint.yml`, `build.yml`, `molecule.yml` and - `gitea-release-key.yml` to the printed digest.** It touches no `image.yml` trigger path, so it rebuilds nothing. - *Reason:* consumers run exactly the digest a reviewer saw. - *Held by:* review; Renovate opens these pull requests for the repository's own images. -- These tooling files are in `galaxy.yml` `build_ignore`, so their bumps change neither the - Collection nor its version. -- **A pull request from a `renovate/` branch changes only version, tag, digest and pin lines.** - *Reason:* the bot's pull requests automerge, so they must not be able to change anything else. - *Held by:* control: `scripts/check_bot_pr_diff.py` in the Lint check, run from `main`'s copy. -- **Workflows never mention the image namespace this repository's CI must not use** (the string is in - `scripts/check_image_versions.py`). - *Reason:* this repository's images are built and pulled only under its own organisation's namespace. - *Held by:* control: the Lint check's `Check image pins` step. -- `renovate.json` configures the bumps (minor and patch automerge, majors by hand). Renovate runs in - `.gitea/workflows/renovate.yml` (daily cron on this repository's runner, as a bot user of this - repository only). Test a config change before the merge with `renovate --platform=local` (the version - in `renovate.yml`), which reads your checkout; a dry run in Actions (Run workflow with `dry_run=true`) - reads `renovate.json` from `main` and proves reads only. Open item: no live run has yet shown that - the bot can push and open a pull request, and that its pull requests get the Lint and Build checks. +- **Test a change to `renovate.json` before the merge with `renovate --platform=local`** (the version + in `.gitea/workflows/renovate.yml`), which reads your checkout. + *Reason:* a dry run in Actions (Run workflow with `dry_run=true`) reads `renovate.json` from `main`, + so it cannot test a pull request's change. + *Held by:* review (`renovate.json` is under `CODEOWNERS`). diff --git a/images/AGENTS.md b/images/AGENTS.md new file mode 100644 index 0000000..68850e8 --- /dev/null +++ b/images/AGENTS.md @@ -0,0 +1,88 @@ +# Image rules + +Every rule for the CI and test images in `images/` (`ci`, `molecule-ubuntu2404`, +`molecule-ubuntu2604`), their build in `.gitea/workflows/image.yml`, and the image-smoke +scenarios in `extensions/molecule/`, in full. Each gives its reason (*Why*) and how it is held +(*Held*): a control names its hook or check; review means a person other than the author sees the +change before it merges (`images/` and `.gitea/` are under `CODEOWNERS`); aspirational means +nothing checks it. "Until X (#N) lands" names a change that is planned and its backlog issue. + +`image.yml` builds each image with kaniko on push to `main`, never on a pull request, and pushes +it to this repository's organisation in the Gitea registry as `` and `latest`. + +## Versions and pins + +- **A published version is never moved and never rebuilt.** The build looks the version up in + the registry first and ends without building when it exists; there is no `sha-*` tag, so one + digest belongs to exactly one version. *Why:* a pin names exactly what a reviewer saw. + *Held:* control: the tag lookup in `image.yml`'s "Prepare kaniko and check the registry + credential" step. +- **A pull request that changes an image input (`requirements-dev.txt`, `requirements-dev.lock`, + `requirements.yml`, `.pre-commit-config.yaml`, `images/**`) raises that image's `version:` (a + PATCH bump) in the `image.yml` build matrix** (`python3 scripts/bump_image_versions.py` makes + the edit). Until #165 assigns versions in CI. *Why:* a published version is never rebuilt, so + a changed input needs a new version. *Held:* control: the Lint check's "Check image versions + were bumped" step. +- **After the merge builds the image, a second pull request moves the + `image:@sha256:` pins in `lint.yml`, `build.yml`, `molecule.yml` and + `gitea-release-key.yml` to the digest the build printed.** It touches no `image.yml` trigger + path, so it rebuilds nothing. Renovate opens it for these images; a new image's first pin is a + hand-made pull request, and a major version is moved by hand. *Why:* consumers run exactly + the digest a reviewer saw. *Held:* review. +- **Image-input bumps are no Collection release:** these files are in `galaxy.yml` + `build_ignore`, and their bumps need no changelog fragment and no new `galaxy.yml` version. + *Why:* they change neither the Collection nor what a consumer installs. *Held:* control for + "not shipped": `scripts/check_tarball.py` in the Build check allows only Collection files in the + archive; review for the version. + +## Releases and the build container + +- **Each molecule image is one Ubuntu release, named after it; a new release is a new image, + added by hand** (Renovate's major `ubuntu` updates are disabled). Roles are tested on every + release a target host runs. *Why:* a role is only proven on the release it runs on. *Held:* + review. +- **Retire an image when no host runs its release.** *Why:* testing on a release nobody runs + costs runner time and proves nothing. *Held:* aspirational. +- **Each matrix entry's `job_image: ubuntu:@sha256:...` has the same release as the + `FROM ubuntu:` of its Dockerfile.** Moving an image to a new release is one edit: the `FROM`, + the `job_image` tag and digest, and the version bump. Digest drift within a release is + tolerated. A `job_image`-only bump is not an image input: no version bump, nothing rebuilt; the + post-merge Images run builds nothing past its prepare step for a published version, so that is + its only exercise. + *Why:* kaniko runs inside the job container and unpacks the image it builds over it. *Held:* + control: `check_image_versions.py pins` in the Lint check. +- **kaniko (the osscontainertools fork) is pinned by layer digests in `image.yml` and bumped by + hand when that fork publishes a release.** *Why:* Renovate cannot compute the layer digests. + *Held:* aspirational. + +## Contents and size + +- **Bake in:** every tool, collection, hook environment and package a CI job uses is in its + image; a job downloads at run time only on the slow path (a pull request that changes a pin + file). *Why:* a run that downloads is slower and depends on the network. *Held:* review until + the network-off check (#168) lands. +- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where + it lives (a comment next to it). *Why:* machinery is kept only for a saving someone can check. + *Held:* review. +- **Every pushed layer stays below 100 MB; when you change an image, estimate each layer's + compressed size and state the estimate in the pull request.** The `ci` build prints the + compressed size of each layer directory, and the registry stores about 9% more. *Why:* Cloudflare rejects + larger request bodies with HTTP 413. *Held:* aspirational; the push failing on `main` is the + backstop, because there is no pull-request build, by the maintainer's choice. + +## Metadata + +- **Each Dockerfile carries the same label block** (`org.opencontainers.image.*` plus + `net.rkdr.mortis.purpose`, `contents` and `usage`); the build adds `version`, `revision` and + `created`. The readme-style text lives in `docs/images/.md`, which the `documentation` + label links to. *Why:* Gitea's package page shows the labels and links but renders no README. + Editing that doc is not an image input and needs no new version; editing a label is and does. + *Held:* control: `check_image_versions.py pins` fails when a label or the doc is missing. + +## Image-smoke scenarios + +- **`extensions/molecule/image-smoke` and `image-smoke-2604` test the molecule images themselves** + (24.04 and 26.04), including that each runs the release its name says. Their image comes from + `MOLECULE_IMAGE` or `MOLECULE_IMAGE_2604` in `molecule.yml`, so a pin pull request runs them. + *Why:* an image is proven by its own pin pull request before a role depends on it. *Held:* + control: the scenarios, in the Molecule check. diff --git a/scripts/AGENTS.md b/scripts/AGENTS.md new file mode 100644 index 0000000..99e49c1 --- /dev/null +++ b/scripts/AGENTS.md @@ -0,0 +1,41 @@ +# Script rules + +Every rule for the scripts in `scripts/` and their tests in `tests/scripts/`, in full. Each gives +its reason (*Why*) and how it is held (*Held*): a control names its hook or check; review means a +person other than the author sees the change before it merges; aspirational means nothing checks +it. "Until X (#N) lands" names a check that does not exist yet and its backlog issue. General +rules for scripts (prefer a standard tool, comment length) are in +[code-style.md](../docs/contributing/code-style.md). + +## Scripts and their tests + +- **A script change comes with its test in `tests/scripts/`** (`test_