57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Parse meta/main.yml platforms and output a Docker test matrix as JSON."""
|
||
|
|
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
try:
|
||
|
|
import yaml
|
||
|
|
except ImportError:
|
||
|
|
print("ERROR: PyYAML is required. Install with: pip install pyyaml", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
# Mapping Galaxy platform name -> Docker image prefix
|
||
|
|
PLATFORM_IMAGE_MAP = {
|
||
|
|
"EL": "rockylinux",
|
||
|
|
"Debian": "debian",
|
||
|
|
"Ubuntu": "ubuntu",
|
||
|
|
}
|
||
|
|
|
||
|
|
def build_matrix(meta_path: str = "roles/remote_users_fact/meta/main.yml") -> list[dict]:
|
||
|
|
meta_file = Path(meta_path)
|
||
|
|
if not meta_file.exists():
|
||
|
|
print(f"ERROR: {meta_file} not found", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
with open(meta_file) as f:
|
||
|
|
meta = yaml.safe_load(f)
|
||
|
|
|
||
|
|
platforms = meta.get("galaxy_info", {}).get("platforms", [])
|
||
|
|
if not platforms:
|
||
|
|
print("ERROR: No platforms found in meta/main.yml", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
matrix = []
|
||
|
|
for platform in platforms:
|
||
|
|
name = platform["name"]
|
||
|
|
if name not in PLATFORM_IMAGE_MAP:
|
||
|
|
print(f"ERROR: Unknown platform '{name}'. Known: {list(PLATFORM_IMAGE_MAP.keys())}", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
image_prefix = PLATFORM_IMAGE_MAP[name]
|
||
|
|
for version in platform.get("versions", []):
|
||
|
|
version_str = str(version)
|
||
|
|
slug = f"{name.lower()}{version_str}" if name == "EL" else f"{name.lower()}-{version_str}"
|
||
|
|
matrix.append({
|
||
|
|
"slug": slug,
|
||
|
|
"image": f"{image_prefix}:{version_str}",
|
||
|
|
"platform": name,
|
||
|
|
"version": version_str,
|
||
|
|
})
|
||
|
|
|
||
|
|
return matrix
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print(json.dumps(build_matrix(), indent=2))
|