ci(pre-commit): run check-json, the script tests and the image pins as hooks
A contributor learns about a broken renovate.json, a failing script test or a bad image pin from Lint today; as hooks they fail before the push. - check-json from pre-commit-hooks covers renovate.json. - script-tests runs the suite at pre-push, since it takes minutes. Its GIT_DIR points at an uncreatable path, so a fixture that keeps the caller's git environment fails instead of writing to this repository. Lint runs it by id; the suite now runs under the network guard. - check-image-pins runs check_image_versions.py pins on every commit: its inputs span workflows, Dockerfiles and docs/images, and it fails when one is missing. Lint's pre-commit run replaces its separate step. Adding hooks changes .pre-commit-config.yaml, an input of the ci image, so this pull request takes Lint's slow path and the next Images run publishes a new ci version. Refs: #187 Assisted-by: Claude Code
This commit is contained in:
1 parent
b2e547edd5
commit
fac7ed47be
8 files changed
+39
-27
No files matched your search
@@ -50,8 +50,8 @@ issue.
|
|||||||
branch name is chosen by the pusher, so this constrains only the bot's own pull requests.
|
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
|
- **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
|
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
|
only under its own organisation's namespace. *Held:* control: the `check-image-pins` hook,
|
||||||
pins" step.
|
run by the Lint check.
|
||||||
|
|
||||||
## Lint and Build
|
## 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.
|
*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.
|
*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
|
- **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
|
set to a dead local port and `no_proxy` empty, for every later step; the slow path keeps
|
||||||
scripts", which unsets them for its fake registry on loopback; the slow path keeps network.
|
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.
|
*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
|
*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
|
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
|
variables); review for a raw socket or a tool that ignores the proxy variables.
|
||||||
script tests.
|
|
||||||
- **Triggers:** both run on pull requests to `main` and on manual dispatch; Build also runs on
|
- **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
|
`v*` tags, where it checks the tag against `galaxy.yml`. *Why:* the tag is what consumers
|
||||||
install. *Held:* review.
|
install. *Held:* review.
|
||||||
|
|||||||
@@ -78,14 +78,6 @@ jobs:
|
|||||||
export PATH="/opt/venv/bin:$PATH"
|
export PATH="/opt/venv/bin:$PATH"
|
||||||
pre-commit run --all-files --show-diff-on-failure
|
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
|
# 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
|
# 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
|
# logic or reach the org secrets. The branch name is attacker-controlled: this only
|
||||||
@@ -113,12 +105,11 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
python3 -E -s "$guard" "$HEAD_REF" "$BASE_REF"
|
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.
|
# The script tests are a pre-push hook (they take minutes), so --all-files above skips them.
|
||||||
- name: Test the repository scripts
|
- name: Run the script tests hook
|
||||||
run: |
|
run: |
|
||||||
unset PIP_NO_INDEX http_proxy https_proxy HTTP_PROXY HTTPS_PROXY
|
|
||||||
export PATH="/opt/venv/bin:$PATH"
|
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,
|
# 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.
|
# so scan the PR's commits explicitly with the binary pre-commit built.
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
stages: ['pre-commit']
|
stages: ['pre-commit']
|
||||||
|
- id: check-json
|
||||||
|
stages: ['pre-commit']
|
||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
stages: ['pre-commit']
|
stages: ['pre-commit']
|
||||||
|
|
||||||
@@ -114,6 +116,27 @@ repos:
|
|||||||
require_serial: true
|
require_serial: true
|
||||||
stages: ['pre-push']
|
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
|
# 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.
|
# ansible-lint, whose fail_fast would otherwise hide this message.
|
||||||
- id: refuse-plugins
|
- id: refuse-plugins
|
||||||
|
|||||||
+3
-3
@@ -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`,
|
- **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`
|
`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.
|
`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
|
- **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
|
`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
|
(`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
|
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`,
|
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).
|
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
|
- **`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
|
`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
|
`/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
|
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
|
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
|
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`
|
(slower, same result), until the image is rebuilt from `main`. `lint.yml`, `build.yml` and `gitea-release-key.yml`
|
||||||
are the real consumers.
|
are the real consumers.
|
||||||
|
|||||||
+1
-2
@@ -63,8 +63,7 @@ it to this repository's organisation in the Gitea registry as `<version>` and `l
|
|||||||
image; a job downloads at run time only on the slow path (a pull request that changes a pin
|
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
|
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
|
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
|
proxy-honouring client fails the job; review for a raw socket and for Molecule.
|
||||||
network, and for Molecule.
|
|
||||||
- **Each Dockerfile upgrades the base image's packages in its first apt layer.** *Why:* Ubuntu
|
- **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.
|
publishes package updates before it refreshes the base image. *Held:* review.
|
||||||
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
|
- **Recorded speed:** a speed optimisation that adds machinery states its measured saving where
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
# - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit,
|
# - /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
|
# 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.
|
# .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.
|
# 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
|
# - /opt/collections: the collections of requirements.yml (the versions the roles are
|
||||||
# tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline`
|
# tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline`
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pre-commit==4.7.0
|
|||||||
antsibull-changelog==0.38.0
|
antsibull-changelog==0.38.0
|
||||||
galaxy-importer==0.4.45
|
galaxy-importer==0.4.45
|
||||||
reuse==6.3.0
|
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.
|
# test_check_scenarios_load_checkout.py and test_run_molecule_scenarios.py, which skip without it.
|
||||||
molecule==26.11.1
|
molecule==26.11.1
|
||||||
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
|
# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3),
|
||||||
|
|||||||
+2
-2
@@ -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_<script>.py`), in the same
|
- **A script change comes with its test in `tests/scripts/`** (`test_<script>.py`), in the same
|
||||||
pull request. Run them with `python3 -m unittest discover -s tests/scripts`.
|
pull request. Run them with `python3 -m unittest discover -s tests/scripts`.
|
||||||
*Why:* a script decides whether a pull request passes, so an untested change can wave through
|
*Why:* a script decides whether a pull request passes, so an untested change can wave through
|
||||||
what it should stop. *Held:* control: the Lint check's "Test the repository scripts" step runs
|
what it should stop. *Held:* control: the `script-tests` pre-push hook runs the
|
||||||
the tests; review for whether the change is tested at all.
|
tests, and the Lint check runs it again; review for whether the change is tested at all.
|
||||||
- **A line added to `tests/sanity/ignore-common.txt` is a last resort and carries its reason** as
|
- **A line added to `tests/sanity/ignore-common.txt` is a last resort and carries its reason** as
|
||||||
a trailing `# ...` comment. Fix the finding first. A finding of one ansible-core version only
|
a trailing `# ...` comment. Fix the finding first. A finding of one ansible-core version only
|
||||||
goes in a committed `ignore-<MAJOR.MINOR>.txt`, which the Build job appends.
|
goes in a committed `ignore-<MAJOR.MINOR>.txt`, which the Build job appends.
|
||||||
|
|||||||
Reference in new issue
Block a user