diff options
| author | Almogaver295 <133548141+guimsolutions@users.noreply.github.com> | 2026-11-23 23:53:36 +0100 |
|---|---|---|
| committer | Almogaver295 <133548141+guimsolutions@users.noreply.github.com> | 2026-11-23 23:53:36 +0100 |
| commit | 33f4a5aedeb48e27b004efe5d6ae306130d55cdd (patch) | |
| tree | 08361685151a2a6a4ecf9156955fabb35b4b570c /scripts/ci_expected_failures.py | |
| parent | 57cb669f52ba6ca4bb58bf2e09492ffbe2b8ee60 (diff) | |
| parent | 5d74c272363f2703265d44e6aaab1a1df8ddfaf3 (diff) | |
Merge upstream main and preserve 1D UAV clear compatibilityold-pr/9948
Diffstat (limited to 'scripts/ci_expected_failures.py')
| -rw-r--r-- | scripts/ci_expected_failures.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/ci_expected_failures.py b/scripts/ci_expected_failures.py new file mode 100644 index 000000000..8112dcf4b --- /dev/null +++ b/scripts/ci_expected_failures.py | |||
| @@ -0,0 +1,62 @@ | |||
| 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, the runner failed without naming a test, or the runner was terminated by a signal | ||
| 8 | (its failure list can be incomplete); 2 on a usage error. `--help` prints this text. An expected failure absent | ||
| 9 | from a completed run gets a GitHub Actions notice so the list in the workflow can shrink. | ||
| 10 | """ | ||
| 11 | |||
| 12 | import sys | ||
| 13 | |||
| 14 | |||
| 15 | def judge(failed: list[str], status: int, expected: list[str]) -> tuple[int, list[str]]: | ||
| 16 | """(exit status, GitHub Actions workflow commands to print).""" | ||
| 17 | unexpected = [name for name in failed if name not in expected] | ||
| 18 | lines = [f"::error::{name} failed" for name in unexpected] | ||
| 19 | # subprocess reports a signal as -N; the shell pipelines in runtime.yml report it as 128+N. | ||
| 20 | if status < 0 or 128 < status <= 255: | ||
| 21 | lines.append(f"::error::abnormal test runner exit {status}; the failure list may be incomplete") | ||
| 22 | return 1, lines | ||
| 23 | if status != 0 and not failed: | ||
| 24 | lines.append(f"::error::the test runner exited with {status} without naming a failed test") | ||
| 25 | for name in expected: | ||
| 26 | if name in failed: | ||
| 27 | lines.append(f"::warning::{name} failed, as expected until its fix is merged") | ||
| 28 | else: | ||
| 29 | lines.append(f"::notice::{name} passed: drop it from the expected failures") | ||
| 30 | return (1 if unexpected or (status != 0 and not failed) else 0), lines | ||
| 31 | |||
| 32 | |||
| 33 | def main(argv: list[str]) -> int: | ||
| 34 | if argv and argv[0] in ("-h", "--help"): | ||
| 35 | print(__doc__.strip()) | ||
| 36 | return 0 | ||
| 37 | if len(argv) < 2: | ||
| 38 | print(__doc__.strip(), file=sys.stderr) | ||
| 39 | return 2 | ||
| 40 | try: | ||
| 41 | status = int(argv[1]) | ||
| 42 | except ValueError: | ||
| 43 | print(f"ci_expected_failures: EXIT_STATUS {argv[1]!r} is not an integer", file=sys.stderr) | ||
| 44 | return 2 | ||
| 45 | try: | ||
| 46 | with open(argv[0], encoding="utf-8") as f: | ||
| 47 | failed = [line.strip() for line in f if line.strip()] | ||
| 48 | except OSError as e: | ||
| 49 | print(f"ci_expected_failures: {argv[0]}: {e.strerror or e}", file=sys.stderr) | ||
| 50 | return 2 | ||
| 51 | expected = [name for arg in argv[2:] for name in arg.split()] | ||
| 52 | code, lines = judge(failed, status, expected) | ||
| 53 | print("\n".join(lines)) | ||
| 54 | return code | ||
| 55 | |||
| 56 | |||
| 57 | if __name__ == "__main__": | ||
| 58 | try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode | ||
| 59 | sys.stdout.reconfigure(errors="replace") | ||
| 60 | except (AttributeError, ValueError, OSError): | ||
| 61 | pass | ||
| 62 | sys.exit(main(sys.argv[1:])) | ||