Skip to content

Commit b771c20

Browse files
authored
Bot fixes and improvements (pyccel#1953)
Update `ci_tools/bot_clean_up.py` to correctly handle the new output of `get_name_key`. Improve the bot to retrigger linux tests if the artifacts have expired and the coverage is requested.
1 parent 6785257 commit b771c20

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

ci_tools/bot_clean_up.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
pr_id = 0
3232

3333
name_key = bot.get_name_key(name)
34+
if isinstance(name_key, tuple):
35+
# Ignore Python version
36+
name_key = name_key[0]
3437

3538
runs = bot.get_check_runs()
3639

@@ -46,11 +49,14 @@
4649

4750
for q in queued_runs:
4851
q_name = q['name']
49-
deps = test_dependencies.get(bot.get_name_key(q_name), ())
52+
q_key = bot.get_name_key(q_name)
53+
if not isinstance(q_key, tuple):
54+
# Not a Pyccel triggered test
55+
continue
56+
deps = test_dependencies.get(q_key[0], ())
5057
if name_key in deps:
5158
if all(d in successful_runs for d in deps):
52-
q_key = q_name.split('(')[1].split(')')[0].strip()
53-
q_name, python_version = q_key.split(',')
59+
q_name, python_version = q_key
5460
workflow_ids = None
5561
if q_name == 'coverage':
5662
workflow_ids = [int(r['details_url'].split('/')[-1]) for r in runs if r['conclusion'] == "success" and '(' in r['name']]

ci_tools/bot_tools/bot_funcs.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,20 @@ def run_tests(self, tests, python_version = None, force_run = False):
308308
assert p.returncode == 0
309309

310310
commit_log = [o.split(' ')[0] for o in out.split('\n')]
311-
print(commit_log)
312311
idx = next((i for i,c in enumerate(commit_log) if c ==self._base), len(commit_log))
313312
commit_log = commit_log[:idx+1]
314313

315314
for t in tests:
316315
pv = python_version or default_python_versions[t]
317316
key = (t, pv)
318-
if key in already_triggered_names:
319-
states.append(check_runs[key]['conclusion'])
320-
continue
317+
if key in check_runs:
318+
current_conclusion = check_runs[key]['conclusion']
319+
if current_conclusion:
320+
workflow_id = int(check_runs[key]['details_url'].split('/')[-1])
321+
force_run = not self._GAI.has_valid_artifacts(workflow_id)
322+
if key in already_triggered_names and not force_run:
323+
states.append(check_runs[key]['conclusion'])
324+
continue
321325
name = f"{test_names[t]} ({t}, {pv})"
322326
if not force_run and not self.is_test_required(commit_log, name, t, states):
323327
continue
@@ -331,11 +335,14 @@ def run_tests(self, tests, python_version = None, force_run = False):
331335
print(already_triggered_names, deps)
332336
if all(d in success_names for d in deps):
333337
workflow_ids = None
338+
ready = True
334339
if t == 'coverage':
335340
print([r['details_url'] for r in check_runs.values() if r['conclusion'] == "success"])
336341
workflow_ids = [int(r['details_url'].split('/')[-1]) for r in check_runs.values() if r['conclusion'] == "success" and '(' in r['name']]
337-
print("Running test")
338-
self.run_test(t, pv, posted["id"], workflow_ids)
342+
ready = all(self._GAI.has_valid_artifacts(w) for w in workflow_ids)
343+
if ready:
344+
print("Running test")
345+
self.run_test(t, pv, posted["id"], workflow_ids)
339346
return states
340347

341348
def run_test(self, test, python_version, check_run_id, workflow_ids = None):

ci_tools/bot_tools/github_api_interactions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,29 @@ def wait_for_runs(self, commit_sha, run_names, max_time=15*60, wait_time=15):
883883

884884
return success
885885

886+
def has_valid_artifacts(self, run_id):
887+
"""
888+
Check if all the artifacts associated with a run id are valid (i.e. not expired).
889+
890+
Check if all the artifacts associated with a run id are valid (i.e. not expired).
891+
This is done by collecting all artifacts associated with a run id using the GitHub
892+
API as described here:
893+
<https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts>
894+
895+
Parameters
896+
----------
897+
run_id : int
898+
The id of the run to be investigated.
899+
900+
Returns
901+
-------
902+
bool
903+
True if all artifacts are valid. False otherwise.
904+
"""
905+
url = f"https://api.github.com/repos/{self._org}/{self._repo}/actions/runs/{run_id}/artifacts"
906+
artifacts = self._post_request("GET", url).json()['artifacts']
907+
return all(not a['expired'] for a in artifacts)
908+
886909
def get_headers(self):
887910
"""
888911
Get the header which is always passed to the API.

0 commit comments

Comments
 (0)