Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
65fd607
WIP: changelog and versioning methods
MaciejKaras Jun 10, 2025
993753e
WIP: generate_changelog func
MaciejKaras Jun 10, 2025
f41c9f3
Working release notes generation
MaciejKaras Jun 10, 2025
30d5b04
Added tests for release notes generation
MaciejKaras Jun 11, 2025
a8e6782
Release with breaking change test
MaciejKaras Jun 11, 2025
6de3703
Added more releases
MaciejKaras Jun 12, 2025
c353737
Added release branch test cases
MaciejKaras Jun 12, 2025
c220f2e
Get the previous version based on current HEAD
MaciejKaras Jun 12, 2025
891d821
Added tests, gitgraph, docs and cmd input
MaciejKaras Jun 13, 2025
a2cdcb4
Add main method in versioning.py
MaciejKaras Jun 15, 2025
5465b98
Move main method to calculate_next_version.py
MaciejKaras Jun 16, 2025
20fded0
Optimize imports
MaciejKaras Jun 16, 2025
df195d1
Lint fix
MaciejKaras Jun 16, 2025
aebd634
Add changelog entry frontmatter text
MaciejKaras Jul 11, 2025
371499a
Added frontmatter validation
MaciejKaras Jul 13, 2025
a7d7f60
Script for generating changelog file
MaciejKaras Jul 13, 2025
136a939
Review fixes
MaciejKaras Jul 13, 2025
5dfa8cd
Review fixes v2
MaciejKaras Jul 14, 2025
ce49927
Review fixes v3
MaciejKaras Jul 14, 2025
240f2c9
Review fixes v4
MaciejKaras Jul 14, 2025
4a97699
Using ChangeEntry type
MaciejKaras Jul 15, 2025
76f0f74
Making release a module
MaciejKaras Jul 15, 2025
c9b6857
Fixing other kind of change issue + missing tests
MaciejKaras Jul 15, 2025
e51357b
Adding quotes to error message variables
MaciejKaras Jul 15, 2025
896db65
remove venv from .gitignore
MaciejKaras Jul 16, 2025
d55f322
fix unit tests
MaciejKaras Jul 16, 2025
5b35ab0
Adding changelog file for testing
MaciejKaras Jul 15, 2025
6723380
Adding GHA workflow
MaciejKaras Jul 15, 2025
a723387
Adding GHA workflow
MaciejKaras Jul 15, 2025
16b1285
Adding GHA workflow
MaciejKaras Jul 15, 2025
48f2507
Fixing GHA workflow
MaciejKaras Jul 15, 2025
bf50605
Removing changelog file
MaciejKaras Jul 15, 2025
5d066f7
Adding release notes action
MaciejKaras Jul 15, 2025
fcd74d6
test
MaciejKaras Jul 15, 2025
35a904d
wip
MaciejKaras Jul 15, 2025
5d72a98
Change permissions
MaciejKaras Jul 16, 2025
8eae2aa
Fix summary
MaciejKaras Jul 16, 2025
3a79629
Add more changes
MaciejKaras Jul 16, 2025
c9850f1
Update activity types
MaciejKaras Jul 16, 2025
2b484ba
Remove test changelog file
MaciejKaras Jul 16, 2025
a6c3360
Fix missing pipefail
MaciejKaras Jul 16, 2025
d6e789d
Added documentation for changelogs
MaciejKaras Jul 16, 2025
8a5cd18
Remove unnecessary default value
MaciejKaras Jul 17, 2025
d956a13
Don't post PR comment on forks - the token has only read permissions
MaciejKaras Jul 17, 2025
0286ddf
Add disclaimer to PR comment
MaciejKaras Jul 17, 2025
4d81905
Merge branch 'master' into maciejk/ar-gha-integration
MaciejKaras Jul 28, 2025
b14bd5c
Review fixes
MaciejKaras Jul 28, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add main method in versioning.py
  • Loading branch information
MaciejKaras committed Jul 16, 2025
commit a2cdcb4de9713b1f81ffb3388809ee7fda431890
1 change: 1 addition & 0 deletions scripts/release/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def git_repo(change_log_path: str = CHANGELOG_PATH) -> Repo:
"""
Create a temporary git repository for testing.
Visual representation of the repository structure is in test_git_repo.mmd (mermaid/gitgraph https://mermaid.js.org/syntax/gitgraph.html).
Whenever you modify or add new commits please update the git graph as well.
"""

repo_dir = tempfile.mkdtemp()
Expand Down
29 changes: 6 additions & 23 deletions scripts/release/release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from jinja2 import Template

from scripts.release.changelog import CHANGELOG_PATH, get_changelog_entries, ChangeType
from scripts.release.versioning import calculate_next_release_version, find_previous_version_tag
from scripts.release.versioning import calculate_next_release_version, find_previous_version, \
calculate_next_version_with_changelog


def generate_release_notes(
Expand All @@ -28,29 +29,11 @@ def generate_release_notes(
"""
repo = Repo(repository_path)

previous_version_tag = find_previous_version_tag(repo)
changelog, version = calculate_next_version_with_changelog(repo, changelog_sub_path, initial_commit_sha,
initial_version)

# If there is no previous version tag, we start with the initial commit
if not previous_version_tag:
# If no initial commit SHA provided, use the first commit in the repository
if not initial_commit_sha:
initial_commit_sha = list(repo.iter_commits(reverse=True))[0].hexsha

previous_version_commit = repo.commit(initial_commit_sha)
else:
previous_version_commit = previous_version_tag.commit

changelog: list = get_changelog_entries(previous_version_commit, repo, changelog_sub_path)
changelog_entries = list[ChangeType](map(lambda x: x[0], changelog))

# If there is no previous version tag, we start with the initial version tag
if not previous_version_tag:
version = initial_version
else:
version = calculate_next_release_version(previous_version_tag.name, changelog_entries)

with open('scripts/release/release_notes_tpl.md', "r") as f:
template = Template(f.read())
with open('scripts/release/release_notes_tpl.md', "r") as file:
template = Template(file.read())

parameters = {
'version': version,
Expand Down
62 changes: 60 additions & 2 deletions scripts/release/versioning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
import argparse
import pathlib
import sys

import semver
from git import Repo, TagReference
from git import Repo, TagReference, Commit

from scripts.release.changelog import ChangeType, get_changelog_entries


def calculate_next_version_with_changelog(
repo: Repo,
changelog_sub_path: str,
initial_commit_sha: str | None,
initial_version: str) -> (str, list[tuple[ChangeType, str]]):
previous_version_tag, previous_version_commit = find_previous_version(repo, initial_commit_sha)

changelog: list[tuple[ChangeType, str]] = get_changelog_entries(previous_version_commit, repo, changelog_sub_path)
changelog_types = list[ChangeType](map(lambda x: x[0], changelog))

# If there is no previous version tag, we start with the initial version tag
if not previous_version_tag:
version = initial_version
else:
version = calculate_next_release_version(previous_version_tag.name, changelog_types)

return version, changelog


from scripts.release.changelog import ChangeType
def find_previous_version(repo: Repo, initial_commit_sha: str = None) -> (TagReference | None, Commit):
"""Find the most recent version that is an ancestor of the current HEAD commit."""

previous_version_tag = find_previous_version_tag(repo)

# If there is no previous version tag, we start with the initial commit
if not previous_version_tag:
# If no initial commit SHA provided, use the first commit in the repository
if not initial_commit_sha:
initial_commit_sha = list(repo.iter_commits(reverse=True))[0].hexsha

return None, repo.commit(initial_commit_sha)

return previous_version_tag, previous_version_tag.commit


def find_previous_version_tag(repo: Repo) -> TagReference | None:
Expand Down Expand Up @@ -32,3 +71,22 @@ def calculate_next_release_version(previous_version_str: str, changelog: list[Ch
return str(previous_version.bump_minor())

return str(previous_version.bump_patch())


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--path", action="store", default=".", type=pathlib.Path,
help="Path to the Git repository. Default is the current directory '.'")
parser.add_argument("--changelog_path", default="changelog/", action="store", type=str,
help="Path to the changelog directory relative to the repository root. Default is 'changelog/'")
parser.add_argument("--initial_commit_sha", action="store", type=str,
help="SHA of the initial commit to start from if no previous version tag is found.")
parser.add_argument("--initial_version", default="1.0.0", action="store", type=str,
help="Version to use if no previous version tag is found. Default is '1.0.0'")
parser.add_argument("--output", "-o", type=pathlib.Path)
args = parser.parse_args()

_, version = calculate_next_version_with_changelog(args.path, args.changelog_path, args.initial_commit_sha,
args.initial_version)

sys.stdout.write(version)