Skip to content

Commit 4e5cdeb

Browse files
ci: port the test step to Python so it works in PowerShell
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
1 parent 60bef18 commit 4e5cdeb

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
# PowerShell, so the Windows job failed on the shell rather than on a
4949
# test. Runners print full output on failure, so no log scraping is
5050
# needed here.
51-
run: python -m unittest test.py test_poc_vulnerability.py -v
51+
run: python run_ci_tests.py

‎run_ci_tests.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Run the unit tests and surface failures as GitHub annotations.
2+
3+
Windows runners execute ``run:`` steps with PowerShell, so shell tricks for
4+
piping or scraping output are not portable. Doing it in Python keeps the
5+
workflow identical on every runner, and the ``::error`` lines land in the
6+
check-run annotations even when the raw job log cannot be retrieved.
7+
"""
8+
import io
9+
import sys
10+
import unittest
11+
12+
RESULT_FILE = "suite-output.txt"
13+
14+
15+
def main():
16+
sys.path.insert(0, ".")
17+
loader = unittest.TestLoader()
18+
suite = unittest.TestSuite([
19+
loader.loadTestsFromName("test"),
20+
loader.loadTestsFromName("test_poc_vulnerability"),
21+
])
22+
buffer = io.StringIO()
23+
runner = unittest.TextTestRunner(stream=buffer, verbosity=2)
24+
result = runner.run(suite)
25+
output = buffer.getvalue()
26+
print(output)
27+
28+
problems = [(str(test), traceback) for test, traceback in
29+
result.errors + result.failures]
30+
for name, traceback in problems:
31+
print(f"::error title={name}::{traceback.strip().splitlines()[-1][:200]}")
32+
33+
if problems:
34+
with open(RESULT_FILE, "w", encoding="utf-8") as handle:
35+
handle.write(output)
36+
return 1
37+
return 0
38+
39+
40+
if __name__ == "__main__":
41+
sys.exit(main())

0 commit comments

Comments
 (0)