Skip to content

Commit

Permalink
patch: Format _get_release_semantic_version.py (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical authored Apr 20, 2023
1 parent 85f49cf commit dcfb65e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions _get_release_semantic_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,29 @@
# Get last release version
# Example: "foobar Latest v1.1.2 2023-02-15T17:50:06Z"
last_release = subprocess.check_output(
["gh", "release", "list", "--limit", "1", "--exclude-drafts", "--exclude-pre-releases"],
[
"gh",
"release",
"list",
"--limit",
"1",
"--exclude-drafts",
"--exclude-pre-releases",
],
encoding="utf-8",
)
last_release_version = last_release.split("\t")[2]
assert re.fullmatch(
r"v[0-9]+\.[0-9]+\.[0-9]+", last_release_version
), f"Invalid version format {last_release_version=}"
major, minor, patch = (int(component) for component in last_release_version[1:].split("."))
major, minor, patch = (
int(component) for component in last_release_version[1:].split(".")
)

# Get prefixes (see CONTRIBUTING.md) of commits since last release
commits_since_last_release = subprocess.check_output(
["git", "log", f"{last_release_version}..HEAD", "--pretty=format:%s"], encoding="utf-8"
["git", "log", f"{last_release_version}..HEAD", "--pretty=format:%s"],
encoding="utf-8",
).splitlines()
prefixes = set()
for commit_subject in commits_since_last_release:
Expand All @@ -40,7 +51,9 @@
elif "patch" in prefixes:
patch += 1
else:
raise ValueError("No commits since last release with valid prefix (see CONTRIBUTING.md).")
raise ValueError(
"No commits since last release with valid prefix (see CONTRIBUTING.md)."
)

output = f"full_version=v{major}.{minor}.{patch}\nmajor_version=v{major}"
print(output)
Expand Down

0 comments on commit dcfb65e

Please sign in to comment.