Skip to content

Commit d4fb00e

Browse files
CI: drop superseded attempts from the workflow report after a rerun
Ports the anchor CTE from #1572 and #2142, keeping only rows at or after the latest result batch per check_name. The guard excludes STARTED/COMPLETED instead of praktika's Pre Hooks/Post Hooks, since COMPLETED lands after the tests on the old CI and would otherwise hide every failure. Signed-off-by: CarlosFelipeOR <carlosfelipeor@gmail.com>
1 parent 12c1369 commit d4fb00e

1 file changed

Lines changed: 77 additions & 46 deletions

File tree

‎.github/actions/create_workflow_report/create_workflow_report.py‎

Lines changed: 77 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,79 @@ def get_run_details(run_url: str) -> dict:
148148
return response.json()
149149

150150

151+
def _checks_latest_test_status_cte(commit_sha: str, branch_name: str) -> str:
152+
"""
153+
Shared filtering for gh-data.checks: anchor time selects the latest result batch
154+
per check_name.
155+
156+
Rows that must not set the anchor (but are still kept if their time is >= anchor):
157+
- Stateless teardown: check_name LIKE 'Stateless%' AND test_name not matching ^[0-9]{5}
158+
- Empty test_name: CIDB job-level parent rows
159+
- STARTED / COMPLETED: job lifecycle markers with their own stopwatches; COMPLETED
160+
always lands after the tests and would otherwise become the sole surviving batch,
161+
hiding all FAILs
162+
163+
Keep rows with check_start_time >= anchor so the latest main batch and any later
164+
teardown/marker rows are included. Earlier batches (failed attempts before a rerun
165+
uploaded a newer uniform timestamp) are dropped, including synthetic rows such as
166+
'Job Timeout Expired' that only exist in the attempt that failed.
167+
"""
168+
return f"""WITH checks_with_anchor AS (
169+
SELECT
170+
check_name,
171+
test_name,
172+
report_url,
173+
check_status,
174+
test_status,
175+
check_start_time,
176+
maxIf(
177+
check_start_time,
178+
test_name != ''
179+
AND test_name NOT IN ('STARTED', 'COMPLETED')
180+
AND NOT (
181+
check_name LIKE 'Stateless%'
182+
AND NOT match(test_name, '^[0-9]{{5}}')
183+
)
184+
) OVER (PARTITION BY check_name) AS latest_check_start_time
185+
FROM `gh-data`.checks
186+
WHERE commit_sha = '{commit_sha}'
187+
AND head_ref IN ('{branch_name}', 'refs/tags/{branch_name}')
188+
),
189+
rows_from_latest_check_run AS (
190+
SELECT
191+
check_name,
192+
test_name,
193+
report_url,
194+
check_status,
195+
test_status,
196+
check_start_time
197+
FROM checks_with_anchor
198+
WHERE check_start_time >= latest_check_start_time
199+
),
200+
latest_test_status AS (
201+
SELECT
202+
argMax(check_status, check_start_time) AS job_status,
203+
check_name AS job_name,
204+
argMax(test_status, check_start_time) AS status,
205+
test_name,
206+
report_url AS results_link
207+
FROM rows_from_latest_check_run
208+
GROUP BY check_name, test_name, report_url
209+
)"""
210+
211+
151212
def get_checks_fails(client: Client, commit_sha: str, branch_name: str):
152213
"""
153214
Get tests that did not succeed for the given commit and branch.
154215
Exclude checks that have status 'error' as they are counted in get_checks_errors.
155216
"""
156-
query = f"""SELECT job_status, job_name, status as test_status, test_name, results_link
157-
FROM (
158-
SELECT
159-
argMax(check_status, check_start_time) as job_status,
160-
check_name as job_name,
161-
argMax(test_status, check_start_time) as status,
162-
test_name,
163-
report_url as results_link,
164-
task_url
165-
FROM `gh-data`.checks
166-
WHERE commit_sha='{commit_sha}' AND head_ref IN ('{branch_name}', 'refs/tags/{branch_name}')
167-
GROUP BY check_name, test_name, report_url, task_url
168-
)
169-
WHERE test_status IN ('FAIL', 'ERROR')
170-
AND job_status!='error'
171-
ORDER BY job_name, test_name
172-
"""
217+
query = f"""{_checks_latest_test_status_cte(commit_sha, branch_name)}
218+
SELECT job_status, job_name, status AS test_status, test_name, results_link
219+
FROM latest_test_status
220+
WHERE test_status IN ('FAIL', 'ERROR')
221+
AND job_status != 'error'
222+
ORDER BY job_name, test_name
223+
"""
173224
return client.query_dataframe(query)
174225

175226

@@ -182,19 +233,9 @@ def get_checks_known_fails(
182233
if len(known_fails) == 0:
183234
return pd.DataFrame()
184235

185-
query = f"""SELECT job_status, job_name, status as test_status, test_name, results_link
186-
FROM (
187-
SELECT
188-
argMax(check_status, check_start_time) as job_status,
189-
check_name as job_name,
190-
argMax(test_status, check_start_time) as status,
191-
test_name,
192-
report_url as results_link,
193-
task_url
194-
FROM `gh-data`.checks
195-
WHERE commit_sha='{commit_sha}' AND head_ref IN ('{branch_name}', 'refs/tags/{branch_name}')
196-
GROUP BY check_name, test_name, report_url, task_url
197-
)
236+
query = f"""{_checks_latest_test_status_cte(commit_sha, branch_name)}
237+
SELECT job_status, job_name, status AS test_status, test_name, results_link
238+
FROM latest_test_status
198239
WHERE test_status='BROKEN'
199240
AND test_name IN ({','.join(f"'{test}'" for test in known_fails.keys())})
200241
ORDER BY job_name, test_name
@@ -219,22 +260,12 @@ def get_checks_errors(client: Client, commit_sha: str, branch_name: str):
219260
"""
220261
Get checks that have status 'error' for the given commit and branch.
221262
"""
222-
query = f"""SELECT job_status, job_name, status as test_status, test_name, results_link
223-
FROM (
224-
SELECT
225-
argMax(check_status, check_start_time) as job_status,
226-
check_name as job_name,
227-
argMax(test_status, check_start_time) as status,
228-
test_name,
229-
report_url as results_link,
230-
task_url
231-
FROM `gh-data`.checks
232-
WHERE commit_sha='{commit_sha}' AND head_ref IN ('{branch_name}', 'refs/tags/{branch_name}')
233-
GROUP BY check_name, test_name, report_url, task_url
234-
)
235-
WHERE job_status=='error'
236-
ORDER BY job_name, test_name
237-
"""
263+
query = f"""{_checks_latest_test_status_cte(commit_sha, branch_name)}
264+
SELECT job_status, job_name, status AS test_status, test_name, results_link
265+
FROM latest_test_status
266+
WHERE job_status == 'error'
267+
ORDER BY job_name, test_name
268+
"""
238269
return client.query_dataframe(query)
239270

240271

0 commit comments

Comments
 (0)