Skip to content

Commit

Permalink
Backport #43681 to 22.10: Fix pagination issue in GITHUB_JOB_ID()
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-clickhouse committed Nov 25, 2022
1 parent fc47557 commit ec504ba
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/ci/env_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def GITHUB_JOB_ID() -> str:
if _GITHUB_JOB_ID:
return _GITHUB_JOB_ID
jobs = []
page = 1
while not _GITHUB_JOB_ID:
response = get_with_retries(
f"https://api.github.com/repos/{GITHUB_REPOSITORY}/"
f"actions/runs/{GITHUB_RUN_ID}/jobs?per_page=100"
f"actions/runs/{GITHUB_RUN_ID}/jobs?per_page=100&page={page}"
)
page += 1
data = response.json()
jobs.extend(data["jobs"])
for job in data["jobs"]:
Expand All @@ -55,7 +57,10 @@ def GITHUB_JOB_ID() -> str:
_GITHUB_JOB_ID = job["id"]
_GITHUB_JOB_URL = job["html_url"]
return _GITHUB_JOB_ID
if len(jobs) == data["total_count"]:
if (
len(jobs) >= data["total_count"] # just in case of inconsistency
or len(data["jobs"]) == 0 # if we excided pages
):
_GITHUB_JOB_ID = "0"

return _GITHUB_JOB_ID
Expand Down

0 comments on commit ec504ba

Please sign in to comment.