Merge pull request #70804 from ClickHouse/backport/24.8/70643

Backport #70643 to 24.8: Fix buddy false alerts
This commit is contained in:
robot-ch-test-poll 2024-10-17 17:09:56 +02:00 committed by GitHub
commit 1f7cf41131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 58 additions and 22 deletions

View File

@ -1,15 +1,18 @@
import argparse import argparse
import json import json
import os import os
from typing import Union, Dict, List from typing import Dict, List, Union
import boto3 import boto3
import requests import requests
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
from pr_info import PRInfo
from ci_config import CI from ci_config import CI
from ci_utils import WithIter from ci_utils import WithIter
from commit_status_helper import get_commit_filtered_statuses, get_repo
from get_robot_token import get_best_robot_token
from github_helper import GitHub
from pr_info import PRInfo
class Channels(metaclass=WithIter): class Channels(metaclass=WithIter):
@ -52,7 +55,8 @@ class CIBuddy:
self.pr_number = pr_info.number self.pr_number = pr_info.number
self.head_ref = pr_info.head_ref self.head_ref = pr_info.head_ref
self.commit_url = pr_info.commit_html_url self.commit_url = pr_info.commit_html_url
self.sha = pr_info.sha[:10] self.sha_full = pr_info.sha
self.sha = self.sha_full[:10]
def check_workflow(self): def check_workflow(self):
CI.GH.print_workflow_results() CI.GH.print_workflow_results()
@ -61,13 +65,25 @@ class CIBuddy:
self.post_job_error( self.post_job_error(
f"{CI.Envs.GITHUB_WORKFLOW} Workflow Failed", critical=True f"{CI.Envs.GITHUB_WORKFLOW} Workflow Failed", critical=True
) )
else: return
res = CI.GH.get_workflow_job_result(CI.GH.ActionsNames.RunConfig) res = CI.GH.get_workflow_job_result(CI.GH.ActionsNames.RunConfig)
if res != CI.GH.ActionStatuses.SUCCESS: if res == CI.GH.ActionStatuses.SUCCESS:
print(f"ERROR: RunConfig status is [{res}] - post report to slack") # the normal case
self.post_job_error( return
f"{CI.Envs.GITHUB_WORKFLOW} Workflow Failed", critical=True
gh = GitHub(get_best_robot_token())
commit = get_repo(gh).get_commit(self.sha_full)
statuses = get_commit_filtered_statuses(commit)
if any(True for st in statuses if st.context == CI.StatusNames.PR_CHECK):
print(
f"INFO: RunConfig status is [{res}], but it "
f'contains "{CI.StatusNames.PR_CHECK}" status, do not report error'
) )
return
print(f"ERROR: RunConfig status is [{res}] - post report to slack")
self.post_job_error(f"{CI.Envs.GITHUB_WORKFLOW} Workflow Failed", critical=True)
@staticmethod @staticmethod
def _get_webhooks(): def _get_webhooks():

View File

@ -552,7 +552,7 @@ CHECK_DESCRIPTIONS = [
CheckDescription( CheckDescription(
CI.StatusNames.PR_CHECK, CI.StatusNames.PR_CHECK,
"Checks correctness of the PR's body", "Checks correctness of the PR's body",
lambda x: x == "PR Check", lambda x: x == CI.StatusNames.PR_CHECK,
), ),
CheckDescription( CheckDescription(
CI.StatusNames.SYNC, CI.StatusNames.SYNC,

View File

@ -4,8 +4,8 @@ import re
import sys import sys
from typing import Tuple from typing import Tuple
from github import Github from build_download_helper import APIException
from ci_config import CI
from commit_status_helper import ( from commit_status_helper import (
create_ci_report, create_ci_report,
format_description, format_description,
@ -16,11 +16,10 @@ from commit_status_helper import (
) )
from env_helper import GITHUB_REPOSITORY, GITHUB_SERVER_URL from env_helper import GITHUB_REPOSITORY, GITHUB_SERVER_URL
from get_robot_token import get_best_robot_token from get_robot_token import get_best_robot_token
from ci_config import CI from github_helper import GitHub
from pr_info import PRInfo from pr_info import PRInfo
from report import FAILURE, PENDING, SUCCESS, StatusType from report import FAILURE, PENDING, SUCCESS, StatusType
TRUSTED_ORG_IDS = { TRUSTED_ORG_IDS = {
54801242, # clickhouse 54801242, # clickhouse
} }
@ -47,7 +46,6 @@ TRUSTED_CONTRIBUTORS = {
} }
OK_SKIP_LABELS = {CI.Labels.RELEASE, CI.Labels.PR_BACKPORT, CI.Labels.PR_CHERRYPICK} OK_SKIP_LABELS = {CI.Labels.RELEASE, CI.Labels.PR_BACKPORT, CI.Labels.PR_CHERRYPICK}
PR_CHECK = "PR Check"
LABEL_CATEGORIES = { LABEL_CATEGORIES = {
@ -207,11 +205,33 @@ def should_run_ci_for_pr(pr_info: PRInfo) -> Tuple[bool, str]:
def main(): def main():
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
pr_info = PRInfo(need_orgs=True, pr_event_from_api=True, need_changed_files=True) fail_early = False
try:
pr_info = PRInfo(
need_orgs=True, pr_event_from_api=True, need_changed_files=True
)
except APIException as e:
logging.exception(
"Failed to receive the PRInfo, backport to a simple case and exit with error",
exc_info=e,
)
pr_info = PRInfo()
fail_early = True
# The case for special branches like backports and releases without created # The case for special branches like backports and releases without created
# PRs, like merged backport branches that are reset immediately after merge # PRs, like merged backport branches that are reset immediately after merge
if pr_info.number == 0: if pr_info.number == 0 or fail_early:
print("::notice ::Cannot run, no PR exists for the commit") print("::notice ::Cannot run, no PR exists for the commit")
gh = GitHub(get_best_robot_token(), per_page=100)
commit = get_commit(gh, pr_info.sha)
post_commit_status(
commit,
FAILURE,
"",
"No PRs found for the commit, finished early",
CI.StatusNames.PR_CHECK,
pr_info,
)
sys.exit(1) sys.exit(1)
can_run, description = should_run_ci_for_pr(pr_info) can_run, description = should_run_ci_for_pr(pr_info)
@ -220,7 +240,7 @@ def main():
sys.exit(0) sys.exit(0)
description = format_description(description) description = format_description(description)
gh = Github(get_best_robot_token(), per_page=100) gh = GitHub(get_best_robot_token(), per_page=100)
commit = get_commit(gh, pr_info.sha) commit = get_commit(gh, pr_info.sha)
status = SUCCESS # type: StatusType status = SUCCESS # type: StatusType
@ -285,7 +305,7 @@ def main():
status, status,
url, url,
format_description(description_error), format_description(description_error),
PR_CHECK, CI.StatusNames.PR_CHECK,
pr_info, pr_info,
) )
sys.exit(1) sys.exit(1)
@ -310,7 +330,7 @@ def main():
status, status,
"", "",
description, description,
PR_CHECK, CI.StatusNames.PR_CHECK,
pr_info, pr_info,
) )
print("::error ::Cannot run") print("::error ::Cannot run")
@ -322,7 +342,7 @@ def main():
status, status,
"", "",
description, description,
PR_CHECK, CI.StatusNames.PR_CHECK,
pr_info, pr_info,
) )