From f54ba3e1dc97254d952cdbfc679376b852a6e9fa Mon Sep 17 00:00:00 2001 From: MarleneKress79789 Date: Tue, 19 Dec 2023 13:29:45 +0100 Subject: [PATCH] [CodeBuild] actually commit the version check script --- .github/workflows/check_version.yaml | 2 +- scripts/check_release_version.py | 50 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/check_release_version.py diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml index c3fd7505..c08f4f5e 100644 --- a/.github/workflows/check_version.yaml +++ b/.github/workflows/check_version.yaml @@ -11,4 +11,4 @@ jobs: fetch-depth: 0 - uses: ./.github/actions/prepare_poetry_env - name: Check Release - run: ./scripts/build/check_release.sh \ No newline at end of file + run: ./scripts/check_release.sh \ No newline at end of file diff --git a/scripts/check_release_version.py b/scripts/check_release_version.py new file mode 100644 index 00000000..3bde41a6 --- /dev/null +++ b/scripts/check_release_version.py @@ -0,0 +1,50 @@ +import re +from pathlib import Path + +from git import Repo +import toml + + +def get_git_version(): + repo = Repo() + assert not repo.bare + tag_strings = [t.name for t in repo.tags] + tag_strings.sort(reverse=True) + + latest_tag = tag_strings[0].strip() + assert len(latest_tag) > 0 + return latest_tag + + +def get_poetry_version(): + parsed_toml = toml.load('pyproject.toml') + return parsed_toml["tool"]["poetry"]["version"].strip() + + +def get_change_log_version(): + # Path overloads __truediv__ + with open(Path(__file__).parent / ".." / ".." / "doc" / "changes" / "changelog.md") as changelog: + changelog_str = changelog.read() + # Search for the FIRST pattern like: "* [0.5.0](changes_0.5.0.md)" in the changelog file. + # Note that we encapsulate the [(0.5.0)] with parenthesis, which tells re to return the matching string as group + version_match = re.search(r"\* \[([0-9]+.[0-9]+.[0-9]+)]\(\S+\)", changelog_str) + return version_match.groups()[0] + + +if __name__ == '__main__': + poetry_version = get_poetry_version() + latest_tag = get_git_version() + changelog_version = get_change_log_version() + print(f'Changelog version: "{changelog_version}"') + print(f'Current version: "{poetry_version}"') + print(f'Latest git tag: "{latest_tag}"') + + # We expect that the current version in pyproject.toml is always greater than the latest tag. + # Thus we avoid creating a release without having the version number updated. + if not poetry_version > latest_tag: + raise ValueError("Poetry version needs to be updated!") + + if changelog_version != poetry_version: + raise ValueError("Poetry version differs from Changelog version!") + + print("Everything looks good") \ No newline at end of file