mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #65228 from ClickHouse/ci_propagate_wf_error_to_finish_check
CI: FinishCheck to set failure if workflow failed
This commit is contained in:
commit
205cb400ab
2
.github/workflows/backport_branches.yml
vendored
2
.github/workflows/backport_branches.yml
vendored
@ -273,5 +273,5 @@ jobs:
|
|||||||
- name: Finish label
|
- name: Finish label
|
||||||
run: |
|
run: |
|
||||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||||
python3 finish_check.py
|
python3 finish_check.py --wf-status ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
|
||||||
python3 merge_pr.py
|
python3 merge_pr.py
|
||||||
|
2
.github/workflows/master.yml
vendored
2
.github/workflows/master.yml
vendored
@ -173,4 +173,4 @@ jobs:
|
|||||||
- name: Finish label
|
- name: Finish label
|
||||||
run: |
|
run: |
|
||||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||||
python3 finish_check.py
|
python3 finish_check.py --wf-status ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
|
||||||
|
2
.github/workflows/merge_queue.yml
vendored
2
.github/workflows/merge_queue.yml
vendored
@ -112,4 +112,4 @@ jobs:
|
|||||||
- name: Finish label
|
- name: Finish label
|
||||||
run: |
|
run: |
|
||||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||||
python3 finish_check.py ${{ (contains(needs.*.result, 'failure') && github.event_name == 'merge_group') && '--pipeline-failure' || '' }}
|
python3 finish_check.py --wf-status ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
|
||||||
|
2
.github/workflows/pull_request.yml
vendored
2
.github/workflows/pull_request.yml
vendored
@ -191,7 +191,7 @@ jobs:
|
|||||||
- name: Finish label
|
- name: Finish label
|
||||||
run: |
|
run: |
|
||||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||||
python3 finish_check.py
|
python3 finish_check.py --wf-status ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
|
||||||
|
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
###################################### JEPSEN TESTS #########################################
|
###################################### JEPSEN TESTS #########################################
|
||||||
|
2
.github/workflows/release_branches.yml
vendored
2
.github/workflows/release_branches.yml
vendored
@ -496,4 +496,4 @@ jobs:
|
|||||||
- name: Finish label
|
- name: Finish label
|
||||||
run: |
|
run: |
|
||||||
cd "$GITHUB_WORKSPACE/tests/ci"
|
cd "$GITHUB_WORKSPACE/tests/ci"
|
||||||
python3 finish_check.py
|
python3 finish_check.py --wf-status ${{ contains(needs.*.result, 'failure') && 'failure' || 'success' }}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
from github import Github
|
from github import Github
|
||||||
|
|
||||||
@ -20,28 +20,40 @@ from report import FAILURE, PENDING, SUCCESS, StatusType
|
|||||||
from synchronizer_utils import SYNC_BRANCH_PREFIX
|
from synchronizer_utils import SYNC_BRANCH_PREFIX
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args() -> argparse.Namespace:
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
|
description="Script to merge the given PR. Additional checks for approved "
|
||||||
|
"status and green commit statuses could be done",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--wf-status",
|
||||||
|
type=str,
|
||||||
|
default="",
|
||||||
|
help="overall workflow status [success|failure]",
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
has_failure = False
|
has_workflow_failures = args.wf_status == FAILURE
|
||||||
|
|
||||||
# FIXME: temporary hack to fail Mergeable Check in MQ if pipeline has any failed jobs
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1] == "--pipeline-failure":
|
|
||||||
has_failure = True
|
|
||||||
|
|
||||||
pr_info = PRInfo(need_orgs=True)
|
pr_info = PRInfo(need_orgs=True)
|
||||||
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)
|
||||||
statuses = None
|
|
||||||
|
|
||||||
if pr_info.is_merge_queue:
|
if pr_info.is_merge_queue:
|
||||||
# in MQ Mergeable check status must never be green if any failures in workflow
|
# in MQ Mergeable check status must never be green if any failures in the workflow
|
||||||
if has_failure:
|
if has_workflow_failures:
|
||||||
set_mergeable_check(commit, "workflow failed", "failure")
|
set_mergeable_check(commit, "workflow failed", FAILURE)
|
||||||
else:
|
else:
|
||||||
# This must be the only place where green MCheck is set in the MQ (in the end of CI) to avoid early merge
|
# This must be the only place where green MCheck is set in the MQ (in the end of CI) to avoid early merge
|
||||||
set_mergeable_check(commit, "workflow passed", "success")
|
set_mergeable_check(commit, "workflow passed", SUCCESS)
|
||||||
else:
|
return
|
||||||
|
|
||||||
statuses = get_commit_filtered_statuses(commit)
|
statuses = get_commit_filtered_statuses(commit)
|
||||||
state = trigger_mergeable_check(commit, statuses, set_if_green=True)
|
state = trigger_mergeable_check(commit, statuses, set_if_green=True)
|
||||||
|
|
||||||
@ -67,33 +79,35 @@ def main():
|
|||||||
|
|
||||||
has_failure = False
|
has_failure = False
|
||||||
has_pending = False
|
has_pending = False
|
||||||
|
error_cnt = 0
|
||||||
for status in statuses:
|
for status in statuses:
|
||||||
if status.context in (StatusNames.MERGEABLE, StatusNames.CI):
|
if status.context in (StatusNames.MERGEABLE, StatusNames.CI, StatusNames.SYNC):
|
||||||
# do not account these statuses
|
# do not account these statuses
|
||||||
continue
|
continue
|
||||||
if status.state == PENDING:
|
if status.state == PENDING:
|
||||||
if status.context == StatusNames.SYNC:
|
|
||||||
# do not account sync status if pending - it's a different WF
|
|
||||||
continue
|
|
||||||
has_pending = True
|
has_pending = True
|
||||||
elif status.state == SUCCESS:
|
elif status.state != SUCCESS:
|
||||||
continue
|
|
||||||
else:
|
|
||||||
has_failure = True
|
has_failure = True
|
||||||
|
error_cnt += 1
|
||||||
|
|
||||||
ci_state = SUCCESS # type: StatusType
|
ci_state = SUCCESS # type: StatusType
|
||||||
|
description = "All checks finished"
|
||||||
if has_failure:
|
if has_failure:
|
||||||
ci_state = FAILURE
|
ci_state = FAILURE
|
||||||
|
description = f"All checks finished. {error_cnt} jobs failed"
|
||||||
|
elif has_workflow_failures:
|
||||||
|
ci_state = FAILURE
|
||||||
|
description = "All checks finished. Workflow has failures."
|
||||||
elif has_pending:
|
elif has_pending:
|
||||||
print("ERROR: CI must not have pending jobs by the time of finish check")
|
print("ERROR: CI must not have pending jobs by the time of finish check")
|
||||||
|
description = "ERROR: workflow has pending jobs"
|
||||||
ci_state = FAILURE
|
ci_state = FAILURE
|
||||||
|
|
||||||
if ci_status.state == PENDING:
|
|
||||||
post_commit_status(
|
post_commit_status(
|
||||||
commit,
|
commit,
|
||||||
ci_state,
|
ci_state,
|
||||||
ci_status.target_url,
|
ci_status.target_url,
|
||||||
"All checks finished",
|
description,
|
||||||
StatusNames.CI,
|
StatusNames.CI,
|
||||||
pr_info,
|
pr_info,
|
||||||
dump_to_file=True,
|
dump_to_file=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user