ci: resolve the Collection's own roles in lint and run ansible-test sanity before a push #126

Merged
Defame1297 merged 4 commits from ci/lint-resolve-own-collection into main 2026-11-14 15:59:29 +00:00
Owner

Step 5 of #118, the last open item, plus a pre-push hook for ansible-test sanity that came out of this PR's own Build failure. Refs #118. This PR is an image input (it edits .pre-commit-config.yaml): it carries the ci bump 0.2.17 -> 0.2.18, and a pin-follow PR is needed after the merge builds the image.

1. Lint resolves the Collection's own roles; mock_roles is gone (3289c0d)

The molecule scenarios' converge plays call the roles by FQCN (mortis.kamino.<role>), which only resolves from an ansible_collections/<namespace>/<name> directory, and a checkout is not one. .ansible-lint therefore listed the five roles in mock_roles, and ansible-lint never checked those plays against the real roles.

scripts/ansible-lint.sh, which the ansible-lint hook runs in CI and locally, links the checkout as ansible_collections/<namespace>/<name> in a temporary root (namespace and name read from galaxy.yml), puts that root first on ANSIBLE_COLLECTIONS_PATH (after it comes CI's /opt/collections or the clone's .ansible/collections, as before) and removes it on exit. It no longer execs ansible-lint, so the cleanup trap runs; the exit code is unchanged. A bare ansible-lint outside the hook gets no link; .ansible-lint says so.

2. A name the sanity pylint disallows (6b930a0)

The first Build run of this PR failed in ansible-test sanity: tests/scripts/test_ansible_lint_wrapper.py:37:13: disallowed-name: Disallowed name "_". Ruff accepts the name; the pylint configuration of ansible-test, which also scans the Python under tests/, does not. Fixed by indexing the partition result.

3. ansible-test sanity before a push (574c0d0, 18a7e26)

  • scripts/ansible-test-sanity.sh copies HEAD (git archive: the committed files only) into a temporary ansible_collections/<namespace>/<name>, applies the Build job's ignore-file step (ignore-common.txt to ignore-<core MAJOR.MINOR>.txt) and runs ansible-test sanity --requirements, passing extra arguments through. Eleven tests cover it.
  • A pre-push hook (language: system, always_run, pass_filenames: false) runs it. pre-push is in default_install_hook_types, and dev-setup.sh treats it like the other two hook types, so its hook script also gets the virtualenv on PATH. It is pre-push and not pre-commit because a cold run builds virtualenvs and needs the network (minutes), then reuses them. CI's pre-commit run --all-files does not run that stage (the Build job runs sanity itself), and a system hook builds no environment, so the image gains no layer size.
  • CLAUDE.md and CONTRIBUTING.md say that git push runs it.

Image loop

.pre-commit-config.yaml is baked into the ci image, so scripts/bump_image_versions.py moved ci 0.2.17 -> 0.2.18 (check_image_versions.py bump origin/main passes). After the merge image.yml builds 0.2.18 on main (the build prints the compressed layer sizes) and a pin-follow PR moves lint.yml and build.yml. Until that PR, Lint on main runs on the 0.2.17 image, whose baked checksums differ from this repository's .pre-commit-config.yaml, so Lint takes the install path for that stretch.

Verified

  • Removing mock_roles alone, linted the way CI does, reproduced 5 syntax-check[specific] errors; with the link the run passes with no warnings, locally and with CI's preset path. The wrapper leaves no temporary directory after a pass or a failing lint.
  • The real ansible-test-sanity.sh ran end to end against the real ansible-test on the committed tree (34 test runs on this host, no findings; the host has no Python 3.14 or 3.15 interpreter for the compile test, CI runs 36). It also ran for real as the pre-push hook of this push: ansible-test sanity ... Passed.
  • Through git push --dry-run in a throwaway clone with the hook installed: a commit with _ as a name inside a function is blocked (exit 1, the same pylint message as CI, failed to push some refs), and the push passes once it is removed. A module-level _ is not flagged by that pylint, so the check is as strict as CI's and no stricter.
  • scripts/dev-setup.sh run for real installs the pre-push hook script with the PATH marker next to the other two.
  • 174 script tests pass; every hook passed on every commit except the format commit's retries, which were ruff-format rewriting a new file before the commit went through.

Not verified

  • This PR's Lint and Build runs on the pushed head: Build failed on the first head only for the name above, which the sanity run now reproduces and clears locally.
  • The image build of 0.2.18 and the baked path with the three-hook-type config: both run only on main.

Things to know

  • With the real roles resolved, ansible-lint now checks the scenarios' converge plays against them; they pass today, but lint can fail on a play where mock_roles used to hide it.
  • The pre-push hook checks HEAD: a push of another branch than the checked-out one checks the wrong commit (the script says so).
  • Whether to comment on or close #112 and #118 afterwards is yours; this PR does not use a closing keyword.

🤖 Generated with Claude Code

Step 5 of #118, the last open item, plus a pre-push hook for `ansible-test sanity` that came out of this PR's own Build failure. Refs #118. **This PR is an image input** (it edits `.pre-commit-config.yaml`): it carries the `ci` bump 0.2.17 -> 0.2.18, and a pin-follow PR is needed after the merge builds the image. ## 1. Lint resolves the Collection's own roles; `mock_roles` is gone (3289c0d) The molecule scenarios' converge plays call the roles by FQCN (`mortis.kamino.<role>`), which only resolves from an `ansible_collections/<namespace>/<name>` directory, and a checkout is not one. `.ansible-lint` therefore listed the five roles in `mock_roles`, and ansible-lint never checked those plays against the real roles. `scripts/ansible-lint.sh`, which the `ansible-lint` hook runs in CI and locally, links the checkout as `ansible_collections/<namespace>/<name>` in a temporary root (namespace and name read from `galaxy.yml`), puts that root first on `ANSIBLE_COLLECTIONS_PATH` (after it comes CI's `/opt/collections` or the clone's `.ansible/collections`, as before) and removes it on exit. It no longer `exec`s ansible-lint, so the cleanup trap runs; the exit code is unchanged. A bare `ansible-lint` outside the hook gets no link; `.ansible-lint` says so. ## 2. A name the sanity pylint disallows (6b930a0) The first Build run of this PR failed in `ansible-test sanity`: `tests/scripts/test_ansible_lint_wrapper.py:37:13: disallowed-name: Disallowed name "_"`. Ruff accepts the name; the pylint configuration of ansible-test, which also scans the Python under `tests/`, does not. Fixed by indexing the `partition` result. ## 3. `ansible-test sanity` before a push (574c0d0, 18a7e26) - `scripts/ansible-test-sanity.sh` copies `HEAD` (`git archive`: the committed files only) into a temporary `ansible_collections/<namespace>/<name>`, applies the Build job's ignore-file step (`ignore-common.txt` to `ignore-<core MAJOR.MINOR>.txt`) and runs `ansible-test sanity --requirements`, passing extra arguments through. Eleven tests cover it. - A `pre-push` hook (`language: system`, `always_run`, `pass_filenames: false`) runs it. `pre-push` is in `default_install_hook_types`, and `dev-setup.sh` treats it like the other two hook types, so its hook script also gets the virtualenv on `PATH`. It is pre-push and not pre-commit because a cold run builds virtualenvs and needs the network (minutes), then reuses them. CI's `pre-commit run --all-files` does not run that stage (the Build job runs sanity itself), and a system hook builds no environment, so the image gains no layer size. - `CLAUDE.md` and `CONTRIBUTING.md` say that `git push` runs it. ## Image loop `.pre-commit-config.yaml` is baked into the `ci` image, so `scripts/bump_image_versions.py` moved `ci` 0.2.17 -> 0.2.18 (`check_image_versions.py bump origin/main` passes). After the merge `image.yml` builds 0.2.18 on `main` (the build prints the compressed layer sizes) and a pin-follow PR moves `lint.yml` and `build.yml`. Until that PR, Lint on `main` runs on the 0.2.17 image, whose baked checksums differ from this repository's `.pre-commit-config.yaml`, so Lint takes the install path for that stretch. ## Verified - Removing `mock_roles` alone, linted the way CI does, reproduced 5 `syntax-check[specific]` errors; with the link the run passes with no warnings, locally and with CI's preset path. The wrapper leaves no temporary directory after a pass or a failing lint. - The real `ansible-test-sanity.sh` ran end to end against the real `ansible-test` on the committed tree (34 test runs on this host, no findings; the host has no Python 3.14 or 3.15 interpreter for the compile test, CI runs 36). It also ran for real as the pre-push hook of this push: `ansible-test sanity ... Passed`. - Through `git push --dry-run` in a throwaway clone with the hook installed: a commit with `_` as a name inside a function is blocked (exit 1, the same pylint message as CI, `failed to push some refs`), and the push passes once it is removed. A module-level `_` is not flagged by that pylint, so the check is as strict as CI's and no stricter. - `scripts/dev-setup.sh` run for real installs the `pre-push` hook script with the `PATH` marker next to the other two. - 174 script tests pass; every hook passed on every commit except the format commit's retries, which were `ruff-format` rewriting a new file before the commit went through. ## Not verified - This PR's Lint and Build runs on the pushed head: Build failed on the first head only for the name above, which the sanity run now reproduces and clears locally. - The image build of 0.2.18 and the baked path with the three-hook-type config: both run only on `main`. ## Things to know - With the real roles resolved, ansible-lint now checks the scenarios' converge plays against them; they pass today, but lint can fail on a play where `mock_roles` used to hide it. - The pre-push hook checks `HEAD`: a push of another branch than the checked-out one checks the wrong commit (the script says so). - Whether to comment on or close #112 and #118 afterwards is yours; this PR does not use a closing keyword. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Claude added 1 commit 2026-11-14 15:41:43 +00:00
ci(lint): resolve the Collection's own roles and drop mock_roles
Build / build (pull_request) Failing after 11s
Lint / lint (pull_request) Successful in 20s
Molecule / molecule (pull_request) Successful in 1s
3289c0d430
Step 5 of #118. The scenarios' converge plays call the roles by FQCN (mortis.kamino.<role>), which only resolves from an ansible_collections/<namespace>/<name> directory, and a checkout is not one, so .ansible-lint listed the five roles in mock_roles and ansible-lint never checked those plays against the real roles.

scripts/ansible-lint.sh, which the ansible-lint hook runs in CI and locally, now links the checkout as ansible_collections/<namespace>/<name> in a temporary root (namespace and name read from galaxy.yml), puts that root first on ANSIBLE_COLLECTIONS_PATH and removes it on exit, so ansible-lint reads the checkout itself. Removing mock_roles reproduced five syntax-check[specific] role-not-found errors; with the link the run passes with no warnings, locally and with CI's preset path. A bare ansible-lint, outside the hook, does not get the link; .ansible-lint says so.

No image input changes: .pre-commit-config.yaml, requirements and images/** are untouched, so no version bump or second pull request. Closes the last open item of #118.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Defame1297 added 3 commits 2026-11-14 15:53:25 +00:00
The Build check failed in ansible-test sanity: pylint reported tests/scripts/test_ansible_lint_wrapper.py:37:13 disallowed-name for `_`, from unpacking the middle of str.partition. Ruff accepts the name, but the pylint configuration of ansible-test, which also scans the Python under tests/, does not. Index the partition result instead. Reproduced locally with ansible-test sanity --test pylint on a copy of the tree under ansible_collections/mortis/kamino: the committed file fails with the same message, this one passes.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
ansible-test only runs a collection from an ansible_collections/<namespace>/<name> directory, so scripts/ansible-test-sanity.sh copies HEAD (git archive: the committed files only) into a temporary one, applies the Build job's ignore-file step and runs ansible-test sanity --requirements, passing extra arguments through. The sanity tests carry their own pylint, pep8 and shellcheck settings and also scan the Python under tests/, which ruff and the other hooks do not (the Build check failed on a name only that pylint disallows). The hook that runs it before a push follows in the next commit.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
ci(hooks): run ansible-test sanity before a push
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Successful in 30s
Molecule / molecule (pull_request) Successful in 5m22s
18a7e26e4f
Add a pre-push hook that runs scripts/ansible-test-sanity.sh, so the Build job's sanity check, which ruff and the other hooks do not cover (it failed on a name only its pylint disallows), stops a push instead of the pull request. It is pre-push and not pre-commit because a cold run builds virtualenvs and needs the network; CI's pre-commit run does not run that stage, and a local system hook builds no environment. pre-push joins default_install_hook_types, and dev-setup.sh and its test treat it like the other two hook types, so its hook script also gets the virtualenv on PATH.

Verified through git push --dry-run in a throwaway clone: a commit with a disallowed name inside a function is blocked (exit 1, the same pylint message as CI, failed to push), and the push passes once it is removed.

Image input: .pre-commit-config.yaml is baked into the ci image, so ci 0.2.17 -> 0.2.18 (scripts/bump_image_versions.py). The new hook adds no hook environment and no layer size; the merge builds 0.2.18 and a pin PR follows.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Claude changed title from ci(lint): resolve the Collection's own roles and drop mock_roles to ci: resolve the Collection's own roles in lint and run ansible-test sanity before a push 2026-11-14 15:53:44 +00:00
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-11-14 15:58:54 +00:00
Defame1297 merged commit 8e66a1154c into main 2026-11-14 15:59:29 +00:00
Defame1297 deleted branch ci/lint-resolve-own-collection 2026-11-14 15:59:30 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#126