Skip to content

Commit

Permalink
[CodeBuild] actually commit the version check script
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneKress79789 committed Dec 19, 2023
1 parent a0f635d commit f54ba3e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/check_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/prepare_poetry_env
- name: Check Release
run: ./scripts/build/check_release.sh
run: ./scripts/check_release.sh
50 changes: 50 additions & 0 deletions scripts/check_release_version.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit f54ba3e

Please sign in to comment.