diff options
Diffstat (limited to 'scripts/ci_expected_failures.py')
| -rw-r--r-- | scripts/ci_expected_failures.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/ci_expected_failures.py b/scripts/ci_expected_failures.py new file mode 100644 index 000000000..13dce177d --- /dev/null +++ b/scripts/ci_expected_failures.py | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | """Judge a CI test run that has known failures, each fixed by an open pull request. | ||
| 2 | |||
| 3 | python -I scripts/ci_expected_failures.py FAILED_LIST EXIT_STATUS [EXPECTED ...] | ||
| 4 | |||
| 5 | FAILED_LIST is a file with one failed test name per line, EXIT_STATUS the test runner's exit status, and each | ||
| 6 | EXPECTED argument one or more whitespace-separated test names (so a workflow can pass one quoted list). Exits 1 when a | ||
| 7 | test outside EXPECTED failed, or when the runner failed without naming a test (a crash, a build error). An expected | ||
| 8 | failure that passed gets a GitHub Actions notice, so the list in the workflow can shrink. | ||
| 9 | """ | ||
| 10 | |||
| 11 | import sys | ||
| 12 | |||
| 13 | |||
| 14 | def judge(failed: list[str], status: int, expected: list[str]) -> tuple[int, list[str]]: | ||
| 15 | """(exit status, GitHub Actions workflow commands to print).""" | ||
| 16 | unexpected = [name for name in failed if name not in expected] | ||
| 17 | lines = [f"::error::{name} failed" for name in unexpected] | ||
| 18 | if status != 0 and not failed: | ||
| 19 | lines.append(f"::error::the test runner exited with {status} without naming a failed test") | ||
| 20 | for name in expected: | ||
| 21 | if name in failed: | ||
| 22 | lines.append(f"::warning::{name} failed, as expected until its fix is merged") | ||
| 23 | else: | ||
| 24 | lines.append(f"::notice::{name} passed: drop it from the expected failures") | ||
| 25 | return (1 if unexpected or (status != 0 and not failed) else 0), lines | ||
| 26 | |||
| 27 | |||
| 28 | def main(argv: list[str]) -> int: | ||
| 29 | if len(argv) < 2: | ||
| 30 | print(__doc__.strip(), file=sys.stderr) | ||
| 31 | return 2 | ||
| 32 | with open(argv[0], encoding="utf-8") as f: | ||
| 33 | failed = [line.strip() for line in f if line.strip()] | ||
| 34 | expected = [name for arg in argv[2:] for name in arg.split()] | ||
| 35 | code, lines = judge(failed, int(argv[1]), expected) | ||
| 36 | print("\n".join(lines)) | ||
| 37 | return code | ||
| 38 | |||
| 39 | |||
| 40 | if __name__ == "__main__": | ||
| 41 | sys.exit(main(sys.argv[1:])) | ||