Skip to content

Commit

Permalink
fix changelog generation
Browse files Browse the repository at this point in the history
A bunch of fixes related to testing changes in #17
  • Loading branch information
2bndy5 committed Oct 5, 2024
1 parent 0bc3601 commit 235f87e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/bump_version_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ jobs:
# here we need v3.10+
python-version: 3.x

- run: rustup update --no-self-update

- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@main

- name: Install git-cliff
run: pip install git-cliff
run: cargo binstall -y git-cliff --install-path org-repo

- name: increment version
working-directory: ${{ inputs.repo }}
Expand Down Expand Up @@ -83,3 +88,4 @@ jobs:
--notes-file ${{ steps.inc-ver.outputs.release-notes }}
--repo nRF24/${{ inputs.repo }}
--target ${{ inputs.branch }}
--title v${{ steps.inc-ver.outputs.new-version }}
32 changes: 22 additions & 10 deletions .github/workflows/increment_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

VERSION_TUPLE = Tuple[int, int, int]
COMPONENTS = ["major", "minor", "patch"]
GIT_CLIFF_CONFIG = Path(__file__).parent / "cliff.toml"
GIT_CLIFF_CONFIG = (Path(__file__).parent / "cliff.toml").resolve()
RELEASE_NOTES = GIT_CLIFF_CONFIG.with_name("ReleaseNotes.md")


Expand Down Expand Up @@ -44,7 +44,7 @@ def get_version() -> Tuple[VERSION_TUPLE, str]:
tags.reverse() # to iterate from newest to oldest versions
print("found version tags:")
for tag in tags:
print(" v" + ".".join([str(t) for t in tag]))
print(" v" + ".".join([str(t) for t in tag]), flush=True)

# get current branch
result = subprocess.run(["git", "branch"], capture_output=True, check=True)
Expand All @@ -70,9 +70,9 @@ def get_version() -> Tuple[VERSION_TUPLE, str]:
else:
raise RuntimeError(f"Found no v1.x tags for branch {branch}")
else:
print("treating branch", repr(branch), "as latest stable branch")
print("treating branch", repr(branch), "as latest stable branch", flush=True)
ver_tag = tags[0]
print("Current version:", ".".join([str(x) for x in ver_tag]))
print("Current version:", ".".join([str(x) for x in ver_tag]), flush=True)
return ver_tag, branch


Expand All @@ -95,18 +95,29 @@ def get_changelog(
anything was changed in the CHANGELOG.md"""
old = ""
changelog = Path("CHANGELOG.md")
if full and changelog.exists():
if not changelog.exists():
changelog.write_bytes(b"")
if full:
old = changelog.read_text(encoding="utf-8")
output = changelog
args = ["git-cliff", "--config", str(GIT_CLIFF_CONFIG), "--tag", tag]
exe_name = "git-cliff"
if environ.get("CI", "false") == "true":
exe_name = (
(GIT_CLIFF_CONFIG.parent.parent.parent / exe_name).resolve().as_posix()
)
args = [exe_name, "--github-repo", f"nRF24/{Path.cwd().name}"]
if not full:
args.append("--unreleased")
output = str(RELEASE_NOTES)
if branch == "v1.x":
args.extend(["--ignore-tags", "[v|V]?2\\..*"])
subprocess.run(
args + ["--output", output], env={"FIRST_COMMIT": first_commit}, check=True
)
env = {
"FIRST_COMMIT": first_commit,
"GIT_CLIFF_CONFIG": str(GIT_CLIFF_CONFIG),
"GIT_CLIFF_OUTPUT": str(output),
"GIT_CLIFF_TAG": tag,
}
subprocess.run(args, env=env, check=True)
if full:
new = changelog.read_text(encoding="utf-8")
changes = list(unified_diff(old, new))
Expand Down Expand Up @@ -187,10 +198,11 @@ def main() -> int:
get_changelog(ver_str, first_commit, full=False, branch=branch)
# generate complete changelog
made_changes = get_changelog(ver_str, first_commit, full=True, branch=branch)
print("Updated CHANGELOG.md:", made_changes)
print("New version:", ver_str)

if args.update_metadata:
made_changes = update_metadata_files(ver_str)
made_changes = made_changes or update_metadata_files(ver_str)
print("Metadata file(s) updated:", made_changes)

if "GITHUB_OUTPUT" in environ: # create an output variables for use in CI workflow
Expand Down

0 comments on commit 235f87e

Please sign in to comment.