Files
marqdo-cli/tools/ci/annotate_workspace_tests.py
T
cflmy a24161c934
CI / schema instance validation + consumers (push) Waiting to run
CI / runtime contract (macos-latest) (push) Waiting to run
CI / runtime contract (windows-latest) (push) Waiting to run
Linux strict security lane (G-C) / strict isolation escape matrix (push) Waiting to run
CI / fmt + clippy + test (Linux x86_64) (push) Waiting to run
ci/woodpecker/push/woodpecker Pipeline was successful
fix(foreign): keep Windows temp paths non-verbatim
fs::canonicalize on Windows returns a \\?\C:\... path. Node's module loader
lstats the working/script path and rejects the verbatim form, so all Node
foreign-kernel tests failed on windows-latest. Use the native temp directory on
Windows and retain canonicalization on Unix for symlink safety; widen the CI
annotator so any remaining native failure shows a full assertion block.
2026-11-21 18:49:05 +08:00

67 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Emit GitHub check annotations from a cargo-test log.
Native jobs (Windows/macOS) and the Linux gate tee `cargo test --workspace` to
a file. Public check-run annotations are then the only failure detail visible
without repository-admin log access. ANSI colour codes are stripped first so
anchored patterns still match.
"""
import re
import sys
MAX_ANNOTATIONS = 60
ANSI = re.compile(r"\x1b\[[0-9;]*m")
def escape(text: str) -> str:
return text.replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
def interesting_lines(lines: list[str]) -> list[tuple[int, str]]:
selected: list[tuple[int, str]] = []
seen: set[int] = set()
def add(index: int) -> None:
if 0 <= index < len(lines) and index not in seen:
seen.add(index)
selected.append((index, lines[index]))
for index, line in enumerate(lines):
if "panicked at" in line:
for offset in range(-2, 19):
add(index + offset)
elif line.startswith("failures:"):
for offset in range(0, 8):
add(index + offset)
elif line.startswith("---- "):
for offset in range(0, 30):
add(index + offset)
elif re.match(r"^error(\[|:)", line):
for offset in range(-1, 7):
add(index + offset)
elif "test " in line and line.endswith("FAILED"):
add(index)
return sorted(selected)
def main(argv: list[str]) -> int:
if len(argv) < 2:
print("usage: annotate_workspace_tests.py <log> [title]", file=sys.stderr)
return 2
log = sys.argv[1]
title = sys.argv[2] if len(argv) > 2 else "Workspace tests"
try:
text = open(log, encoding="utf-8", errors="replace").read()
except OSError as error:
print(f"::error title={title}::cannot read test log: {error}")
return 0
lines = ANSI.sub("", text).splitlines()
for _, line in interesting_lines(lines)[:MAX_ANNOTATIONS]:
print(f"::error title={title}::{escape(line)}")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv))