Merge pull request #45013 from ClickHouse/download-script-failed

Supposedly fix the "Download script failed" error
This commit is contained in:
Alexey Milovidov 2023-01-13 05:23:09 +03:00 committed by GitHub
commit ab8c676ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,18 +2,25 @@
import re
import logging
from typing import List, Optional, Tuple
import requests # type: ignore
CLICKHOUSE_TAGS_URL = "https://api.github.com/repos/ClickHouse/ClickHouse/tags"
CLICKHOUSE_PACKAGE_URL = (
"https://github.com/ClickHouse/ClickHouse/releases/download/"
"v{version}-{type}/clickhouse-common-static_{version}_amd64.deb"
)
VERSION_PATTERN = r"(v(?:\d+\.)?(?:\d+\.)?(?:\d+\.)?\d+-[a-zA-Z]*)"
logger = logging.getLogger(__name__)
class Version:
def __init__(self, version):
def __init__(self, version: str):
self.version = version
def __lt__(self, other):
def __lt__(self, other: "Version") -> bool:
return list(map(int, self.version.split("."))) < list(
map(int, other.version.split("."))
)
@ -23,7 +30,7 @@ class Version:
class ReleaseInfo:
def __init__(self, release_tag):
def __init__(self, release_tag: str):
self.version = Version(release_tag[1:].split("-")[0])
self.type = release_tag[1:].split("-")[1]
@ -34,7 +41,9 @@ class ReleaseInfo:
return f"ReleaseInfo: {self.version}-{self.type}"
def find_previous_release(server_version, releases):
def find_previous_release(
server_version: Optional[Version], releases: List[ReleaseInfo]
) -> Tuple[bool, Optional[ReleaseInfo]]:
releases.sort(key=lambda x: x.version, reverse=True)
if server_version is None:
@ -42,16 +51,37 @@ def find_previous_release(server_version, releases):
for release in releases:
if release.version < server_version:
return True, release
# Check if the artifact exists on GitHub.
# It can be not true for a short period of time
# after creating a tag for a new release before uploading the packages.
if (
requests.head(
CLICKHOUSE_PACKAGE_URL.format(
version=release.version, type=release.type
),
timeout=10,
).status_code
!= 404
):
return True, release
logger.debug(
"The tag v%s-%s exists but the package is not yet available on GitHub",
release.version,
release.type,
)
return False, None
def get_previous_release(server_version):
def get_previous_release(server_version: Optional[Version]) -> Optional[ReleaseInfo]:
page = 1
found = False
while not found:
response = requests.get(CLICKHOUSE_TAGS_URL, {"page": page, "per_page": 100})
response = requests.get(
CLICKHOUSE_TAGS_URL, {"page": page, "per_page": 100}, timeout=10
)
if not response.ok:
raise Exception(
"Cannot load the list of tags from github: " + response.reason
@ -72,7 +102,11 @@ def get_previous_release(server_version):
return previous_release
if __name__ == "__main__":
def main():
logging.basicConfig(level=logging.INFO)
server_version = Version(input())
print(get_previous_release(server_version))
if __name__ == "__main__":
main()