55
55
- name : Test Queries
56
56
if : steps.changes.outputs.src == 'true'
57
57
env :
58
- GITHUB_TOKEN : ${{ github.token }}
58
+ RUNNER_TEMP : ${{ runner.temp }}
59
+ shell : python
59
60
run : |
60
- ./.github/scripts/pr-tests.sh ${{ github.event.number }} ${{ matrix.language }}
61
+ import os
62
+ import sys
63
+ import subprocess
64
+ from pathlib import Path
65
+
66
+ def print_error(fmt, *args):
67
+ print(f"::error::{fmt}", *args)
68
+
69
+ def print_error_and_fail(fmt, *args):
70
+ print_error(fmt, args)
71
+ sys.exit(1)
72
+
73
+ runner_temp = os.environ['RUNNER_TEMP']
74
+
75
+ test_root = Path('${{ github.workspace }}', '${{ matrix.language }}', 'test')
76
+ print(f"Executing tests found (recursively) in the directory '{test_root}'")
77
+ files_to_close = []
78
+ try:
79
+ # Runners have 4 cores, so split the tests into 4 "slices", and run one per thread
80
+ num_slices = 4
81
+ procs = []
82
+
83
+ for slice in range(1, num_slices+1):
84
+ test_report_path = os.path.join(runner_temp, "${{ matrix.language }}", f"test_report_slice_{slice}_of_{num_slices}.json")
85
+ os.makedirs(os.path.dirname(test_report_path), exist_ok=True)
86
+ test_report_file = open(test_report_path, 'w')
87
+ files_to_close.append(test_report_file)
88
+ procs.append(subprocess.Popen(["codeql", "test", "run", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", test_root], stdout=test_report_file, stderr=subprocess.PIPE))
89
+
90
+ for p in procs:
91
+ _, err = p.communicate()
92
+ if p.returncode != 0:
93
+ if p.returncode == 122:
94
+ # Failed because a test case failed, so just print the regular output.
95
+ # This will allow us to proceed to validate-test-results, which will fail if
96
+ # any test cases failed
97
+ print(f"{err.decode()}")
98
+ else:
99
+ # Some more serious problem occurred, so print and fail fast
100
+ print_error_and_fail(f"Failed to run tests with return code {p.returncode}\n{err.decode()}")
101
+ finally:
102
+ for file in files_to_close:
103
+ file.close()
104
+
105
+ - name : Upload test results
106
+ if : steps.changes.outputs.src == 'true'
107
+ uses : actions/upload-artifact@v4
108
+ with :
109
+ name : ${{ matrix.language }}-test-results
110
+ path : |
111
+ ${{ runner.temp }}/${{ matrix.language }}/test_report_slice_*.json
112
+ if-no-files-found : error
61
113
62
114
- name : Compile / Check Suites & Packs
63
115
if : steps.changes.outputs.src == 'true'
@@ -66,6 +118,39 @@ jobs:
66
118
run : |
67
119
./.github/scripts/pr-suites-packs.sh ${{ github.event.number }} ${{ matrix.language }}
68
120
121
+ validate-test-results :
122
+ name : Validate test results
123
+ needs : compile-and-test
124
+ runs-on : ubuntu-latest
125
+ steps :
126
+ - name : Check if compile-and-test job failed to complete, if so fail
127
+ if : ${{ needs.compile-and-test.result == 'failure' }}
128
+ uses : actions/github-script@v3
129
+ with :
130
+ script : |
131
+ core.setFailed('Test run job failed')
132
+
133
+ - name : Collect test results
134
+ uses : actions/download-artifact@v4
135
+
136
+ - name : Validate test results
137
+ run : |
138
+ if [[ ! -n "$(find . -name 'test_report_*' -print -quit)" ]]; then
139
+ echo "No test results found"
140
+ exit 0
141
+ fi
142
+
143
+ for json_report in *-test-results/test_report_*
144
+ do
145
+ jq --raw-output '"PASS \(map(select(.pass == true)) | length)/\(length)'" $json_report\"" "$json_report"
146
+ done
147
+ FAILING_TESTS=$(jq --raw-output '.[] | select(.pass == false)' *-test-results/test_report_*.json)
148
+ if [[ ! -z "$FAILING_TESTS" ]]; then
149
+ echo "ERROR: The following tests failed:"
150
+ echo $FAILING_TESTS | jq .
151
+ exit 1
152
+ fi
153
+
69
154
extensions :
70
155
runs-on : ubuntu-latest
71
156
0 commit comments