Add JOB_ID and JOB_URL getters

This commit is contained in:
Mikhail f. Shiryaev 2022-08-09 18:34:12 +02:00
parent 99b9e85a8f
commit 32efae4f1b
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4

View File

@ -1,6 +1,8 @@
import os import os
from os import path as p from os import path as p
from build_download_helper import get_with_retries
module_dir = p.abspath(p.dirname(__file__)) module_dir = p.abspath(p.dirname(__file__))
git_root = p.abspath(p.join(module_dir, "..", "..")) git_root = p.abspath(p.join(module_dir, "..", ".."))
@ -22,3 +24,37 @@ REPO_COPY = os.getenv("REPO_COPY", git_root)
RUNNER_TEMP = os.getenv("RUNNER_TEMP", p.abspath(p.join(module_dir, "./tmp"))) RUNNER_TEMP = os.getenv("RUNNER_TEMP", p.abspath(p.join(module_dir, "./tmp")))
S3_BUILDS_BUCKET = os.getenv("S3_BUILDS_BUCKET", "clickhouse-builds") S3_BUILDS_BUCKET = os.getenv("S3_BUILDS_BUCKET", "clickhouse-builds")
S3_TEST_REPORTS_BUCKET = os.getenv("S3_TEST_REPORTS_BUCKET", "clickhouse-test-reports") S3_TEST_REPORTS_BUCKET = os.getenv("S3_TEST_REPORTS_BUCKET", "clickhouse-test-reports")
# These parameters are set only on demand, and only once
_GITHUB_JOB_ID = ""
_GITHUB_JOB_URL = ""
def GITHUB_JOB_ID() -> str:
global _GITHUB_JOB_ID
global _GITHUB_JOB_URL
if _GITHUB_JOB_ID:
return _GITHUB_JOB_ID
jobs = []
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"
)
data = response.json()
jobs.extend(data["jobs"])
for job in data["jobs"]:
if job["name"] != GITHUB_JOB:
continue
_GITHUB_JOB_ID = job["id"]
_GITHUB_JOB_URL = job["html_url"]
return _GITHUB_JOB_ID
if len(jobs) == data["total_count"]:
_GITHUB_JOB_ID = "0"
return _GITHUB_JOB_ID
def GITHUB_JOB_URL() -> str:
GITHUB_JOB_ID()
return _GITHUB_JOB_URL