Merge pull request #46821 from ClickHouse/stateless-cmake-version

Stateless cmake version
This commit is contained in:
Mikhail f. Shiryaev 2023-02-24 16:24:32 +01:00 committed by GitHub
commit de4ee65c85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 20 deletions

View File

@ -199,6 +199,10 @@ class Release:
raise ValueError(
"The relese type must be 'major' for minor versions>=12"
)
if self._version.minor < 12 and self.release_type == "major":
raise ValueError(
"The relese type must be 'minor' for minor versions<12"
)
with self._checkout(self.release_commit, True):
# Checkout to the commit, it will provide the correct current version
@ -265,7 +269,11 @@ class Release:
f"for {self.release_type} release"
)
def _commit_cmake_contributors(self, version: ClickHouseVersion) -> None:
def _update_cmake_contributors(
self, version: ClickHouseVersion, reset_tweak: bool = True
) -> None:
if reset_tweak:
version = version.reset_tweak()
update_cmake_version(version)
update_contributors(raise_error=True)
if self.dry_run:
@ -274,9 +282,15 @@ class Release:
self.run(f"git diff '{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'"),
)
self.run(f"git checkout '{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'")
def _commit_cmake_contributors(
self, version: ClickHouseVersion, reset_tweak: bool = True
) -> None:
if reset_tweak:
version = version.reset_tweak()
self.run(
f"git commit -m 'Update version to {version.string}' "
f"'{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'",
f"git commit '{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}' "
f"-m 'Update autogenerated version to {version.string} and contributors'",
dry_run=self.dry_run,
)
@ -321,27 +335,12 @@ class Release:
with self._create_gh_release(False):
self.version = self.version.update(self.release_type)
self.version.with_description(version_type)
update_cmake_version(self.version)
update_contributors(raise_error=True)
if self.dry_run:
logging.info(
"Dry running, resetting the following changes in the repo:\n%s",
self.run(
f"git diff '{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'"
),
)
self.run(f"git checkout '{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'")
self._update_cmake_contributors(self.version)
# Checkouting the commit of the branch and not the branch itself,
# then we are able to skip rollback
with self._checkout(f"{self.release_branch}^0", False):
current_commit = self.run("git rev-parse HEAD")
self.run(
f"git commit -m "
f"'Update version to {self.version.string}' "
f"'{self.CMAKE_PATH}' '{self.CONTRIBUTORS_PATH}'",
dry_run=self.dry_run,
)
self._commit_cmake_contributors(self.version)
with self._push(
"HEAD", with_rollback_on_fail=False, remote_ref=self.release_branch
):
@ -406,6 +405,7 @@ class Release:
if version_type == VersionType.LTS:
pr_labels += " --label release-lts"
new_version.with_description(version_type)
self._update_cmake_contributors(new_version)
self._commit_cmake_contributors(new_version)
with self._push(self.release_branch):
with self._create_gh_label(
@ -434,6 +434,7 @@ class Release:
self.read_version()
self.version = self.version.update(self.release_type)
self.version.with_description(VersionType.TESTING)
self._update_cmake_contributors(self.version)
self._commit_cmake_contributors(self.version)
with self._push(helper_branch):
body_file = get_abs_path(".github/PULL_REQUEST_TEMPLATE.md")

View File

@ -88,6 +88,13 @@ class ClickHouseVersion:
self.major, self.minor, self.patch + 1, self.revision, self._git
)
def reset_tweak(self) -> "ClickHouseVersion":
if self._git is not None:
self._git.update()
return ClickHouseVersion(
self.major, self.minor, self.patch, self.revision, self._git, "1"
)
@property
def major(self) -> int:
return self._major