2021-11-26 14:00:09 +00:00
|
|
|
import os
|
2022-03-23 10:53:32 +00:00
|
|
|
from os import path as p
|
|
|
|
|
2023-04-28 16:26:50 +00:00
|
|
|
from build_download_helper import get_gh_api
|
2022-08-09 16:34:12 +00:00
|
|
|
|
2022-03-23 10:53:32 +00:00
|
|
|
module_dir = p.abspath(p.dirname(__file__))
|
|
|
|
git_root = p.abspath(p.join(module_dir, "..", ".."))
|
2021-11-26 14:00:09 +00:00
|
|
|
|
|
|
|
CI = bool(os.getenv("CI"))
|
2022-05-25 13:15:11 +00:00
|
|
|
TEMP_PATH = os.getenv("TEMP_PATH", p.abspath(p.join(module_dir, "./tmp")))
|
2021-11-26 14:00:09 +00:00
|
|
|
|
|
|
|
CACHES_PATH = os.getenv("CACHES_PATH", TEMP_PATH)
|
|
|
|
CLOUDFLARE_TOKEN = os.getenv("CLOUDFLARE_TOKEN")
|
2022-05-16 18:39:10 +00:00
|
|
|
GITHUB_EVENT_PATH = os.getenv("GITHUB_EVENT_PATH", "")
|
2022-05-25 13:15:11 +00:00
|
|
|
GITHUB_JOB = os.getenv("GITHUB_JOB", "local")
|
2021-11-26 14:00:09 +00:00
|
|
|
GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY", "ClickHouse/ClickHouse")
|
2022-03-24 14:37:53 +00:00
|
|
|
GITHUB_RUN_ID = os.getenv("GITHUB_RUN_ID", "0")
|
2021-11-26 14:00:09 +00:00
|
|
|
GITHUB_SERVER_URL = os.getenv("GITHUB_SERVER_URL", "https://github.com")
|
2022-03-23 10:53:32 +00:00
|
|
|
GITHUB_WORKSPACE = os.getenv("GITHUB_WORKSPACE", git_root)
|
2022-03-24 14:37:53 +00:00
|
|
|
GITHUB_RUN_URL = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/actions/runs/{GITHUB_RUN_ID}"
|
2022-04-07 16:22:29 +00:00
|
|
|
IMAGES_PATH = os.getenv("IMAGES_PATH", TEMP_PATH)
|
2022-03-23 10:53:32 +00:00
|
|
|
REPORTS_PATH = os.getenv("REPORTS_PATH", p.abspath(p.join(module_dir, "./reports")))
|
|
|
|
REPO_COPY = os.getenv("REPO_COPY", git_root)
|
|
|
|
RUNNER_TEMP = os.getenv("RUNNER_TEMP", p.abspath(p.join(module_dir, "./tmp")))
|
2021-11-26 14:00:09 +00:00
|
|
|
S3_BUILDS_BUCKET = os.getenv("S3_BUILDS_BUCKET", "clickhouse-builds")
|
|
|
|
S3_TEST_REPORTS_BUCKET = os.getenv("S3_TEST_REPORTS_BUCKET", "clickhouse-test-reports")
|
2022-09-07 15:10:58 +00:00
|
|
|
S3_URL = os.getenv("S3_URL", "https://s3.amazonaws.com")
|
|
|
|
S3_DOWNLOAD = os.getenv("S3_DOWNLOAD", S3_URL)
|
|
|
|
S3_ARTIFACT_DOWNLOAD_TEMPLATE = (
|
|
|
|
f"{S3_DOWNLOAD}/{S3_BUILDS_BUCKET}/"
|
|
|
|
"{pr_or_release}/{commit}/{build_name}/{artifact}"
|
|
|
|
)
|
2022-08-09 16:34:12 +00:00
|
|
|
|
|
|
|
# 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
|
2023-01-09 20:46:33 +00:00
|
|
|
if GITHUB_RUN_ID == "0":
|
|
|
|
_GITHUB_JOB_ID = "0"
|
2022-08-09 16:34:12 +00:00
|
|
|
if _GITHUB_JOB_ID:
|
|
|
|
return _GITHUB_JOB_ID
|
|
|
|
jobs = []
|
2022-11-25 16:28:13 +00:00
|
|
|
page = 1
|
2022-08-09 16:34:12 +00:00
|
|
|
while not _GITHUB_JOB_ID:
|
2023-04-28 16:26:50 +00:00
|
|
|
response = get_gh_api(
|
2022-08-09 16:34:12 +00:00
|
|
|
f"https://api.github.com/repos/{GITHUB_REPOSITORY}/"
|
2022-11-25 16:28:13 +00:00
|
|
|
f"actions/runs/{GITHUB_RUN_ID}/jobs?per_page=100&page={page}"
|
2022-08-09 16:34:12 +00:00
|
|
|
)
|
2022-11-25 16:28:13 +00:00
|
|
|
page += 1
|
2022-08-09 16:34:12 +00:00
|
|
|
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
|
2022-11-25 16:28:13 +00:00
|
|
|
if (
|
|
|
|
len(jobs) >= data["total_count"] # just in case of inconsistency
|
|
|
|
or len(data["jobs"]) == 0 # if we excided pages
|
|
|
|
):
|
2022-08-09 16:34:12 +00:00
|
|
|
_GITHUB_JOB_ID = "0"
|
|
|
|
|
|
|
|
return _GITHUB_JOB_ID
|
|
|
|
|
|
|
|
|
|
|
|
def GITHUB_JOB_URL() -> str:
|
|
|
|
GITHUB_JOB_ID()
|
|
|
|
return _GITHUB_JOB_URL
|