Skip to content

Commit

Permalink
Merge pull request ClickHouse#43894 from ClickHouse/improve-release-s…
Browse files Browse the repository at this point in the history
…cript

Improve release script
  • Loading branch information
Felixoid authored Dec 2, 2022
2 parents c2ceb78 + 7356d48 commit e2a9b22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
3 changes: 1 addition & 2 deletions tests/ci/mark_release_ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from get_robot_token import get_best_robot_token
from github_helper import GitHub
from pr_info import PRInfo

RELEASE_READY_STATUS = "Ready for release"
from release import RELEASE_READY_STATUS


def main():
Expand Down
51 changes: 25 additions & 26 deletions tests/ci/release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""
script to create releases for ClickHouse
Expand All @@ -13,12 +13,11 @@
from contextlib import contextmanager
from typing import Any, Iterator, List, Literal, Optional
import argparse
import json
import logging
import subprocess

from git_helper import commit, release_branch
from github_helper import GitHub
from mark_release_ready import RELEASE_READY_STATUS
from version_helper import (
FILE_WITH_VERSION_PATH,
GENERATED_CONTRIBUTORS,
Expand All @@ -31,6 +30,7 @@
update_contributors,
)

RELEASE_READY_STATUS = "Ready for release"

git = Git()

Expand Down Expand Up @@ -112,31 +112,30 @@ def get_stable_release_type(self) -> str:
return VersionType.STABLE

def check_commit_release_ready(self):
# First, get the auth token from gh cli
auth_status = self.run(
"gh auth status -t", stderr=subprocess.STDOUT
).splitlines()
token = ""
for line in auth_status:
if "✓ Token:" in line:
token = line.split()[-1]
if not token:
logging.error("Can not extract token from `gh auth`")
raise subprocess.SubprocessError("Can not extract token from `gh auth`")
gh = GitHub(token, per_page=100)
repo = gh.get_repo(str(self.repo))

# Statuses are ordered by descending updated_at, so the first necessary
# status in the list is the most recent
statuses = repo.get_commit(self.release_commit).get_statuses()
for status in statuses:
if status.context == RELEASE_READY_STATUS:
if status.state == "success":
per_page = 100
page = 1
while True:
statuses = json.loads(
self.run(
f"gh api 'repos/{self.repo}/commits/{self.release_commit}"
f"/statuses?per_page={per_page}&page={page}'"
)
)

if not statuses:
break

for status in statuses:
if status["context"] == RELEASE_READY_STATUS:
if not status["state"] == "success":
raise Exception(
f"the status {RELEASE_READY_STATUS} is {status['state']}"
", not success"
)

return

raise Exception(
f"the status {RELEASE_READY_STATUS} is {status.state}, not success"
)
page += 1

raise Exception(
f"the status {RELEASE_READY_STATUS} "
Expand Down

0 comments on commit e2a9b22

Please sign in to comment.