Skip to content

Commit

Permalink
Improve generate_changelog.py (#17)
Browse files Browse the repository at this point in the history
* See rerun-io/rerun#7844 for motivation
  • Loading branch information
emilk authored Oct 22, 2024
1 parent 1f3188c commit 98c9b34
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release Checklist

* [ ] Update `CHANGELOG.md` using `./scripts/generate_changelog.py --version 0.NEW.VERSION`
* [ ] Bump version numbers in `Cargo.toml` and run `cargo check`.
* [ ] `git commit -m 'Release 0.x.0 - summary'`
* [ ] `cargo publish --quiet -p new_project_name`
* [ ] `git tag -a 0.x.0 -m 'Release 0.x.0 - summary'`
* [ ] `git pull --tags && git tag -d latest && git tag -a latest -m 'Latest release' && git push --tags origin latest --force && git push origin main ; git push --tags`
* [ ] Do a GitHub release: https://github.com/rerun-io/new_repo_name/releases/new
34 changes: 32 additions & 2 deletions scripts/generate_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
import sys
from dataclasses import dataclass
from datetime import date
from typing import Any, Optional

import requests
Expand Down Expand Up @@ -110,13 +111,41 @@ def print_section(crate: str, items: list[str]) -> None:
print()


def commit_range(new_version: str) -> str:
parts = new_version.split(".")
assert len(parts) == 3, "Expected version to be on the format X.Y.Z"
major = int(parts[0])
minor = int(parts[1])
patch = int(parts[2])

if 0 < patch:
# A patch release.
# Include changes since last patch release.
# This assumes we've cherry-picked stuff for this release.
diff_since_version = f"0.{minor}.{patch - 1}"
elif 0 < minor:
# A minor release
# The diff should span everything since the last minor release.
# The script later excludes duplicated automatically, so we don't include stuff that
# was part of intervening patch releases.
diff_since_version = f"{major}.{minor - 1}.0"
else:
# A major release
# The diff should span everything since the last major release.
# The script later excludes duplicated automatically, so we don't include stuff that
# was part of intervening minor/patch releases.
diff_since_version = f"{major - 1}.{minor}.0"

return f"{diff_since_version}..HEAD"


def main() -> None:
parser = argparse.ArgumentParser(description="Generate a changelog.")
parser.add_argument("--commit-range", help="e.g. 0.1.0..HEAD", required=True)
parser.add_argument("--version", required=True, help="The version of the new release, e.g. 0.42.0")
args = parser.parse_args()

repo = Repo(".")
commits = list(repo.iter_commits(args.commit_range))
commits = list(repo.iter_commits(commit_range(args.version)))
commits.reverse() # Most recent last
commit_infos = list(map(get_commit_info, commits))

Expand Down Expand Up @@ -170,6 +199,7 @@ def main() -> None:
line = line[0].upper() + line[1:] # Upper-case first letter
prs[i] = line

print(f"## {args.version} - {date.today()}")
print()
print(f"Full diff at https://github.com/{OWNER}/{REPO}/compare/{args.commit_range}")
print()
Expand Down
1 change: 1 addition & 0 deletions scripts/template_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"clippy.toml",
"Cranky.toml",
"deny.toml",
"RELEASES.md",
"rust-toolchain",
"scripts/clippy_wasm/",
"scripts/clippy_wasm/clippy.toml",
Expand Down

0 comments on commit 98c9b34

Please sign in to comment.