|
12 | 12 | data = json.load(f)
|
13 | 13 | tests = sorted(data["stats"]["suite_details"], key=lambda x: x["name"])
|
14 | 14 |
|
| 15 | +# Get commit SHA from command line argument or environment variable |
| 16 | +commit_sha = None |
| 17 | +if len(sys.argv) < 2 or len(sys.argv) > 3: |
| 18 | + print("Usage: python table_generator.py <test_results.json> [commit_sha]") |
| 19 | + sys.exit(1) |
| 20 | +elif len(sys.argv) == 3: # Commit SHA is provided as argument |
| 21 | + commit_sha = sys.argv[2] |
| 22 | +elif "GITHUB_SHA" in os.environ: # Commit SHA is provided as environment variable |
| 23 | + commit_sha = os.environ["GITHUB_SHA"] |
| 24 | +else: # Commit SHA is not provided |
| 25 | + print("Commit SHA is not provided. Please provide it as an argument or set the GITHUB_SHA environment variable.") |
| 26 | + sys.exit(1) |
| 27 | + |
15 | 28 | # Generate the table
|
16 | 29 |
|
17 |
| -print("## Runtime Tests Report") |
| 30 | +print("## Runtime Test Results") |
18 | 31 | print("")
|
19 | 32 |
|
20 | 33 | try:
|
|
99 | 112 | print("")
|
100 | 113 |
|
101 | 114 | try:
|
102 |
| - print(f"[Build, Hardware and QEMU run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['BUILD_RUN_ID']}) / [Wokwi run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['WOKWI_RUN_ID']})") |
| 115 | + print(f"[Commit](https://github.com/{os.environ['GITHUB_REPOSITORY']}/commit/{commit_sha}) / [Build, Hardware and QEMU run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['BUILD_RUN_ID']}) / [Wokwi run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['WOKWI_RUN_ID']})") |
103 | 116 | except KeyError:
|
104 | 117 | pass
|
| 118 | + |
| 119 | +# Save test results to JSON file |
| 120 | +results_data = { |
| 121 | + "commit_sha": commit_sha, |
| 122 | + "tests_failed": os.environ["IS_FAILING"] == "true", |
| 123 | + "test_data": proc_test_data, |
| 124 | + "generated_at": datetime.now().isoformat() |
| 125 | +} |
| 126 | + |
| 127 | +with open("test_results.json", "w") as f: |
| 128 | + json.dump(results_data, f, indent=2) |
| 129 | + |
| 130 | +print(f"\nTest results saved to test_results.json") |
| 131 | +print(f"Commit SHA: {commit_sha}") |
| 132 | +print(f"Tests failed: {results_data['tests_failed']}") |
0 commit comments