diff --git a/.github/workflows/cron-collection-source.yml b/.github/workflows/cron-collection-source.yml index 9d0f374db5..50dc753b10 100644 --- a/.github/workflows/cron-collection-source.yml +++ b/.github/workflows/cron-collection-source.yml @@ -1,4 +1,4 @@ -name: "⚖️ Benchmark collection sources" +name: "⚖️ Source benchmark" run-name: "${{ github.event_name == 'schedule' && '⏰ ' || '' }}⚖️ Benchmark collection sources" on: diff --git a/cli/contributing/update/collection_source/__main__.py b/cli/contributing/update/collection_source/__main__.py index ba5ed513bf..2a7342ad92 100755 --- a/cli/contributing/update/collection_source/__main__.py +++ b/cli/contributing/update/collection_source/__main__.py @@ -35,7 +35,9 @@ def read_preferred(env_file: Path) -> str: env_file: the default.env holding the setting. """ match = re.search( - rf"^{SETTING}=(\S+)\s*$", env_file.read_text(encoding="utf-8"), re.MULTILINE + rf"^{SETTING}=(\S+)\s*$", + env_file.read_text(encoding="utf-8"), # nocheck: cache-read -- write_preferred rewrites this file in the same run + re.MULTILINE, ) if match is None: raise SystemExit(f"{SETTING} is not declared in {env_file}") @@ -49,7 +51,7 @@ def write_preferred(env_file: Path, source: str) -> None: env_file: the default.env holding the setting. source: the source to try first from now on. """ - text = env_file.read_text(encoding="utf-8") + text = env_file.read_text(encoding="utf-8") # nocheck: cache-read -- rewritten on the next line env_file.write_text( re.sub(rf"^{SETTING}=\S+$", f"{SETTING}={source}", text, flags=re.MULTILINE), encoding="utf-8", diff --git a/scripts/github/update/restore_collection_history.sh b/scripts/github/update/restore_collection_history.sh old mode 100644 new mode 100755 diff --git a/scripts/install/ansible.sh b/scripts/install/ansible.sh index 3f0152a001..6f5ce14ed8 100755 --- a/scripts/install/ansible.sh +++ b/scripts/install/ansible.sh @@ -25,7 +25,9 @@ if [[ -z "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE:-}" ]]; then source <(grep -E '^INFINITO_ANSIBLE_COLLECTIONS_SOURCE=' default.env) fi -case "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE:-galaxy}" in +: "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE:?not declared in default.env}" + +case "${INFINITO_ANSIBLE_COLLECTIONS_SOURCE}" in galaxy) SOURCE_ORDER=("Galaxy:${GALAXY_REQ}" "Git:${GIT_REQ}") ;; git) SOURCE_ORDER=("Git:${GIT_REQ}" "Galaxy:${GALAXY_REQ}") ;; *) diff --git a/tests/unit/python/utils/update/test_galaxy.py b/tests/unit/python/utils/update/test_galaxy.py index 3d977818cc..06f7a2789f 100644 --- a/tests/unit/python/utils/update/test_galaxy.py +++ b/tests/unit/python/utils/update/test_galaxy.py @@ -27,6 +27,11 @@ collections: """ +def _read(root: Path, name: str) -> str: + # nocheck: cache-read -- apply_updates rewrote this file inside the same test + return (root / "requirements" / name).read_text(encoding="utf-8") + + def _repo(root: Path) -> Path: (root / "requirements").mkdir() (root / "requirements" / "requirements.galaxy.yml").write_text( @@ -98,12 +103,8 @@ class TestApplyUpdates(unittest.TestCase): changed = apply_updates(root, updates) self.assertEqual(len(changed), 2) - galaxy_text = (root / "requirements" / "requirements.galaxy.yml").read_text( - encoding="utf-8" - ) - git_text = (root / "requirements" / "requirements.git.yml").read_text( - encoding="utf-8" - ) + galaxy_text = _read(root, "requirements.galaxy.yml") + git_text = _read(root, "requirements.git.yml") self.assertIn("version: 13.4.0", galaxy_text) self.assertIn("version: 13.4.0", git_text) self.assertNotIn("13.2.0", galaxy_text) @@ -118,16 +119,8 @@ class TestApplyUpdates(unittest.TestCase): ): apply_updates(root, find_outdated_updates(root)) - git_text = (root / "requirements" / "requirements.git.yml").read_text( - encoding="utf-8" - ) - self.assertIn("version: master", git_text) - self.assertIn( - "version: 0.13.0", - (root / "requirements" / "requirements.galaxy.yml").read_text( - encoding="utf-8" - ), - ) + self.assertIn("version: master", _read(root, "requirements.git.yml")) + self.assertIn("version: 0.13.0", _read(root, "requirements.galaxy.yml")) if __name__ == "__main__": diff --git a/utils/env/handlers/passthrough.py b/utils/env/handlers/passthrough.py index f054fda41c..8d563d5875 100644 --- a/utils/env/handlers/passthrough.py +++ b/utils/env/handlers/passthrough.py @@ -12,6 +12,7 @@ if TYPE_CHECKING: STATIC_KEYS = ( "INFINITO_SRC_DIR", "INFINITO_VENV_DIR", + "INFINITO_ANSIBLE_COLLECTIONS_SOURCE", "INFINITO_BIND_IP", "INFINITO_BUILD", "INFINITO_SUBNET", diff --git a/utils/update/collection_source.py b/utils/update/collection_source.py index 1e28db2c9e..eee2819253 100644 --- a/utils/update/collection_source.py +++ b/utils/update/collection_source.py @@ -57,7 +57,7 @@ def load_history(path: Path) -> list[dict[str, float | None]]: path: JSON file holding the rolling window. """ try: - payload = json.loads(path.read_text(encoding="utf-8")) + payload = json.loads(path.read_text(encoding="utf-8")) # nocheck: cache-read -- the history file is rewritten every run, a cached copy would go stale except (OSError, ValueError): return [] return payload if isinstance(payload, list) else [] diff --git a/utils/update/galaxy.py b/utils/update/galaxy.py index b06a7714ae..5473a2c3c1 100644 --- a/utils/update/galaxy.py +++ b/utils/update/galaxy.py @@ -20,8 +20,7 @@ import re from dataclasses import dataclass from pathlib import Path -import yaml - +from utils.cache.yaml import load_yaml_any from utils.update.base import is_semver, version_key from utils.update.repository import git_ls_remote_tags @@ -51,7 +50,7 @@ class CollectionPinUpdate: def _entries(path: Path) -> list[dict]: - declared = yaml.safe_load(path.read_text(encoding="utf-8")) or {} + declared = load_yaml_any(str(path), default_if_missing={}) or {} return [e for e in (declared.get("collections") or []) if isinstance(e, dict)] @@ -108,7 +107,7 @@ def find_outdated_updates(repo_root: Path) -> list[CollectionPinUpdate]: def _rewrite(path: Path, fqcn: str, old: str, new: str) -> bool: - text = path.read_text(encoding="utf-8") + text = path.read_text(encoding="utf-8") # nocheck: cache-read -- rewritten below, a cached copy would go stale mid-run pattern = re.compile( rf"(name:\s*{re.escape(fqcn)}\b(?:\n(?!\s*-\s).*)*?\n\s*version:\s*){re.escape(old)}\b" )