pr / done (pull_request) Successful in 1m51s
verify.sh --on <호스트>는 단계를 돌린 뒤 새 worktree의 JUnit XML을
읽어 합계 한 줄만 로그에 쓰고, trap이 worktree와 XML을 지운다. Gradle
--console=plain 로그에는 성공한 시험의 수도 클래스도 없어, 표준
진입점으로 돌리면 「고친 시험이 그 lane에서 돌았다」를 남길 곳이 없다.
requires lane은 빌드가 단언하지만 tag lane과 기본 test는 비어 있고,
세션마다 XML을 손으로 복사해 왔다.
합계를 새 scripts/junit-summary.py로 옮기고, 같은 스크립트가 XML마다
leaf·태스크·클래스·숫자 한 줄을 ~/<로그 이름>-logs/<단계>-classes.tsv에
남긴다. 단계 전에 지난 목록을 지워, 단계가 합계 전에 끊겨도 옛 목록이
새 로그 옆에 남지 않는다. 합계 줄은 전 awk와 같은 꼴이고, 읽는 범위도
전 find와 같다(build/test-results/ 아래 TEST-*.xml). 다른 점: 루트
testsuite만 세서 시험이 찍은 "<testsuite " 글자를 더 세지 않고, 열지
못하거나 끝까지 읽지 못하거나 숫자가 아닌 XML은 stderr에 이름을 찍고
뺀다. rc는 전처럼 단계의 rc다. 버린 안: heredoc 안 셸로 목록 만들기
(이스케이프가 겹쳐 시험하기 어렵다), XML 폴더 통째 복사(pr 단계 약
1천 개가 실행마다 쌓인다). gates.md 4절·operate.md의 손 복사 절차는
--on here나 손으로 돌린 worktree일 때만으로 좁히고, 같은 절차를 말하던
docs/work/README.md와 스킬 셋(be-testing·be-build-ci·desktop-gates)의
한 줄도 맞춘다.
위험: 원격 worktree에 python3이 있어야 한다(desktop 3.12.3). 합계
스크립트가 죽어도 단계 rc는 바뀌지 않는다. 캐시에서 되살린 태스크의
XML도 목록에 줄이 되므로 「돌았다」의 증거는 --no-cache 실행의 목록만
쓴다고 gates.md에 적었다. 잠금·정리·트리 비교·rc 처리·workflow는
그대로다.
검증(트리 fb7606c4): scripts 시험 전체 332개 통과, 새 시험 9개는 base
트리에서 모두 실패(rc=1). 변이 9개를 모두 시험이 잡는다. desktop
scripts/verify.sh pr --no-cache rc=0(tests=7353, 목록 1059줄, TSV 합
7353), leaf :adapter:inbound:grpc rc=0(tests=85, TSV 합 85,
GrpcP1BoundaryWireTest 줄), docs rc=0.
Refs: CI-BE-0006
80 lines
3.5 KiB
Python
Executable File
80 lines
3.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Totals the JUnit XML under a tree and lists, per lane, the test classes that ran.
|
|
|
|
Called by scripts/verify.sh: the script run_remote sends to the host calls it in the throwaway worktree
|
|
after the stage, before the worktree and its XML are removed. Run on a tree of your own the same way:
|
|
|
|
python3 scripts/junit-summary.py <root> [--classes <out.tsv>]
|
|
|
|
It reads the files the former find read: TEST-*.xml anywhere below a build/test-results/ folder. stdout
|
|
gets the total line in the form verify.sh always printed,
|
|
|
|
verify: 테스트 tests=N failures=N errors=N skipped=N
|
|
|
|
and, with --classes, one TSV row per file (leaf path, task, class, tests, skipped, failures, errors, time;
|
|
the root project's leaf is ".") and a line naming the file. Only the root testsuite counts, so a test that
|
|
prints "<testsuite " is not a second suite. A file that cannot be opened, does not parse to the end or whose
|
|
counts are not numbers is named on stderr and left out of both. A row says a result file was there, not that
|
|
the test ran in this build: a task restored FROM-CACHE puts its XML back too. The exit stays 0 either way: the stage's rc is what
|
|
verify.sh reports, and this script only describes the run.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
import xml.etree.ElementTree as ET
|
|
from pathlib import Path
|
|
|
|
RESULTS = "/build/test-results/"
|
|
COUNTS = ("tests", "skipped", "failures", "errors")
|
|
|
|
|
|
def result_files(root: Path) -> list[str]:
|
|
"""Paths relative to root, sorted, of every TEST-*.xml below a build/test-results/ folder."""
|
|
found = []
|
|
for directory, _, files in os.walk(root): # like find: symlinked folders are not followed
|
|
relative = os.path.relpath(directory, root)
|
|
for name in files:
|
|
path = name if relative == "." else f"{relative}/{name}"
|
|
if name.startswith("TEST-") and name.endswith(".xml") and RESULTS in f"/{path}":
|
|
found.append(path)
|
|
return sorted(found)
|
|
|
|
|
|
def read(root: Path, path: str) -> list[str] | None:
|
|
"""The TSV fields of one result file, or None when it cannot be read."""
|
|
try:
|
|
suite = ET.parse(root / path).getroot() # parses to the end: a file cut off after the root fails here
|
|
counts = [int(suite.get(key, "0")) for key in COUNTS]
|
|
except (OSError, ET.ParseError, ValueError):
|
|
return None
|
|
leaf, _, rest = f"/{path}".partition(RESULTS)
|
|
return [leaf.lstrip("/") or ".", rest.split("/", 1)[0], suite.get("name", ""), *map(str, counts),
|
|
suite.get("time", "")]
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument("root", type=Path)
|
|
parser.add_argument("--classes", type=Path, help="write one TSV row per result file here")
|
|
args = parser.parse_args(argv)
|
|
rows = []
|
|
for path in result_files(args.root):
|
|
fields = read(args.root, path)
|
|
if fields is None:
|
|
print(f"verify: 읽지 못한 XML {path}", file=sys.stderr)
|
|
else:
|
|
rows.append(fields)
|
|
total = {key: sum(int(row[3 + i]) for row in rows) for i, key in enumerate(COUNTS)}
|
|
print("verify: 테스트 tests={tests} failures={failures} errors={errors} skipped={skipped}".format(**total))
|
|
if args.classes:
|
|
args.classes.write_text("".join("\t".join(row) + "\n" for row in rows), encoding="utf-8")
|
|
print(f"verify: 클래스 목록 {len(rows)}줄 → {args.classes}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|