Skip to content

Commit 374376c

Browse files
cloudwebrtcclaude
andcommitted
ci: keep rc changesets until promote and list them in its release notes
Changesets used by an rc release are kept and recorded in .changeset/pre.json instead of being deleted. Later runs skip them, and the package's next stable release (normally promote) lists them in its release notes and deletes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9aa7d98 commit 374376c

2 files changed

Lines changed: 60 additions & 9 deletions

File tree

‎.changeset/README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ anything else, is rejected. Only rc types are allowed on branches other than
3838
the check.
3939
2. On each push to `main`, **Package Release** applies all pending changesets
4040
and opens (or updates) the `Release: ...` PR with the version bumps and
41-
release notes, then deletes the changesets it used.
41+
release notes, then deletes the changesets it used. Changesets used by an
42+
rc release are kept instead (and recorded in `.changeset/pre.json`) until
43+
that package's next stable release, normally `promote`, whose release notes
44+
then list every change since the last stable version.
4245
3. Merging that release PR tags each bumped package, publishes it to PyPI and
4346
creates its GitHub Release.
4447

‎.github/changesets.py‎

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313
next-rc, promote. When several changesets touch the same package, the
1414
largest bump wins (an explicit X-rc wins over next-rc). Mixing stable and
1515
rc bumps, or combining promote with anything else, is an error.
16+
17+
Changesets used by an rc release are kept and recorded in .changeset/pre.json
18+
(package -> file names) instead of being deleted, so later runs skip them. The
19+
package's next stable release (normally promote) lists them in its release
20+
notes and deletes them.
1621
"""
1722

1823
from __future__ import annotations
1924

25+
import json
2026
import os
2127
import pathlib
2228
import re
@@ -27,6 +33,8 @@
2733
from update_versions import PACKAGES, do_bump, do_prerelease, read_version
2834

2935
CHANGESET_DIR = pathlib.Path(".changeset")
36+
# Changesets already released in an rc, kept until the package's stable release
37+
PRE_STATE = CHANGESET_DIR / "pre.json"
3038

3139
# Names accepted in changeset frontmatter -> key in PACKAGES
3240
PACKAGE_ALIASES = {
@@ -140,6 +148,20 @@ def changeset_origin(path: pathlib.Path, repo: str | None) -> str:
140148
return f" ({sha[:7]})"
141149

142150

151+
def kept_entries(names: list[str], package: str, repo: str | None) -> list[str]:
152+
"""Release-note entries for this package from changesets kept since its rc releases."""
153+
entries = []
154+
for name in names:
155+
path = CHANGESET_DIR / name
156+
if not path.exists():
157+
click.echo(f"warning: kept changeset {path} is missing", err=True)
158+
continue
159+
bumps, summary = parse_changeset(path)
160+
if summary and package in bumps:
161+
entries.append(f"`{bumps[package]}` {summary}{changeset_origin(path, repo)}")
162+
return entries
163+
164+
143165
@click.command()
144166
@click.option(
145167
"--rc-only",
@@ -166,12 +188,20 @@ def changeset_origin(path: pathlib.Path, repo: str | None) -> str:
166188
help="Only validate the pending changesets; don't change any file.",
167189
)
168190
def main(rc_only: bool, notes: pathlib.Path | None, repo: str | None, check: bool) -> None:
169-
files = sorted(p for p in CHANGESET_DIR.glob("*.md") if p.name.lower() != "readme.md")
191+
pre: dict[str, list[str]] = json.loads(PRE_STATE.read_text()) if PRE_STATE.exists() else {}
192+
kept = {name for names in pre.values() for name in names}
193+
files = sorted(
194+
p
195+
for p in CHANGESET_DIR.glob("*.md")
196+
if p.name.lower() != "readme.md" and p.name not in kept
197+
)
170198

171199
kinds: dict[str, set[str]] = {}
172200
summaries: dict[str, list[str]] = {}
201+
packages_of: dict[str, set[str]] = {}
173202
for path in files:
174203
bumps, summary = parse_changeset(path)
204+
packages_of[path.name] = set(bumps)
175205
if summary and not check:
176206
summary += changeset_origin(path, repo)
177207
for package, kind in bumps.items():
@@ -192,7 +222,7 @@ def main(rc_only: bool, notes: pathlib.Path | None, repo: str | None, check: boo
192222
validate(package, kind)
193223

194224
if check:
195-
click.echo(f"{len(files)} changeset(s) valid.")
225+
click.echo(f"{len(files)} changeset(s) valid ({len(kept)} kept from rc releases).")
196226
for package in PACKAGES:
197227
if package in resolved:
198228
cur = read_version(pathlib.Path(PACKAGES[package]))
@@ -204,17 +234,35 @@ def main(rc_only: bool, notes: pathlib.Path | None, repo: str | None, check: boo
204234
for package in PACKAGES: # stable order
205235
if package not in resolved:
206236
continue
207-
apply(package, resolved[package])
237+
kind = resolved[package]
238+
apply(package, kind)
208239
version = read_version(pathlib.Path(PACKAGES[package]))
209240
released.append(f"{package} v{version}")
210-
lines.append(f"## {package} v{version} ({resolved[package]})\n")
211-
for summary in summaries.get(package, []):
241+
lines.append(f"## {package} v{version} ({kind})\n")
242+
entries = summaries.get(package, [])
243+
if kind in RC or kind == "next-rc":
244+
# Keep this rc's changesets for the stable release notes.
245+
pre.setdefault(package, []).extend(
246+
p.name for p in files if package in packages_of[p.name]
247+
)
248+
else:
249+
# A stable release (normally promote) also lists the changesets
250+
# kept since this package's rc releases.
251+
entries = kept_entries(pre.pop(package, []), package, repo) + entries
252+
for summary in entries:
212253
lines.append("- " + summary.replace("\n", "\n "))
213254
lines.append("")
214255

215-
# Changesets are consumed once applied (including ones listing no package).
216-
for path in files:
217-
path.unlink()
256+
# Changesets are consumed once applied (including ones listing no package),
257+
# except those still kept for a package's stable release.
258+
still_kept = {name for names in pre.values() for name in names}
259+
for name in {p.name for p in files} | kept:
260+
if name not in still_kept:
261+
(CHANGESET_DIR / name).unlink(missing_ok=True)
262+
if pre:
263+
PRE_STATE.write_text(json.dumps(pre, indent=2, sort_keys=True) + "\n")
264+
else:
265+
PRE_STATE.unlink(missing_ok=True)
218266

219267
if notes is not None:
220268
notes.write_text("\n".join(lines))

0 commit comments

Comments
 (0)