ci(molecule): select by image pin for a molecule.yml change of only pins or comments #439

Merged
Defame1297 merged 2 commits from ci/selector-narrow-pins into main 2026-11-27 16:08:47 +00:00
Owner

What and why

Closes #428

A change to .gitea/workflows/molecule.yml selected every scenario, so a molecule image pin bump (a Renovate pull request) or a comment edit took the runner for a full run. scripts/select_molecule_scenarios.py now compares the merge-base and HEAD copies of that workflow:

  • # and blank lines outside a block scalar are dropped; inside one (a run: | script, where a # line may be heredoc content) they are content, so changing them is not narrowed;
  • the line right after CI_IMAGE: >-, MOLECULE_IMAGE: >- or MOLECULE_IMAGE_2604: >- must be the value, indented deeper than its key and in the shape Renovate writes (git.rkdr.net/mortis/<name>:<tag>@sha256:<64 hex>) in both copies; otherwise nothing is narrowed;
  • only comments changed: nothing is selected for it;
  • MOLECULE_IMAGE and/or MOLECULE_IMAGE_2604 changed: every scenario with a file naming that variable (word match, so MOLECULE_IMAGE does not match _2604); every scenario when a shared molecule file (.config/molecule/**, non-scenario files under extensions/molecule/ or roles/*/molecule/) names it, or a file cannot be read or is a symlink;
  • CI_IMAGE changed (the tools molecule runs with), anything else differs, or git fails: every scenario, as before.

What this gains, honestly: the main saving is comment-only edits outside run: scripts, which now select no scenario. Image pin bumps gain little today: most scenarios name both images, so a MOLECULE_IMAGE bump selects 18 of 19 scenarios (all but image-smoke-2604) and a MOLECULE_IMAGE_2604 bump 16 of 19 (all but image-smoke, network_interfaces and pve_lxc), on both platforms. Running only the platforms of the changed image is left for a follow-up.

Ruled out (code-style.md rule 1, existing tool first): a YAML parser. The selector runs as python3 -I on the host (.gitea/workflows/molecule.yml, "Run the scenarios"), and on the host-executor label the host "only clones the checkout and runs stdlib Python" (roles/gitea_runner/tasks/molecule.yml), so there is no PyYAML to rely on. The selector compares lines instead and fails closed on any shape it does not expect. No path filter or Renovate setting can tell a pin line from other lines of the same file, so the check lives in the selector that already decides the selection.

The script grows to 450 lines, over the 200-line soft limit in docs/contributing/code-style.md ("a script or workflow over 200 lines ... Above one, the pull request says why; nothing fails"). It stays one file: it is still one job (choosing scenarios), rule 2 says "do not split a file only for its length", and the Molecule workflow copies only this file from origin/main, so a helper module would be read from the pull request's copy and let a pull request change the rules it is judged by. reason_for() is split out of select() to keep it under ruff's complexity limit.

The selector's docstring and the Molecule rule in .gitea/workflows/AGENTS.md describe the new case.

This pull request is judged by main's copy of the selector, so it runs every scenario itself.

Verified

  • python3 -m unittest discover -s tests/scripts: OK. New tests cover pin detection, a comment inside a pin's value, a value line replaced or reshaped, a # line inside a run: | block, shared molecule files, an unreadable scenario, a symlinked directory, and the end-to-end main() path.
  • pre-commit run --files on the changed files and the commit hooks: gitleaks, ruff check, ruff format, REUSE, Conventional Commit and the Assisted-by trailer check pass; ansible-test sanity (pre-push) passed.
  • Replay of the last 60 merges on main, each against its first parent, old vs new selector with EVENT_NAME=pull_request: 56 unchanged, 4 narrowed, all expected:
    • #384 and #344 (molecule-ubuntu2604 pin): 17 and 16 to 1 (image-smoke-2604). These are from before the roles named the 26.04 image; the same bump selects 16 of 19 today.
    • #343 (molecule-ubuntu2404 pin): 16 to 15 (all but image-smoke-2604).
    • #362 (comment-only molecule.yml edit plus ignored docs): 16 to 0.
    • Every CI_IMAGE bump and every other molecule.yml change selects the same as before.
  • Two adversarial review rounds by a separate agent, trying to make the selector under-select (comments inside pin values, block-scalar edges, CRLF, tabs, line separators, duplicated keys, symlinks); every case fails closed or selects correctly.

Not verified

  • Molecule was not run locally (molecule runs only in CI); the narrowed selections are first exercised by the next comment-only or image pin pull request after merge.
  • That the runner host has no YAML parser is taken from roles/gitea_runner/tasks/molecule.yml, not checked on the runner.
  • The new selector does not judge this pull request: the workflow runs main's copy.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Closes #428 A change to `.gitea/workflows/molecule.yml` selected every scenario, so a molecule image pin bump (a Renovate pull request) or a comment edit took the runner for a full run. `scripts/select_molecule_scenarios.py` now compares the merge-base and HEAD copies of that workflow: - `#` and blank lines outside a block scalar are dropped; inside one (a `run: |` script, where a `#` line may be heredoc content) they are content, so changing them is not narrowed; - the line right after `CI_IMAGE: >-`, `MOLECULE_IMAGE: >-` or `MOLECULE_IMAGE_2604: >-` must be the value, indented deeper than its key and in the shape Renovate writes (`git.rkdr.net/mortis/<name>:<tag>@sha256:<64 hex>`) in both copies; otherwise nothing is narrowed; - only comments changed: nothing is selected for it; - `MOLECULE_IMAGE` and/or `MOLECULE_IMAGE_2604` changed: every scenario with a file naming that variable (word match, so `MOLECULE_IMAGE` does not match `_2604`); every scenario when a shared molecule file (`.config/molecule/**`, non-scenario files under `extensions/molecule/` or `roles/*/molecule/`) names it, or a file cannot be read or is a symlink; - `CI_IMAGE` changed (the tools molecule runs with), anything else differs, or git fails: every scenario, as before. What this gains, honestly: the main saving is comment-only edits outside `run:` scripts, which now select no scenario. Image pin bumps gain little today: most scenarios name both images, so a `MOLECULE_IMAGE` bump selects 18 of 19 scenarios (all but image-smoke-2604) and a `MOLECULE_IMAGE_2604` bump 16 of 19 (all but image-smoke, network_interfaces and pve_lxc), on both platforms. Running only the platforms of the changed image is left for a follow-up. Ruled out (code-style.md rule 1, existing tool first): a YAML parser. The selector runs as `python3 -I` on the host (`.gitea/workflows/molecule.yml`, "Run the scenarios"), and on the host-executor label the host "only clones the checkout and runs stdlib Python" (`roles/gitea_runner/tasks/molecule.yml`), so there is no PyYAML to rely on. The selector compares lines instead and fails closed on any shape it does not expect. No path filter or Renovate setting can tell a pin line from other lines of the same file, so the check lives in the selector that already decides the selection. The script grows to 450 lines, over the 200-line soft limit in `docs/contributing/code-style.md` ("a script or workflow over 200 lines ... Above one, the pull request says why; nothing fails"). It stays one file: it is still one job (choosing scenarios), rule 2 says "do not split a file only for its length", and the Molecule workflow copies only this file from `origin/main`, so a helper module would be read from the pull request's copy and let a pull request change the rules it is judged by. `reason_for()` is split out of `select()` to keep it under ruff's complexity limit. The selector's docstring and the Molecule rule in `.gitea/workflows/AGENTS.md` describe the new case. This pull request is judged by `main`'s copy of the selector, so it runs every scenario itself. ## Verified - `python3 -m unittest discover -s tests/scripts`: OK. New tests cover pin detection, a comment inside a pin's value, a value line replaced or reshaped, a `#` line inside a `run: |` block, shared molecule files, an unreadable scenario, a symlinked directory, and the end-to-end `main()` path. - `pre-commit run --files` on the changed files and the commit hooks: gitleaks, ruff check, ruff format, REUSE, Conventional Commit and the Assisted-by trailer check pass; `ansible-test sanity` (pre-push) passed. - Replay of the last 60 merges on `main`, each against its first parent, old vs new selector with `EVENT_NAME=pull_request`: 56 unchanged, 4 narrowed, all expected: - #384 and #344 (molecule-ubuntu2604 pin): 17 and 16 to 1 (image-smoke-2604). These are from before the roles named the 26.04 image; the same bump selects 16 of 19 today. - #343 (molecule-ubuntu2404 pin): 16 to 15 (all but image-smoke-2604). - #362 (comment-only molecule.yml edit plus ignored docs): 16 to 0. - Every `CI_IMAGE` bump and every other molecule.yml change selects the same as before. - Two adversarial review rounds by a separate agent, trying to make the selector under-select (comments inside pin values, block-scalar edges, CRLF, tabs, line separators, duplicated keys, symlinks); every case fails closed or selects correctly. ## Not verified - Molecule was not run locally (molecule runs only in CI); the narrowed selections are first exercised by the next comment-only or image pin pull request after merge. - That the runner host has no YAML parser is taken from `roles/gitea_runner/tasks/molecule.yml`, not checked on the runner. - The new selector does not judge this pull request: the workflow runs `main`'s copy. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Claude added 1 commit 2026-11-27 14:44:27 +00:00
ci(molecule): select by image pin for a molecule.yml change of only pins or comments
Build / build (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 1m59s
Molecule / molecule (pull_request) Successful in 1m37s
6eca2f4031
A change to .gitea/workflows/molecule.yml selected every scenario, so a
molecule image pin bump or a comment edit ran the full set. The selector
now compares the merge-base and HEAD copies of the workflow:

- `#` and blank lines outside a block scalar are dropped; inside one
  (a `run: |` script, where they may be heredoc content) they count;
- the line after each CI_IMAGE, MOLECULE_IMAGE and MOLECULE_IMAGE_2604
  `>-` key must be its value, deeper than the key and in the shape
  Renovate writes, in both copies;
- comments only select nothing; a MOLECULE_IMAGE* pin selects every
  scenario with a file naming it, or every scenario when a shared
  molecule file names it or a file is unreadable or a symlink;
- CI_IMAGE, any other difference or a git error selects everything.

reason_for() is split out of select() to stay under ruff's complexity
limit. The Molecule rule in .gitea/workflows/AGENTS.md describes the
new case.

Assisted-by: Claude Code:claude-opus-5-5
CODEOWNERS rules requested review from Defame1297 2026-11-27 14:44:28 +00:00
Defame1297 added 1 commit 2026-11-27 16:07:05 +00:00
Merge branch 'main' into ci/selector-narrow-pins
Build / build (pull_request) Successful in 28s
Molecule / molecule (pull_request) Successful in 5s
Lint / lint (pull_request) Successful in 1m33s
7df98ea8c7
Defame1297 approved these changes 2026-11-27 16:07:38 +00:00
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-11-27 16:07:41 +00:00
Defame1297 merged commit 48e6dcb543 into main 2026-11-27 16:08:47 +00:00
Defame1297 deleted branch ci/selector-narrow-pins 2026-11-27 16:08:50 +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#439