From 12fe748bdd47dafc8c12aff618c2bbcc81a3f40e Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 14 Nov 2026 13:52:03 +0000 Subject: [PATCH] ci(molecule): install the pinned collections from requirements.yml 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 Claude-Session: https://claude.ai/code/session_014uGZTNmHMc85bomfevwUDG --- .gitea/workflows/molecule.yml | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index e052fd5..a9d3074 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -18,8 +18,9 @@ name: Molecule # operator decides otherwise; the real condition is that only trusted people can push # branches or open pull requests here. # -# Tooling is provisioned on the runner by the gitea_runner role (molecule venv and the -# collections the roles use); this job installs nothing. The test image is pulled from +# The molecule venv is provisioned on the runner by the gitea_runner role. The collections +# the roles use are this repository's own pins (requirements.yml, the file the ci image bakes +# for Lint): the job installs them, cached on the runner by the file's checksum. The test image is pulled from # the registry by tag and digest (the digest is what is enforced). Bump both here when # image.yml publishes a new molecule-ubuntu2404 or molecule-ubuntu2604 version. on: # yamllint disable-line rule:truthy @@ -35,6 +36,7 @@ on: # yamllint disable-line rule:truthy - 'plugins/**' - 'meta/**' - 'galaxy.yml' + - 'requirements.yml' - '.gitea/workflows/molecule.yml' # Every scenario, nightly: a pull request runs only the scenarios of the roles it changes, so # drift in the others (a package mirror, the runner's molecule venv) would otherwise wait for @@ -70,7 +72,6 @@ jobs: timeout-minutes: 30 env: MOLECULE_VENV: /opt/molecule-venv - MOLECULE_COLLECTIONS: /opt/molecule-collections # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # one locally. MOLECULE_IMAGE: >- @@ -80,8 +81,8 @@ jobs: MOLECULE_IMAGE_2604: >- git.rkdr.net/mortis/molecule-ubuntu2604:0.1.3@sha256:7a90a9ff1819e99be17b28decff273f4f6405470a302c0fe961a61427e72bad6 steps: - # Provisioned by the gitea_runner role (install_services); fail with a clear - # message when this runs before it has. + # The molecule venv is provisioned by the gitea_runner role (install_services); fail with + # a clear message when this runs before it has. - name: Check the provisioned tooling run: | if ! test -x "$MOLECULE_VENV/bin/molecule"; then @@ -108,6 +109,27 @@ jobs: git checkout "$SHA" || { git fetch origin "$REF" && git checkout "$SHA"; } echo "Checked out $(git rev-parse HEAD)" + # The collections of requirements.yml, exactly as pinned. They are installed into a temporary + # directory and renamed into place, so a cancelled run never leaves a half-installed set, and + # the directory is named by the file's checksum, so a changed pin installs a new set and an + # unchanged one is reused. ANSIBLE_COLLECTIONS_PATH is set to the target for the install: + # a copy found elsewhere (the runner user's ~/.ansible) would be skipped as already installed. + - name: Install the pinned collections + working-directory: ac/ansible_collections/mortis/kamino + run: | + export PATH="$MOLECULE_VENV/bin:$PATH" + sum="$(sha256sum requirements.yml | cut -c1-16)" + dest="${XDG_CACHE_HOME:-$HOME/.cache}/kamino-collections/$sum" + if [ ! -d "$dest/ansible_collections" ]; then + mkdir -p "$(dirname "$dest")" + tmp="$(mktemp -d "$dest.XXXXXX")" + ANSIBLE_COLLECTIONS_PATH="$tmp" ansible-galaxy collection install -r requirements.yml -p "$tmp" + rm -rf "$dest" + mv -T "$tmp" "$dest" + fi + ANSIBLE_COLLECTIONS_PATH="$dest" ansible-galaxy collection list + echo "KAMINO_COLLECTIONS=$dest" >> "$GITHUB_ENV" + # A pull request runs only the scenarios of the roles it changes (scripts/select_molecule_scenarios.py # explains the rules); a push to main and a manual dispatch run all of them. # molecule test destroys its instance on success and on failure; a cancelled run is killed @@ -129,14 +151,14 @@ jobs: fi # molecule calls ansible-config and ansible-playbook by name export PATH="$MOLECULE_VENV/bin:$PATH" - # The collection under test first, then what the roles use. molecule also + # The collection under test first, then the pinned collections the roles use. molecule also # installs the collection under test into ANSIBLE_HOME; keep that inside the # job tree so no run resolves a copy another run left in the runner user's # home (the version stays 0.1.0, so a stale copy would look current). The rm # clears a copy left there by runs before this was set. ac_root="$(cd ../../.. && pwd)" export ANSIBLE_HOME="$ac_root/.ansible" - export ANSIBLE_COLLECTIONS_PATH="$ac_root:$MOLECULE_COLLECTIONS" + export ANSIBLE_COLLECTIONS_PATH="$ac_root:$KAMINO_COLLECTIONS" rm -rf "$HOME/.ansible/collections/ansible_collections/mortis" # The selector comes from the base branch, so a pull request cannot edit the rules it is # judged by (lint.yml does the same for check_bot_pr_diff.py); the first pull request that