Skip to content

Commit

Permalink
scripts: Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
SenZmaKi committed Aug 5, 2024
1 parent 4eae47b commit 1098250
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scripts/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def log_error(msg: str, exit=False) -> None:


@cache
def get_prev_version() -> str:
def get_prev_version(exit=True) -> str:
prev_version = ""
with open(PYPROJECT_FILE_PATH, "r") as f:
opt_version = VERSION_REGEX.search(f.read())
if opt_version is not None:
prev_version = opt_version.group(1)
if not prev_version:
log_error("Failed to get previous version", True)
log_error("Failed to get previous version", exit)
return prev_version


Expand Down
30 changes: 18 additions & 12 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,28 @@ def merge_branch() -> None:
subprocess.run("gh pr merge --auto --merge --delete-branch").check_returncode()


def add_change_log_link(release_notes: str) -> str:
prev_version = bump_version.get_prev_version()
def add_change_log_link(release_notes: str, previous_version: str | None) -> str:
new_version = bump_version.get_new_version()
if new_version == prev_version:
prev_version = input(
'Failed to get previous version number, manual input required (without the "v" prefix)\n> '
)
if not prev_version:
sys.exit()
if previous_version:
prev_version = previous_version
else:
prev_version = bump_version.get_prev_version(False)
if new_version == prev_version:
prev_version = input(
'Failed to get previous version number, manual input required (without the "v" prefix)\n> '
)
if not prev_version:
sys.exit()
change_log_link = (
f"**Full Changelog**: {REPO_URL}/compare/v{prev_version}...v{new_version}"
)
return f"{release_notes}\n\n{change_log_link}"


def get_release_notes(from_commits: bool) -> str:
def get_release_notes(from_commits: bool, previous_version: str | None) -> str:
with open(ROOT_DIR.joinpath("docs", "release-notes.md"), "r+") as f:
if not from_commits:
return add_change_log_link(f.read())
return add_change_log_link(f.read(), previous_version)
completed_process = subprocess.run(
f'git log --format="%s" master..{BRANCH_NAME}',
capture_output=True,
Expand All @@ -55,7 +58,7 @@ def get_release_notes(from_commits: bool) -> str:
release_notes = f"# Changes\n\n{completed_process.stdout}"
overwrite(f, release_notes)
git_commit("Generate release notes from commits").check_returncode()
return add_change_log_link(release_notes)
return add_change_log_link(release_notes, previous_version)


def publish_release(release_notes: str) -> None:
Expand Down Expand Up @@ -129,6 +132,9 @@ def main() -> None:
action="store_true",
help="Skip creating new branch",
)
parser.add_argument(
"-pv", "--previous_version", help='Previous version number (without the "v" prefix)', type=str
)
parsed = parser.parse_args()
if BRANCH_NAME == "master":
log_error("On master branch, switch to version branch", True)
Expand All @@ -144,7 +150,7 @@ def main() -> None:
if not parsed.skip_build_release:
log_info("Building release")
subprocess.run("poe build_release_ddl").check_returncode()
release_notes = get_release_notes(parsed.from_commits)
release_notes = get_release_notes(parsed.from_commits, parsed.previous_version)
if not parsed.skip_merge_branch:
log_info(f"Merging branch {BRANCH_NAME}")
merge_branch()
Expand Down

0 comments on commit 1098250

Please sign in to comment.