2021-11-12 12:36:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-12-28 10:13:51 +00:00
|
|
|
import time
|
2022-03-18 12:36:45 +00:00
|
|
|
import os
|
|
|
|
import csv
|
2021-11-26 14:00:09 +00:00
|
|
|
from env_helper import GITHUB_REPOSITORY
|
2022-01-10 16:45:17 +00:00
|
|
|
from ci_config import CI_CONFIG
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2021-12-28 10:13:51 +00:00
|
|
|
RETRY = 5
|
|
|
|
|
|
|
|
|
2022-03-10 16:39:18 +00:00
|
|
|
def override_status(status, check_name, invert=False):
|
|
|
|
if CI_CONFIG["tests_config"].get(check_name, {}).get("force_tests", False):
|
2022-01-10 16:45:17 +00:00
|
|
|
return "success"
|
2022-03-10 16:39:18 +00:00
|
|
|
|
|
|
|
if invert:
|
2022-03-22 16:39:58 +00:00
|
|
|
if status == "success":
|
|
|
|
return "error"
|
|
|
|
return "success"
|
2022-03-10 16:39:18 +00:00
|
|
|
|
2022-01-10 16:45:17 +00:00
|
|
|
return status
|
|
|
|
|
|
|
|
|
2021-12-28 10:13:51 +00:00
|
|
|
def get_commit(gh, commit_sha, retry_count=RETRY):
|
|
|
|
for i in range(retry_count):
|
|
|
|
try:
|
|
|
|
repo = gh.get_repo(GITHUB_REPOSITORY)
|
|
|
|
commit = repo.get_commit(commit_sha)
|
|
|
|
return commit
|
|
|
|
except Exception as ex:
|
|
|
|
if i == retry_count - 1:
|
|
|
|
raise ex
|
|
|
|
time.sleep(i)
|
|
|
|
|
|
|
|
# just suppress warning
|
|
|
|
return None
|
2021-11-12 12:36:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def post_commit_status(gh, sha, check_name, description, state, report_url):
|
2021-12-28 10:13:51 +00:00
|
|
|
for i in range(RETRY):
|
|
|
|
try:
|
|
|
|
commit = get_commit(gh, sha, 1)
|
2022-01-10 16:37:38 +00:00
|
|
|
commit.create_status(
|
|
|
|
context=check_name,
|
|
|
|
description=description,
|
|
|
|
state=state,
|
|
|
|
target_url=report_url,
|
|
|
|
)
|
2021-12-28 10:13:51 +00:00
|
|
|
break
|
|
|
|
except Exception as ex:
|
|
|
|
if i == RETRY - 1:
|
|
|
|
raise ex
|
|
|
|
time.sleep(i)
|
2022-03-18 12:36:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def post_commit_status_to_file(file_path, description, state, report_url):
|
|
|
|
if os.path.exists(file_path):
|
|
|
|
raise Exception(f'File "{file_path}" already exists!')
|
2022-03-22 16:39:58 +00:00
|
|
|
with open(file_path, "w", encoding="utf-8") as f:
|
|
|
|
out = csv.writer(f, delimiter="\t")
|
2022-03-18 12:36:45 +00:00
|
|
|
out.writerow([state, report_url, description])
|