Skip to content

Commit

Permalink
chore(build): fix computation of version number in bump_version.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed May 5, 2024
1 parent d50786c commit 487678a
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions bump_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from enum import Enum
from functools import lru_cache
from git import Repo, TagReference, Commit
import subprocess
import sys
Expand Down Expand Up @@ -32,7 +31,7 @@ def version_increment(majors: int, minors: int, patches: int, dev: int) -> Versi


def find_last_tag(repo: Repo) -> TagReference:
last_tag_name = repo.git.describe('--tags', '--abbrev=0')
last_tag_name = repo.git.describe('--tags', '--abbrev=0', '--match', '*.*.*', '--exclude', '*-*')
return repo.tags[last_tag_name]


Expand Down Expand Up @@ -78,29 +77,27 @@ def _poetry(*args):
return subprocess.run([sys.executable, "-m", "poetry", *args], capture_output=True, text=True).stdout.strip()


@lru_cache
def get_current_version() -> str:
return _poetry("version", "--short")


def update_version(increment: VersionIncrement, n_changes: int, apply: bool = False):
target = f"{get_current_version()}-dev{n_changes}" \
def update_version(from_version: str, increment: VersionIncrement, n_changes: int, apply: bool = False):
target = f"{from_version}-dev{n_changes}" \
if increment == VersionIncrement.DEVELOPMENT \
else increment.value
args = ["version", "--short", target] + ([] if apply else ['--dry-run'])
version = _poetry(*args)
log("hence, next version is: `", end='')
print(version + ('`' if LOGGING else ''))
get_current_version.cache_clear()


if __name__ == '__main__':
with Repo('.') as repo:
LOGGING = "--silent" not in sys.argv
last_tag = find_last_tag(repo)
current_version = get_current_version()
log(f"From commit {last_tag.commit.hexsha} (corresponding to v`{current_version}`):")
log(f"From commit {last_tag.commit.hexsha} (corresponding to v`{current_version}`, according to Poetry):")
commits = all_commits_up_to_tag(repo, )
version, n_changes = comput_version_increment_from(commits)
actually_apply = "--apply" in sys.argv
update_version(version, n_changes, actually_apply)
update_version(last_tag.name, version, n_changes, actually_apply)

0 comments on commit 487678a

Please sign in to comment.