diff --git a/.gitea/workflows/AGENTS.md b/.gitea/workflows/AGENTS.md index 22c2070..559ac58 100644 --- a/.gitea/workflows/AGENTS.md +++ b/.gitea/workflows/AGENTS.md @@ -50,8 +50,8 @@ issue. 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. + only under its own organisation's namespace. *Held:* control: the `check-image-pins` hook, + run by the Lint check. ## Lint and Build @@ -62,13 +62,12 @@ issue. *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. - **On the fast path the network is cut by environment**: `PIP_NO_INDEX=1`, the proxy variables - set to a dead local port and `no_proxy` empty, for every later step except "Test the repository - scripts", which unsets them for its fake registry on loopback; the slow path keeps network. + set to a dead local port and `no_proxy` empty, for every later step; the slow path keeps + network. The script tests set `no_proxy` to `127.0.0.1` for their fake registry on loopback. *Why:* a runtime download is a bake-in defect and must fail the job, not silently slow it. *Held:* control, set by the "Check the baked tooling against the pins" step, for pip, curl, git over HTTPS and Python's urllib or requests (anything honouring `PIP_NO_INDEX` or the proxy - variables); review for a raw socket or a tool that ignores the proxy variables, and for the - script tests. + variables); review for a raw socket or a tool that ignores the proxy variables. - **Triggers:** both run on pull requests to `main` 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. diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 2ac301b..8e5abef 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -78,14 +78,6 @@ jobs: export PATH="/opt/venv/bin:$PATH" pre-commit run --all-files --show-diff-on-failure - # Image pins (scripts/check_image_versions.py): a pin in a workflow must name an - # image of the matrix. Not a pre-commit hook: a change to .pre-commit-config.yaml - # is itself an input of the ci image and would force an image rebuild. - - name: Check image pins - run: | - export PATH="/opt/venv/bin:$PATH" - python3 scripts/check_image_versions.py pins - # A pull request from a renovate/ branch may only move version, tag, digest and pin # lines (scripts/check_bot_pr_diff.py), so the bot's automerge cannot change workflow # logic or reach the org secrets. The branch name is attacker-controlled: this only @@ -113,12 +105,11 @@ jobs: fi python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF" - # Without the guard: an empty no_proxy would send the fake registry on 127.0.0.1 to the dead proxy. - - name: Test the repository scripts + # The script tests are a pre-push hook (they take minutes), so --all-files above skips them. + - name: Run the script tests hook run: | - unset PIP_NO_INDEX http_proxy https_proxy HTTP_PROXY HTTPS_PROXY export PATH="/opt/venv/bin:$PATH" - python3 -m unittest discover -s tests/scripts + pre-commit run --hook-stage pre-push script-tests --all-files --show-diff-on-failure # The gitleaks hook scans --staged only, which is empty in a clean checkout, # so scan the PR's commits explicitly with the binary pre-commit built. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cbef59c..bb0e699 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,6 +49,8 @@ repos: hooks: - id: check-toml stages: ['pre-commit'] + - id: check-json + stages: ['pre-commit'] - id: check-merge-conflict stages: ['pre-commit'] @@ -114,6 +116,27 @@ repos: require_serial: true stages: ['pre-push'] + # Pre-push only: the suite takes minutes. Lint runs it by id. The uncreatable GIT_DIR makes a + # git fixture that keeps the caller's GIT_* fail instead of writing to this repository. + - id: script-tests + name: A script change passes its tests in tests/scripts (scripts/AGENTS.md) + description: python3 -m unittest discover -s tests/scripts + entry: env GIT_DIR=/dev/null/not-a-repo python3 -m unittest discover -s tests/scripts + language: system + files: ^(scripts/|tests/scripts/|roles/[^/]+/meta/) + pass_filenames: false + stages: ['pre-push'] + + # always_run: its inputs span workflows, Dockerfiles and docs/images, and it fails on a missing one. + - id: check-image-pins + name: Image pins name an image of the image.yml matrix, which has its job image, labels and docs (images/AGENTS.md) + description: python3 scripts/check_image_versions.py pins + entry: python3 scripts/check_image_versions.py pins + language: system + pass_filenames: false + always_run: true + stages: ['pre-commit'] + # SECURITY.md's accepted risks rest on the Collection shipping roles only. It sits before # ansible-lint, whose fail_fast would otherwise hide this message. - id: refuse-plugins diff --git a/docs/images/ci.md b/docs/images/ci.md index 30052ab..d8af45f 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -11,7 +11,7 @@ Ubuntu 26.04 with: - **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`, `ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` - (without its Docker driver: Lint's "Test the repository scripts" step runs the tests that import it), and + (without its Docker driver: Lint's run of the `script-tests` hook runs the tests that import it), and `proxmoxer`, the controller-side library the modules of `community.proxmox` import. - **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from `requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so @@ -20,7 +20,7 @@ Ubuntu 26.04 with: (`PRE_COMMIT_HOME`): conventional-pre-commit, gitleaks, yamllint, ruff, shellcheck-py, pre-commit-hooks, actionlint and zizmor. The Go hooks are prebuilt; their toolchains, and the binaries of those repositories that no hook runs, are removed to keep layers small. The local hooks (`reuse-lint`, - `antsibull-changelog-lint`, `ansible-lint`) are `language: system`: they run from `/opt/venv`, which is why + `antsibull-changelog-lint`, `ansible-lint`, `script-tests`, `check-image-pins`) are `language: system`: they run from `/opt/venv`, which is why that directory must be on `PATH` (it is, in the image). - **`ansible-test sanity` virtualenvs**, primed in `/root/.ansible/test`, and Python 3.11, 3.13 and 3.14 as `python3.11` / `python3.13` / `python3.14` (python-build-standalone, installed with uv) next to the distribution's @@ -63,7 +63,7 @@ jobs: `/opt/ci-pins.sha256` lists the four pin files by their checkout-relative path, so `sha256sum -c` runs in the checkout root. When the checkout's `requirements-dev.txt`, `requirements-dev.lock`, `requirements.yml` and `.pre-commit-config.yaml` match, the baked tools and collections are used as they are, and Lint and Build cut the network by environment (proxy variables and -`PIP_NO_INDEX`) for all but the script tests, so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned +`PIP_NO_INDEX`), so a tool that downloads at run time fails the job. When a pull request changes a pin the check fails and the job installs the pinned tools and collections itself for that run (slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml` and `gitea-release-key.yml` are the real consumers. diff --git a/images/AGENTS.md b/images/AGENTS.md index 1cc8c19..d64a50a 100644 --- a/images/AGENTS.md +++ b/images/AGENTS.md @@ -63,8 +63,7 @@ it to this repository's organisation in the Gitea registry as `` and `l 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:* control: on the fast path Lint and Build cut the network by environment, so a download through pip or a - proxy-honouring client fails the job; review for a raw socket, for the script tests, which keep - network, and for Molecule. + proxy-honouring client fails the job; review for a raw socket and for Molecule. - **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu publishes package updates before it refreshes the base image. *Held:* review. - **Recorded speed:** a speed optimisation that adds machinery states its measured saving where diff --git a/images/ci/Dockerfile b/images/ci/Dockerfile index 5de8985..7a05aae 100644 --- a/images/ci/Dockerfile +++ b/images/ci/Dockerfile @@ -15,7 +15,7 @@ # - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit, # antsibull-changelog, galaxy-importer, reuse, molecule, proxmoxer), on the Python of # .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv-dev uses. -# molecule is there for Lint's "Test the repository scripts" step, whose molecule tests import it; its +# molecule is there for Lint's run of the script-tests hook, whose molecule tests import it; its # Docker driver and community.docker are not: Molecule runs in the molecule-controller image. # - /opt/collections: the collections of requirements.yml (the versions the roles are # tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline` diff --git a/requirements-dev.txt b/requirements-dev.txt index 2d36974..8ab05f5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,7 +12,7 @@ pre-commit==4.7.0 antsibull-changelog==0.38.0 galaxy-importer==0.4.45 reuse==6.3.0 -# molecule without its Docker driver: Lint's "Test the repository scripts" step imports it in +# molecule without its Docker driver: Lint's run of the script-tests hook imports it in # test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it. molecule==26.11.1 # proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3), diff --git a/scripts/AGENTS.md b/scripts/AGENTS.md index 827e5d3..51b3274 100644 --- a/scripts/AGENTS.md +++ b/scripts/AGENTS.md @@ -12,8 +12,8 @@ rules for scripts (prefer a standard tool, comment length) are in - **A script change comes with its test in `tests/scripts/`** (`test_