mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Move version_arg to version_helper, add tests
This commit is contained in:
parent
11fe15be9e
commit
a7145cf087
@ -16,7 +16,6 @@ from commit_status_helper import post_commit_status
|
|||||||
from docker_images_check import DockerImage
|
from docker_images_check import DockerImage
|
||||||
from env_helper import CI, GITHUB_RUN_URL, RUNNER_TEMP, S3_BUILDS_BUCKET
|
from env_helper import CI, GITHUB_RUN_URL, RUNNER_TEMP, S3_BUILDS_BUCKET
|
||||||
from get_robot_token import get_best_robot_token, get_parameter_from_ssm
|
from get_robot_token import get_best_robot_token, get_parameter_from_ssm
|
||||||
from git_helper import removeprefix
|
|
||||||
from pr_info import PRInfo
|
from pr_info import PRInfo
|
||||||
from s3_helper import S3Helper
|
from s3_helper import S3Helper
|
||||||
from stopwatch import Stopwatch
|
from stopwatch import Stopwatch
|
||||||
@ -25,8 +24,7 @@ from version_helper import (
|
|||||||
ClickHouseVersion,
|
ClickHouseVersion,
|
||||||
get_tagged_versions,
|
get_tagged_versions,
|
||||||
get_version_from_repo,
|
get_version_from_repo,
|
||||||
get_version_from_string,
|
version_arg,
|
||||||
get_version_from_tag,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check")
|
TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check")
|
||||||
@ -114,22 +112,6 @@ def parse_args() -> argparse.Namespace:
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def version_arg(version: str) -> ClickHouseVersion:
|
|
||||||
version = removeprefix(version, "refs/tags/")
|
|
||||||
try:
|
|
||||||
return get_version_from_string(version)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
return get_version_from_tag(version)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
raise argparse.ArgumentTypeError(
|
|
||||||
f"version {version} does not match tag of plain version"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def auto_release_type(version: ClickHouseVersion, 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
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
import logging
|
||||||
import os.path as p
|
import os.path as p
|
||||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, ArgumentTypeError
|
||||||
from typing import Dict, List, Tuple, Union
|
from typing import Dict, List, Tuple, Union
|
||||||
|
|
||||||
from git_helper import Git, removeprefix
|
from git_helper import Git, removeprefix
|
||||||
@ -220,6 +220,20 @@ def get_version_from_tag(tag: str) -> ClickHouseVersion:
|
|||||||
return get_version_from_string(tag)
|
return get_version_from_string(tag)
|
||||||
|
|
||||||
|
|
||||||
|
def version_arg(version: str) -> ClickHouseVersion:
|
||||||
|
version = removeprefix(version, "refs/tags/")
|
||||||
|
try:
|
||||||
|
return get_version_from_string(version)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
return get_version_from_tag(version)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
raise ArgumentTypeError(f"version {version} does not match tag of plain version")
|
||||||
|
|
||||||
|
|
||||||
def get_tagged_versions() -> List[ClickHouseVersion]:
|
def get_tagged_versions() -> List[ClickHouseVersion]:
|
||||||
versions = []
|
versions = []
|
||||||
for tag in git.get_tags():
|
for tag in git.get_tags():
|
||||||
|
33
tests/ci/version_test.py
Normal file
33
tests/ci/version_test.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from argparse import ArgumentTypeError
|
||||||
|
|
||||||
|
import version_helper as vh
|
||||||
|
|
||||||
|
|
||||||
|
class TestFunctions(unittest.TestCase):
|
||||||
|
def test_version_arg(self):
|
||||||
|
cases = (
|
||||||
|
("0.0.0.0", vh.get_version_from_string("0.0.0.0")),
|
||||||
|
("1.1.1.2", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
("v1.1.1.2-lts", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
("v1.1.1.2-prestable", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
("v1.1.1.2-stable", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
("v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
("refs/tags/v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")),
|
||||||
|
)
|
||||||
|
for case in cases:
|
||||||
|
version = vh.version_arg(case[0])
|
||||||
|
self.assertEqual(case[1], version)
|
||||||
|
error_cases = (
|
||||||
|
"0.0.0",
|
||||||
|
"1.1.1.a",
|
||||||
|
"1.1.1.1.1",
|
||||||
|
"1.1.1.2-testing",
|
||||||
|
"v1.1.1.2-testin",
|
||||||
|
"refs/tags/v1.1.1.2-testin",
|
||||||
|
)
|
||||||
|
for case in error_cases:
|
||||||
|
with self.assertRaises(ArgumentTypeError):
|
||||||
|
version = vh.version_arg(case[0])
|
Loading…
Reference in New Issue
Block a user