diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 713401613d..d13b3febc7 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -20,6 +20,7 @@ env: permissions: contents: write + pull-requests: write jobs: fetch-versions: @@ -238,11 +239,26 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Bump Version + if: github.event.inputs.release_type == 'dev' + id: bump-version + run: | + python tools/release/bump_version.py + - uses: stefanzweifel/git-auto-commit-action@v5 + if: github.event.inputs.release_type == 'dev' with: - file_pattern: '*/version.json' + branch: "feature/update-dev-version-${{ github.run_id }}" + create_branch: 'true' + file_pattern: '**/version.json' commit_message: Update version to ${{ needs.fetch-versions.outputs.NEW_VERSION }} + - name: create pull request + if: github.event.inputs.release_type == 'dev' + run: gh pr create -B develop -H "feature/update-dev-version-${{ github.run_id }}" --title 'Update Dev Version' --body 'Created by Github action' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Reset changes run: | git reset --hard HEAD diff --git a/tools/release/bump_version.py b/tools/release/bump_version.py new file mode 100644 index 0000000000..575e6cfbf6 --- /dev/null +++ b/tools/release/bump_version.py @@ -0,0 +1,97 @@ +# Copyright 2021-2024 Avaiga Private Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +import json +import os +import re +from dataclasses import asdict, dataclass +from typing import Optional + + +@dataclass +class Version: + major: str + minor: str + patch: str + ext: Optional[str] = None + + def bump_ext_version(self) -> None: + if not self.ext: + return + reg = re.compile(r"[0-9]+$") + num = reg.findall(self.ext)[0] + + self.ext = self.ext.replace(num, str(int(num) + 1)) + + def validate_suffix(self, suffix="dev"): + if suffix not in self.ext: + raise Exception(f"Version does not contain suffix {suffix}") + + @property + def name(self) -> str: + """returns a string representation of a version""" + return f"{self.major}.{self.minor}.{self.patch}" + + @property + def dev_name(self) -> str: + """returns a string representation of a version""" + return f"{self.name}.{self.ext}" + + def __str__(self) -> str: + """returns a string representation of a version""" + version_str = f"{self.major}.{self.minor}.{self.patch}" + if self.ext: + version_str = f"{version_str}.{self.ext}" + return version_str + + +def __load_version_from_path(base_path: str) -> Version: + """Load version.json file from base path.""" + with open(os.path.join(base_path, "version.json")) as version_file: + data = json.load(version_file) + return Version(**data) + + +def __write_version_to_path(base_path: str, version: Version) -> None: + with open(os.path.join(base_path, "version.json"), "w") as version_file: + json.dump(asdict(version), version_file) + + +def extract_version(base_path: str) -> Version: + """ + Load version.json file from base path and return the version string. + """ + return __load_version_from_path(base_path) + + +def bump_ext_version(version: Version, _base_path: str) -> None: + version.bump_ext_version() + __write_version_to_path(_base_path, version) + + + +if __name__ == "__main__": + paths = ( + [ + f"taipy{os.sep}common", + f"taipy{os.sep}core", + f"taipy{os.sep}rest", + f"taipy{os.sep}gui", + f"taipy{os.sep}templates", + "taipy", + ] + ) + + for _path in paths: + _version = extract_version(_path) + bump_ext_version(_version, _path) + print(f"NEW_VERSION={_version.dev_name}") + diff --git a/tools/release/setup_version.py b/tools/release/setup_version.py index 15580aafa6..d5d35e7d0a 100644 --- a/tools/release/setup_version.py +++ b/tools/release/setup_version.py @@ -77,12 +77,13 @@ def __setup_dev_version(version: Version, _base_path: str, name: Optional[str] = version.validate_suffix() name = f"{name}_VERSION" if name else "VERSION" + print(f"{name}={version.dev_name}") # noqa: T201 - version.bump_ext_version() +def bump_ext_version(version: Version, _base_path: str) -> None: + version.bump_ext_version() __write_version_to_path(_base_path, version) - print(f"NEW_{name}={version.dev_name}") # noqa: T201 def __setup_prod_version(version: Version, target_version: str, branch_name: str, name: str = None) -> None: