1313next-rc, promote. When several changesets touch the same package, the
1414largest bump wins (an explicit X-rc wins over next-rc). Mixing stable and
1515rc 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
1823from __future__ import annotations
1924
25+ import json
2026import os
2127import pathlib
2228import re
2733from update_versions import PACKAGES , do_bump , do_prerelease , read_version
2834
2935CHANGESET_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
3240PACKAGE_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)
168190def 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