ci: lint scripts with ruff and shellcheck, bake pinned collections into the ci image #121

Merged
Defame1297 merged 11 commits from ci/ruff-shellcheck-and-baked-collections into main 2026-11-14 14:45:23 +00:00
Owner

Refs #112, #118. PR 1 of the two-PR image loop: it carries the input changes and the ci bump 0.2.15 -> 0.2.16 (one bump for both issues). It does not close either issue: the consumer pins move in PR 2 after the merge builds the image, and #118 step 5 (mock_roles) stays open.

#112: ruff and shellcheck

  • ruff-check, ruff-format (astral-sh/ruff-pre-commit v0.17.5) and shellcheck (shellcheck-py v0.11.0.1) hooks; ruff.toml is ruff's default rule set plus C901, PLR0912, PLR0915 at default thresholds. No global ignore, no tuned threshold.
  • ruff format is its own commit. Findings are fixed, or suppressed inline with a rule code and a reason (three functions; two of them name #96 as their possible replacement). No per-file entry was needed.
  • The Dockerfile smoke test now also runs the three new hooks on a staged sample, so a missing environment fails the image build.

#118: collections (steps 1-4)

  • requirements.yml: exact pins (community.general 14.0.0, ansible.posix 2.2.2), baked into /opt/collections of the ci image and added to /opt/ci-pins.sha256. Lint sets ANSIBLE_COLLECTIONS_PATH; mock_modules is gone from .ansible-lint.
  • Molecule installs the same file itself (cached on the runner by the file's checksum) instead of reading /opt/molecule-collections.
  • scripts/dev-setup.sh installs the pins into .ansible/collections; the ansible-lint hook runs scripts/ansible-lint.sh, which uses them when ANSIBLE_COLLECTIONS_PATH is unset (git commit or a bare pre-commit run) and leaves CI's preset path alone.
  • Renovate's ansible-galaxy manager tracks requirements.yml, and the bot-diff gate lets a bot change only its version: lines. renovate.json is touched although #112 says it is not: #118 requires the tracking.

Verified

  • All 158 script tests pass; check_image_versions.py pins and bump origin/main pass; every commit passed all hooks except the one below.
  • #112 acceptance: an unused import in a script makes ruff-check fail, and an unquoted variable in dev-setup.sh makes shellcheck fail (SC2086). Both were tried, then reverted.
  • #118 acceptance: ansible-lint --offline passes with no mock list against the pinned collections alone, and fails with syntax-check[unknown-module] for community.general.locale_gen with none. The real dev-setup.sh replaced a stale community.general 14.0.1 with the pinned 14.0.0. Bare pre-commit run ansible-lint passes with the clone's collections and fails with the fix message without them.
  • A subagent code review (standards and spec) found no hard violations; three small defects it found are fixed in 42ad8de.

Not verified (no container runtime here; first exercised by CI)

  • The ci image build: the collections install, layer sizes (community.general is about 29 MB installed) and the new smoke steps ran only as a dry run against this repo's hook config.
  • The Molecule install step and its checksum cache on the runner.
  • That Renovate's ansible-galaxy manager parses requirements.yml as intended.

Things to know

  • db1c1e1 (the ruff format commit) skipped the ruff-check hook only (SKIP=ruff-check): it cannot pass on unformatted code that still has findings, which the next commit fixes. All hooks ran on every other commit.
  • ruff 0.17.5's default rule set is much wider than the older E/F set, which produced 27 findings; I kept "ruff's defaults" as #112 says.
  • The new hooks make ruff write .ruff_cache/ into the checkout, which test_real_build_passes caught in the Collection archive; it is now in build_ignore.
  • Until PR 2 moves the pins, Lint runs on the old 0.2.15 image, which has no /opt/collections. It takes the install path only because .pre-commit-config.yaml differs from what that image baked. Merge PR 2 promptly after the image builds.
  • ansible-galaxy skips a collection it finds elsewhere on the path as already installed, so every install here scopes ANSIBLE_COLLECTIONS_PATH to its target.

🤖 Generated with Claude Code

Refs #112, #118. PR 1 of the two-PR image loop: it carries the input changes and the `ci` bump 0.2.15 -> 0.2.16 (one bump for both issues). It does not close either issue: the consumer pins move in PR 2 after the merge builds the image, and #118 step 5 (`mock_roles`) stays open. ## #112: ruff and shellcheck - `ruff-check`, `ruff-format` (astral-sh/ruff-pre-commit v0.17.5) and `shellcheck` (shellcheck-py v0.11.0.1) hooks; `ruff.toml` is ruff's default rule set plus C901, PLR0912, PLR0915 at default thresholds. No global ignore, no tuned threshold. - `ruff format` is its own commit. Findings are fixed, or suppressed inline with a rule code and a reason (three functions; two of them name #96 as their possible replacement). No per-file entry was needed. - The Dockerfile smoke test now also runs the three new hooks on a staged sample, so a missing environment fails the image build. ## #118: collections (steps 1-4) - `requirements.yml`: exact pins (community.general 14.0.0, ansible.posix 2.2.2), baked into `/opt/collections` of the `ci` image and added to `/opt/ci-pins.sha256`. Lint sets `ANSIBLE_COLLECTIONS_PATH`; `mock_modules` is gone from `.ansible-lint`. - Molecule installs the same file itself (cached on the runner by the file's checksum) instead of reading `/opt/molecule-collections`. - `scripts/dev-setup.sh` installs the pins into `.ansible/collections`; the `ansible-lint` hook runs `scripts/ansible-lint.sh`, which uses them when `ANSIBLE_COLLECTIONS_PATH` is unset (git commit or a bare `pre-commit run`) and leaves CI's preset path alone. - Renovate's `ansible-galaxy` manager tracks `requirements.yml`, and the bot-diff gate lets a bot change only its `version:` lines. `renovate.json` is touched although #112 says it is not: #118 requires the tracking. ## Verified - All 158 script tests pass; `check_image_versions.py pins` and `bump origin/main` pass; every commit passed all hooks except the one below. - #112 acceptance: an unused import in a script makes `ruff-check` fail, and an unquoted variable in `dev-setup.sh` makes `shellcheck` fail (SC2086). Both were tried, then reverted. - #118 acceptance: `ansible-lint --offline` passes with no mock list against the pinned collections alone, and fails with `syntax-check[unknown-module]` for `community.general.locale_gen` with none. The real `dev-setup.sh` replaced a stale community.general 14.0.1 with the pinned 14.0.0. Bare `pre-commit run ansible-lint` passes with the clone's collections and fails with the fix message without them. - A subagent code review (standards and spec) found no hard violations; three small defects it found are fixed in `42ad8de`. ## Not verified (no container runtime here; first exercised by CI) - The `ci` image build: the collections install, layer sizes (community.general is about 29 MB installed) and the new smoke steps ran only as a dry run against this repo's hook config. - The Molecule install step and its checksum cache on the runner. - That Renovate's `ansible-galaxy` manager parses `requirements.yml` as intended. ## Things to know - `db1c1e1` (the ruff format commit) skipped the `ruff-check` hook only (`SKIP=ruff-check`): it cannot pass on unformatted code that still has findings, which the next commit fixes. All hooks ran on every other commit. - ruff 0.17.5's default rule set is much wider than the older E/F set, which produced 27 findings; I kept "ruff's defaults" as #112 says. - The new hooks make ruff write `.ruff_cache/` into the checkout, which `test_real_build_passes` caught in the Collection archive; it is now in `build_ignore`. - Until PR 2 moves the pins, Lint runs on the old 0.2.15 image, which has no `/opt/collections`. It takes the install path only because `.pre-commit-config.yaml` differs from what that image baked. Merge PR 2 promptly after the image builds. - `ansible-galaxy` skips a collection it finds elsewhere on the path as already installed, so every install here scopes `ANSIBLE_COLLECTIONS_PATH` to its target. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Claude added 10 commits 2026-11-14 14:23:42 +00:00
Add ruff-check and ruff-format from astral-sh/ruff-pre-commit and shellcheck from
shellcheck-py, with ruff.toml at ruff's defaults plus C901, PLR0912 and PLR0915
(#112). ruff.toml is repository tooling, so it joins galaxy.yml build_ignore.

The existing scripts are formatted and fixed in the commits that follow.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Output of `ruff format` and nothing else, in its own commit so the diff is
reviewable (#112). The ruff-check hook is skipped for this commit only: its
findings are fixed in the next one.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Fix what ruff 0.17.5's default rule set and the complexity rules report (#112):
removeprefix/removesuffix instead of slicing, `_unused` for discarded tuple
members, obsolete `noqa: E402` removed, a parenthesised string pair and an
immutable class constant in the tests.

Three functions stay over a complexity threshold and carry an inline
`# noqa` with the rule code and a reason: matrix_of and copy_sources of
check_image_versions.py (#96 may replace them) and path_problems of
check_tarball.py. No rule is ignored globally and no threshold is tuned.

ruff writes .ruff_cache/ into the checkout, which test_real_build_passes
caught in the Collection archive: add it to galaxy.yml build_ignore. ruff.toml
joins the molecule selector's IGNORED paths, since no scenario reads it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Add requirements.yml, a Kamino-owned file with exact pins for the collections the
roles call (community.general 14.0.0, ansible.posix 2.2.2), and install it into
/opt/collections of the ci image (#118). Lint sets ANSIBLE_COLLECTIONS_PATH to it,
so ansible-lint --offline resolves the modules and mock_modules is dropped. The file
joins /opt/ci-pins.sha256: a pull request that changes a pin installs the collections
for its own run, as it does for requirements-dev.txt. mock_roles stays (step 5 of #118).

The install scopes ANSIBLE_COLLECTIONS_PATH to its target: ansible-galaxy skips a
collection it finds elsewhere on the path as already installed, so the image would
otherwise miss any that the build host happens to have.

Image input: ci 0.2.15 -> 0.2.16 (one bump for this change and the ruff and
shellcheck hooks of #112, which are also baked into the image). requirements.yml
is added to the image.yml push paths so that a pin change rebuilds the image.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Enable Renovate's ansible-galaxy manager for requirements.yml and let a bot pull
request change only the version: lines of that file (check_bot_pr_diff.py), so a
collection bump can automerge like the other pins while a changed name or source
still fails the gate (#118).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Molecule read /opt/molecule-collections, which the environment repository's
gitea_runner role installs from that repository's own requirements, so Kamino's
tests depended on pins Kamino does not own (#118). The job now installs
requirements.yml itself, into a directory named by the file's checksum on the
runner: a changed pin installs a new set, an unchanged one is reused, and the
install goes through a temporary directory so a cancelled run leaves no partial
set. requirements.yml is added to the push paths.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
dev-setup.sh installs requirements.yml into .ansible/collections of the clone and
exports ANSIBLE_HOME and ANSIBLE_COLLECTIONS_PATH from the hook scripts, so local
ansible-lint resolves the collection versions CI does and not the control host's
~/.ansible (#118, part of #80). The install scopes the path to its target so a
copy elsewhere is not skipped as already installed. A hook written by the previous
version gains only the new block.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
The image build ran only yamllint, gitleaks and actionlint on a staged sample, and a hook with
no matching file is skipped, so a missing ruff or shellcheck-py environment would not have
failed the build. Stage a .py and a .sh sample and run ruff-check, ruff-format and
shellcheck too (#112). Part of the unpublished ci 0.2.16, so no further version bump.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
ruff.toml described the older E/F default rule set, which ruff 0.17 widened. The ansible-lint hook now also runs when requirements.yml changes, so a pin bump in a partial commit is linted. The Renovate post-upgrade note names requirements.yml among the image inputs.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
fix(dev): run ansible-lint against the clone's pinned collections from any shell
Build / build (pull_request) Successful in 12s
Lint / lint (pull_request) Successful in 43s
Molecule / molecule (pull_request) Failing after 49s
bdb34cf98e
The hook scripts written by dev-setup.sh exported ANSIBLE_HOME and ANSIBLE_COLLECTIONS_PATH, so only a hook run through git commit saw the pinned collections; a bare pre-commit run fell back to the control host's ~/.ansible, the drift #118 removes. The ansible-lint hook now runs scripts/ansible-lint.sh, which uses .ansible/collections of the clone when ANSIBLE_COLLECTIONS_PATH is unset, fails with the fix when they are missing, and leaves a preset path (CI's /opt/collections) alone. dev-setup.sh keeps installing the collections and no longer edits the hook scripts beyond the PATH block it always wrote.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Defame1297 added 1 commit 2026-11-14 14:37:43 +00:00
fix(molecule): install community.docker for the Docker driver
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Successful in 43s
Molecule / molecule (pull_request) Successful in 6m19s
068bec93a9
Every scenario failed in its create step (couldn't resolve module community.docker.docker_login): molecule's Docker driver runs community.docker modules in its own create and destroy playbooks, and the collection came from the runner-provisioned /opt/molecule-collections that the previous commit stopped reading. The roles do not call it, so it is not in requirements.yml, which the ci image bakes for Lint and which Renovate would rebuild the image for. It is pinned in extensions/molecule/requirements.yml instead; the Molecule job installs both files, cached by their combined checksum. Renovate tracks the new file and the bot-diff gate allows only its version: lines.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG
Defame1297 merged commit 212dd7aea8 into main 2026-11-14 14:45:23 +00:00
Defame1297 deleted branch ci/ruff-shellcheck-and-baked-collections 2026-11-14 14:45:23 +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#121