Fix automatic bucket prefix for master

This commit is contained in:
Mikhail f. Shiryaev 2022-04-01 17:53:43 +02:00
parent b56beeca9d
commit 6b83e2b2a7
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 36 additions and 31 deletions

View File

@ -10,6 +10,7 @@ from typing import List, Tuple
from github import Github from github import Github
from build_check import get_release_or_pr
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
from commit_status_helper import post_commit_status from commit_status_helper import post_commit_status
from docker_images_check import DockerImage from docker_images_check import DockerImage
@ -20,10 +21,10 @@ from s3_helper import S3Helper
from stopwatch import Stopwatch from stopwatch import Stopwatch
from upload_result_helper import upload_results from upload_result_helper import upload_results
from version_helper import ( from version_helper import (
ClickHouseVersion,
get_tagged_versions, get_tagged_versions,
get_version_from_repo, get_version_from_repo,
get_version_from_string, get_version_from_string,
validate_version,
) )
TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check") TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check")
@ -110,42 +111,40 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args() return parser.parse_args()
def version_arg(version: str) -> str: def version_arg(version: str) -> ClickHouseVersion:
try: try:
validate_version(version) return get_version_from_string(version)
return version
except ValueError as e: except ValueError as e:
raise argparse.ArgumentTypeError(e) raise argparse.ArgumentTypeError(e)
def auto_release_type(version: str, release_type: str) -> str: def auto_release_type(version: ClickHouseVersion, release_type: str) -> str:
if release_type != "auto": if release_type != "auto":
return release_type return release_type
current_version = get_version_from_string(version)
git_versions = get_tagged_versions() git_versions = get_tagged_versions()
reference_version = git_versions[0] reference_version = git_versions[0]
for i in reversed(range(len(git_versions))): for i in reversed(range(len(git_versions))):
if git_versions[i] < current_version: if git_versions[i] < version:
if i == len(git_versions) - 1: if i == len(git_versions) - 1:
return "latest" return "latest"
reference_version = git_versions[i + 1] reference_version = git_versions[i + 1]
break break
if current_version.major < reference_version.major: if version.major < reference_version.major:
return "major" return "major"
if current_version.minor < reference_version.minor: if version.minor < reference_version.minor:
return "minor" return "minor"
if current_version.patch < reference_version.patch: if version.patch < reference_version.patch:
return "patch" return "patch"
raise ValueError( raise ValueError(
"Release type 'tweak' is not supported for " "Release type 'tweak' is not supported for "
f"{current_version.string} < {reference_version.string}" f"{version.string} < {reference_version.string}"
) )
def gen_tags(version: str, release_type: str) -> List[str]: def gen_tags(version: ClickHouseVersion, release_type: str) -> List[str]:
""" """
22.2.2.2 + latest: 22.2.2.2 + latest:
- latest - latest
@ -168,8 +167,7 @@ def gen_tags(version: str, release_type: str) -> List[str]:
22.2.2.2 + head: 22.2.2.2 + head:
- head - head
""" """
validate_version(version) parts = version.string.split(".")
parts = version.split(".")
tags = [] tags = []
if release_type == "latest": if release_type == "latest":
tags.append(release_type) tags.append(release_type)
@ -201,7 +199,12 @@ def buildx_args(bucket_prefix: str, arch: str) -> List[str]:
def build_and_push_image( def build_and_push_image(
image: DockerImage, push: bool, bucket_prefix: str, os: str, tag: str, version: str image: DockerImage,
push: bool,
bucket_prefix: str,
os: str,
tag: str,
version: ClickHouseVersion,
) -> List[Tuple[str, str]]: ) -> List[Tuple[str, str]]:
result = [] result = []
if os != "ubuntu": if os != "ubuntu":
@ -228,7 +231,7 @@ def build_and_push_image(
cmd_args.extend( cmd_args.extend(
[ [
f"--metadata-file={metadata_path}", f"--metadata-file={metadata_path}",
f"--build-arg=VERSION='{version}'", f"--build-arg=VERSION='{version.string}'",
"--progress=plain", "--progress=plain",
f"--file={dockerfile}", f"--file={dockerfile}",
image.full_path, image.full_path,
@ -293,9 +296,10 @@ def main():
pr_info = None pr_info = None
if CI: if CI:
pr_info = PRInfo() pr_info = PRInfo()
release_or_pr = get_release_or_pr(pr_info, {"package_type": ""}, args.version)
args.bucket_prefix = ( args.bucket_prefix = (
f"https://s3.amazonaws.com/{S3_BUILDS_BUCKET}/" f"https://s3.amazonaws.com/{S3_BUILDS_BUCKET}/"
f"{pr_info.number}/{pr_info.sha}" f"{release_or_pr}/{pr_info.sha}"
) )
if args.push: if args.push:

View File

@ -227,19 +227,20 @@ class TestDockerImageCheck(unittest.TestCase):
class TestDockerServer(unittest.TestCase): class TestDockerServer(unittest.TestCase):
def test_gen_tags(self): def test_gen_tags(self):
version = get_version_from_string("22.2.2.2")
cases = ( cases = (
(("22.2.2.2", "latest"), ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]), ("latest", ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "major"), ["22", "22.2", "22.2.2", "22.2.2.2"]), ("major", ["22", "22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "minor"), ["22.2", "22.2.2", "22.2.2.2"]), ("minor", ["22.2", "22.2.2", "22.2.2.2"]),
(("22.2.2.2", "patch"), ["22.2.2", "22.2.2.2"]), ("patch", ["22.2.2", "22.2.2.2"]),
(("22.2.2.2", "head"), ["head"]), ("head", ["head"]),
) )
for case in cases: for case in cases:
version, release_type = case[0] release_type = case[0]
self.assertEqual(case[1], ds.gen_tags(version, release_type)) self.assertEqual(case[1], ds.gen_tags(version, release_type))
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
ds.gen_tags("22.2.2.2", "auto") ds.gen_tags(version, "auto")
@patch("docker_server.get_tagged_versions") @patch("docker_server.get_tagged_versions")
def test_auto_release_type(self, mock_tagged_versions: MagicMock): def test_auto_release_type(self, mock_tagged_versions: MagicMock):
@ -251,13 +252,13 @@ class TestDockerServer(unittest.TestCase):
get_version_from_string("2.2.2.1"), get_version_from_string("2.2.2.1"),
] ]
cases = ( cases = (
("1.0.1.1", "minor"), (get_version_from_string("1.0.1.1"), "minor"),
("1.1.2.1", "minor"), (get_version_from_string("1.1.2.1"), "minor"),
("1.3.1.1", "major"), (get_version_from_string("1.3.1.1"), "major"),
("2.1.2.1", "minor"), (get_version_from_string("2.1.2.1"), "minor"),
("2.2.1.3", "patch"), (get_version_from_string("2.2.1.3"), "patch"),
("2.2.3.1", "latest"), (get_version_from_string("2.2.3.1"), "latest"),
("2.3.1.1", "latest"), (get_version_from_string("2.3.1.1"), "latest"),
) )
_ = get_tagged_versions() _ = get_tagged_versions()
for case in cases: for case in cases: