Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

1.5 KB
Raw Blame
"""Classify completed release pytest lanes using their exit outcomes and JUnit reports."""

import os
import xml.etree.ElementTree as ET
from pathlib import Path


def release_result():
    failed = False
    for outcome, path in (
        ("IDENTITY_RESULT", "pytest-identities.xml"),
        ("CATALOG_RESULT", "pytest-catalog.xml"),
        ("SUITE_RESULT", "pytest-junit.xml"),
    ):
        cases = ET.parse(path).findall(".//testcase")
        if not any(case.find("skipped") is None for case in cases):
            raise ValueError(f"{path} contains no executed tests")
        if any(case.find("error") is not None for case in cases):
            raise ValueError(f"{path} contains a test setup, collection or teardown error")
        assertions_failed = any(case.find("failure") is not None for case in cases)
        expected = "failure" if assertions_failed else "success"
        # make returns 2 for every failed recipe. Only pytest exit 1 means completed, failing tests.
        exit_code = Path(path).with_suffix(".exitcode").read_text().strip()
        if exit_code != ("1" if assertions_failed else "0") or os.environ[outcome] != expected:
            raise ValueError(f"{path} does not explain the {os.environ[outcome]} step outcome")
        failed |= assertions_failed
    return "failure" if failed else "success"


if __name__ == "__main__":
    with Path(os.environ["GITHUB_OUTPUT"]).open("a") as output:
        print(f"result={release_result()}", file=output)