GuestOps asible playbook

This commit is contained in:
2026-10-21 11:55:33 +01:00
parent c5c6ec1453
commit db8422afda
61 changed files with 108 additions and 4417 deletions
+8 -28
View File
@@ -5,7 +5,6 @@ from __future__ import annotations
import argparse
import gzip
import hashlib
import io
import json
from pathlib import Path
@@ -44,11 +43,7 @@ def versions(repository: Path, commit: str) -> tuple[str, str]:
return dotnet_version, web_version
def sha256_bytes(value: bytes) -> str:
return hashlib.sha256(value).hexdigest()
def build_package(repository: Path, ref: str, output_directory: Path) -> tuple[Path, Path, dict[str, object]]:
def build_package(repository: Path, ref: str, output_directory: Path) -> tuple[Path, dict[str, str]]:
repository = repository.resolve()
output_directory = output_directory.resolve()
if not (repository / ".git").exists():
@@ -66,7 +61,7 @@ def build_package(repository: Path, ref: str, output_directory: Path) -> tuple[P
if SEMVER.fullmatch(dotnet_version) is None:
raise ValueError("The committed version must use MAJOR.MINOR.PATCH.")
prefix = f"GuestOps-{dotnet_version}/"
prefix = f"guestops_{dotnet_version}/"
tar_bytes = bytes(
git(
repository,
@@ -82,28 +77,13 @@ def build_package(repository: Path, ref: str, output_directory: Path) -> tuple[P
stream.write(tar_bytes)
archive_bytes = compressed.getvalue()
stem = f"GuestOps-{dotnet_version}-{commit[:12]}"
archive = output_directory / f"{stem}.tar.gz"
record_path = output_directory / f"{stem}.source.json"
if archive.exists() or record_path.exists():
raise ValueError("The output package or source record already exists; releases are not overwritten.")
archive = output_directory / f"guestops_{dotnet_version}.tar.gz"
if archive.exists():
raise ValueError("The output package already exists; published versions are not overwritten.")
output_directory.mkdir(parents=True, exist_ok=True)
archive.write_bytes(archive_bytes)
record: dict[str, object] = {
"artifact": {
"name": archive.name,
"sha256": sha256_bytes(archive_bytes),
"size": len(archive_bytes),
},
"commit": commit,
"schemaVersion": 1,
"version": dotnet_version,
}
record_path.write_text(
json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8"
)
return archive, record_path, record
return archive, {"commit": commit, "version": dotnet_version}
def main() -> None:
@@ -113,11 +93,11 @@ def main() -> None:
parser.add_argument("--output-directory", required=True, type=Path)
args = parser.parse_args()
try:
archive, record, details = build_package(args.repository, args.ref, args.output_directory)
archive, details = build_package(args.repository, args.ref, args.output_directory)
except (OSError, ValueError, ET.ParseError, json.JSONDecodeError, subprocess.SubprocessError) as error:
print(f"Source packaging failed: {error}", file=sys.stderr)
raise SystemExit(1)
print(json.dumps({"archive": str(archive), "record": str(record), **details}, indent=2))
print(json.dumps({"archive": str(archive), **details}, indent=2))
if __name__ == "__main__":