-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* add version check and prepare release
- Loading branch information
1 parent
237e4ae
commit fe25840
Showing
5 changed files
with
88 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Check if versions are consistent | ||
|
||
on: pull_request | ||
|
||
jobs: | ||
check-version-numbers: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: ./.github/actions/prepare_poetry_env | ||
- name: Check Release | ||
run: poetry run python3 -u "./scripts/check_release_version.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
from packaging import version | ||
|
||
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 version.parse(poetry_version) > version.parse(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") |