From 2d7fe8dc675200167f5ec497c432eb9114cbf2b6 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 2 Dec 2026 13:17:46 +0100 Subject: [PATCH 1/3] changelog: one fragment file per change instead of a shared latest.md Every PR appended its entry to the same spot in docs/changelog/versions/latest.md, so any two PRs with changelog entries conflicted and needed a rebase and force push. Each PR now adds docs/changelog/unreleased/
/.md. docs/changelog/assemble.py renders them; the docs build generates latest.md from them (no longer checked in), and bump_version.py writes them to versions/.md and deletes them at release. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Konrad Breitsprecher --- .github/pull_request_template.md | 2 +- .gitignore | 2 + SilKit/ci/bump_version.py | 38 +++--- SilKit/ci/check_files_changed.py | 2 +- docs/CMakeLists.txt | 4 + docs/changelog/assemble.py | 127 ++++++++++++++++++ docs/changelog/unreleased/README.md | 35 +++++ .../changed/build-identity-settings.md | 4 + .../changed/sim-step-handler-switch.md | 3 + .../changed/version-macros-committed.md | 3 + docs/changelog/versions/latest.md | 14 -- docs/conf.py | 7 + docs/development/release.md | 23 +++- 13 files changed, 226 insertions(+), 38 deletions(-) create mode 100644 docs/changelog/assemble.py create mode 100644 docs/changelog/unreleased/README.md create mode 100644 docs/changelog/unreleased/changed/build-identity-settings.md create mode 100644 docs/changelog/unreleased/changed/sim-step-handler-switch.md create mode 100644 docs/changelog/unreleased/changed/version-macros-committed.md delete mode 100644 docs/changelog/versions/latest.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 540e39090..852e83199 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -27,7 +27,7 @@ SPDX-License-Identifier: MIT ## Developer checklist (address before review) -- [ ] Changelog.md updated +- [ ] Changelog fragment added in `docs/changelog/unreleased/` (see the README there) - [ ] Prepared update for depending repositories - [ ] Documentation updated (public API changes only) - [ ] API docstrings updated (public API changes only) diff --git a/.gitignore b/.gitignore index aca9c1b64..df091eb2e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ CMakeUserPresets.json #ignore temporary merge conflict backup files *.orig +# generated from docs/changelog/unreleased/ by docs/changelog/assemble.py +/docs/changelog/versions/latest.md diff --git a/SilKit/ci/bump_version.py b/SilKit/ci/bump_version.py index daa5b3754..1a1697c3c 100644 --- a/SilKit/ci/bump_version.py +++ b/SilKit/ci/bump_version.py @@ -4,9 +4,10 @@ # # SPDX-License-Identifier: MIT -# Bumps the SIL Kit version: patches SilKitVersionMacros.h, archives -# docs/changelog/versions/latest.md as .md, lists it in -# docs/changelog/overview.rst and resets latest.md. +# Bumps the SIL Kit version: patches SilKitVersionMacros.h, assembles the +# changelog fragments in docs/changelog/unreleased/ into +# docs/changelog/versions/.md, deletes the fragments and lists +# the new page in docs/changelog/overview.rst. # See docs/development/release.md. import argparse @@ -16,9 +17,11 @@ import sys ROOT = pathlib.Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / "docs/changelog")) +import assemble # noqa: E402 + HEADER = ROOT / "SilKit/include/silkit/capi/SilKitVersionMacros.h" VERSIONS_DIR = ROOT / "docs/changelog/versions" -LATEST = VERSIONS_DIR / "latest.md" OVERVIEW = ROOT / "docs/changelog/overview.rst" COMPONENTS = ("MAJOR", "MINOR", "PATCH") @@ -57,8 +60,7 @@ def main(): parser = argparse.ArgumentParser(description="Bump the SIL Kit version and rotate the changelog.") parser.add_argument("version", help="new version, e.g. 5.0.9") parser.add_argument("--date", type=datetime.date.fromisoformat, - help="release date of the current version, YYYY-MM-DD (default: the date already in " - "latest.md, or today if it is UNRELEASED)") + help="release date of the current version, YYYY-MM-DD (default: today)") parser.add_argument("-n", "--dry-run", action="store_true", help="only print the files that would be written") args = parser.parse_args() @@ -79,20 +81,19 @@ def main(): die(f"{args.version} is not newer than {'.'.join(map(str, current))}") current_name = ".".join(map(str, current)) - new_name = ".".join(map(str, new)) archive = VERSIONS_DIR / (current_name + ".md") if archive.exists(): die(f"{archive.relative_to(ROOT)} already exists") - latest, latest_eol = read(LATEST) - heading = re.search(r"^# \[[^\]]*\] - (UNRELEASED|\d{4}-\d{2}-\d{2})$", latest, re.M) - if not heading: - die(f"no '# [x.y.z] - UNRELEASED' or '# [x.y.z] - YYYY-MM-DD' heading in {LATEST.relative_to(ROOT)}") - date = args.date - if date is None: - date = datetime.date.today() if heading.group(1) == "UNRELEASED" else heading.group(1) - latest = f"{latest[:heading.start()]}# [{current_name}] - {date}{latest[heading.end():]}" + try: + fragments = assemble.fragments() + except assemble.FragmentError as e: + die(str(e)) + fragment_paths = [path for found in fragments.values() for path, _ in found] + if not fragment_paths: + die(f"no changelog fragments in {assemble.UNRELEASED_DIR.relative_to(ROOT)}") + changelog = assemble.render(current_name, args.date or datetime.date.today(), fragments) overview, overview_eol = read(OVERVIEW) anchor = re.search(r"^( *)versions/latest\.md$", overview, re.M) @@ -104,9 +105,12 @@ def main(): header = re.sub(rf"^(#define SILKIT_VERSION_{component} )\d+$", rf"\g<1>{value}", header, flags=re.M) write(HEADER, header, header_eol, args.dry_run) - write(archive, latest, latest_eol, args.dry_run) - write(LATEST, f"# [{new_name}] - UNRELEASED\n\n> This changelog entry is still empty.\n", latest_eol, args.dry_run) + write(archive, changelog, overview_eol, args.dry_run) write(OVERVIEW, overview, overview_eol, args.dry_run) + for path in fragment_paths: + print(f"{'[dry-run] ' if args.dry_run else ''}delete {path.relative_to(ROOT)}") + if not args.dry_run: + path.unlink() if __name__ == "__main__": diff --git a/SilKit/ci/check_files_changed.py b/SilKit/ci/check_files_changed.py index c7058cdb4..9e7639f0c 100644 --- a/SilKit/ci/check_files_changed.py +++ b/SilKit/ci/check_files_changed.py @@ -22,7 +22,7 @@ def check_run_build(url: str): file_path = fileObject["filename"] file = file_path.split(sep="/")[-1] - if file not in exceptional_files: + if file not in exceptional_files and not file_path.startswith('docs/changelog/unreleased/'): run_builds = "true" break diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4a3ed97a3..d05a75b8f 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -45,6 +45,9 @@ file(GLOB_RECURSE SPHINX_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.rst) # Markdown pages (the changelog entries, development/release.md) are part of the # Sphinx sources too and must retrigger the build when edited. file(GLOB_RECURSE SPHINX_MD_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.md) +# latest.md is generated by conf.py from the fragments in changelog/unreleased/, +# which the glob already lists; as a dependency it would retrigger every build. +list(FILTER SPHINX_MD_FILES EXCLUDE REGEX "/changelog/versions/latest\.md$") list(APPEND SPHINX_SOURCE_FILES ${SPHINX_MD_FILES}) file(GLOB_RECURSE SVG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.svg) list(APPEND SPHINX_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/_static/custom.css) @@ -97,6 +100,7 @@ install(DIRECTORY ${SPHINX_BUILD}/ REGEX "\.venv$" EXCLUDE REGEX "\.buildinfo$" EXCLUDE ) +# generated by conf.py during the Sphinx build install( FILES changelog/versions/latest.md diff --git a/docs/changelog/assemble.py b/docs/changelog/assemble.py new file mode 100644 index 000000000..cf5c5047c --- /dev/null +++ b/docs/changelog/assemble.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: 2026 Vector Informatik GmbH +# +# SPDX-License-Identifier: MIT + +# Assembles the changelog of the unreleased version from the fragments in +# docs/changelog/unreleased/
/*.md. Every pull request adds its own +# fragment instead of editing a shared file, so changelog entries never +# conflict. See docs/changelog/unreleased/README.md. +# +# Used by docs/conf.py (writes versions/latest.md for the docs build) and by +# SilKit/ci/bump_version.py (writes versions/.md at release). +# +# python3 docs/changelog/assemble.py # print the unreleased changelog +# python3 docs/changelog/assemble.py --check # only validate the fragments + +import argparse +import pathlib +import re +import sys + +CHANGELOG_DIR = pathlib.Path(__file__).resolve().parent +UNRELEASED_DIR = CHANGELOG_DIR / "unreleased" +LATEST = CHANGELOG_DIR / "versions" / "latest.md" +VERSION_HEADER = CHANGELOG_DIR.parents[1] / "SilKit/include/silkit/capi/SilKitVersionMacros.h" + +# Directory name -> heading, in the order of Keep a Changelog. "notes" holds +# free-form text (with its own "##" heading) that goes before all sections. +SECTIONS = { + "notes": None, + "added": "Added", + "changed": "Changed", + "deprecated": "Deprecated", + "removed": "Removed", + "fixed": "Fixed", +} +IGNORED = {"README.md", ".gitkeep"} + + +class FragmentError(Exception): + pass + + +def fragments(): + """Returns {section: [(path, text)]}, sorted by file name; raises FragmentError on misplaced or empty files.""" + found = {section: [] for section in SECTIONS} + errors = [] + for path in sorted(UNRELEASED_DIR.rglob("*")): + if path.is_dir() or path.name in IGNORED: + continue + relative = path.relative_to(UNRELEASED_DIR) + if len(relative.parts) != 2 or relative.parts[0] not in SECTIONS or path.suffix != ".md": + errors.append(f"{relative.as_posix()}: expected
/.md with
one of " + f"{', '.join(SECTIONS)}") + continue + text = path.read_text(encoding="utf-8").strip() + if not text: + errors.append(f"{relative.as_posix()}: empty") + continue + if relative.parts[0] != "notes" and not text.startswith("- "): + errors.append(f"{relative.as_posix()}: must be a list item starting with '- '") + continue + found[relative.parts[0]].append((path, text)) + if errors: + raise FragmentError("invalid changelog fragments:\n " + "\n ".join(errors)) + return found + + +def current_version(): + header = VERSION_HEADER.read_text(encoding="utf-8") + parts = [] + for component in ("MAJOR", "MINOR", "PATCH"): + match = re.search(rf"^#define SILKIT_VERSION_{component} (\d+)$", header, re.M) + if not match: + raise FragmentError(f"no SILKIT_VERSION_{component} in {VERSION_HEADER}") + parts.append(match.group(1)) + return ".".join(parts) + + +def render(version, date="UNRELEASED", found=None): + """The changelog page of `version` from the fragments, with `date` (YYYY-MM-DD or UNRELEASED).""" + if found is None: + found = fragments() + blocks = [f"# [{version}] - {date}"] + for section, heading in SECTIONS.items(): + texts = [text for _, text in found[section]] + if not texts: + continue + if heading is None: + blocks.extend(texts) + else: + blocks.append(f"## {heading}\n\n" + "\n".join(texts)) + if len(blocks) == 1: + blocks.append("> This changelog entry is still empty.") + return "\n\n".join(blocks) + "\n" + + +def write_if_changed(path, text): + """Writes only on change, so that the docs build doesn't see a new file every time.""" + try: + if path.read_text(encoding="utf-8") == text: + return + except FileNotFoundError: + pass + with open(path, "w", encoding="utf-8", newline="\n") as f: + f.write(text) + + +def write_latest(): + write_if_changed(LATEST, render(current_version())) + + +def main(): + parser = argparse.ArgumentParser(description="Assemble the unreleased changelog from its fragments.") + parser.add_argument("--check", action="store_true", help="only validate the fragments") + args = parser.parse_args() + try: + text = render(current_version()) + except FragmentError as e: + sys.exit(f"error: {e}") + if not args.check: + sys.stdout.write(text) + + +if __name__ == "__main__": + main() diff --git a/docs/changelog/unreleased/README.md b/docs/changelog/unreleased/README.md new file mode 100644 index 000000000..4b9d5264c --- /dev/null +++ b/docs/changelog/unreleased/README.md @@ -0,0 +1,35 @@ +# Changelog fragments + +Every pull request with a user-visible change adds its changelog entry as a file of its own here, +instead of editing a shared changelog file. Different files never conflict, so PRs don't need +rebasing just because another PR with a changelog entry was merged first. + +``` +docs/changelog/unreleased/
/.md +``` + +`
` is one of: + +| Folder | Heading in the changelog | +|---------------|------------------------------------------------------------------------| +| `notes/` | none: free-form text with its own `## Heading`, put before all sections | +| `added/` | Added | +| `changed/` | Changed | +| `deprecated/` | Deprecated | +| `removed/` | Removed | +| `fixed/` | Fixed | + +Except in `notes/`, a fragment holds one or more Markdown list items, each starting with `- `. +Continuation lines are indented by two spaces. Fragments are sorted by file name within a section. +`` only has to be unique; something like `timesync-blocking-race.md` works well. + +Example, `docs/changelog/unreleased/fixed/timesync-blocking-race.md`: + +```md +- Fixed a data race on `_blocking` in the time synchronization. +``` + +Preview the result with `python3 docs/changelog/assemble.py` (or `--check` to only validate). +The docs build generates `docs/changelog/versions/latest.md` from these files; it is not checked in. +At release, `SilKit/ci/bump_version.py` writes the fragments to `versions/.md` and +deletes them. See `docs/development/release.md`. diff --git a/docs/changelog/unreleased/changed/build-identity-settings.md b/docs/changelog/unreleased/changed/build-identity-settings.md new file mode 100644 index 000000000..678df0123 --- /dev/null +++ b/docs/changelog/unreleased/changed/build-identity-settings.md @@ -0,0 +1,4 @@ +- The build number, git hash and pre-release suffix are build-time settings (`cmake -DSILKIT_BUILD_NUMBER=N`, + `-DSILKIT_BUILD_GIT_HASH=`, `-DSILKIT_VERSION_SUFFIX=rc1`). The git hash defaults to `git rev-parse HEAD`. + The installed `SilKitVersionMacros.h` only carries fallbacks for these three; query them at runtime via + `SilKit::Version` or the C API instead. diff --git a/docs/changelog/unreleased/changed/sim-step-handler-switch.md b/docs/changelog/unreleased/changed/sim-step-handler-switch.md new file mode 100644 index 000000000..2777c7f6d --- /dev/null +++ b/docs/changelog/unreleased/changed/sim-step-handler-switch.md @@ -0,0 +1,3 @@ +- Switching between `SetSimulationStepHandler` and `SetSimulationStepHandlerAsync` is now rejected once + `StartLifecycle()` has been called (`SilKit::StateError`, `SilKit_ReturnCode_WRONGSTATE` in the C API). Setting + another handler of the same kind at runtime, e.g., to change the step size, remains possible. diff --git a/docs/changelog/unreleased/changed/version-macros-committed.md b/docs/changelog/unreleased/changed/version-macros-committed.md new file mode 100644 index 000000000..87aad7214 --- /dev/null +++ b/docs/changelog/unreleased/changed/version-macros-committed.md @@ -0,0 +1,3 @@ +- `SilKitVersionMacros.h` is now committed to the source tree instead of being generated at CMake configure time. + It is the single source of truth for the version numbers; `SilKitVersion.cmake` reads them from it. + `SilKit/ci/bump_version.py` bumps the version and rotates the changelog. See `docs/development/release.md`. diff --git a/docs/changelog/versions/latest.md b/docs/changelog/versions/latest.md deleted file mode 100644 index 204a2862a..000000000 --- a/docs/changelog/versions/latest.md +++ /dev/null @@ -1,14 +0,0 @@ -# [5.0.9] - UNRELEASED - -## Changed - -- `SilKitVersionMacros.h` is now committed to the source tree instead of being generated at CMake configure time. - It is the single source of truth for the version numbers; `SilKitVersion.cmake` reads them from it. - `SilKit/ci/bump_version.py` bumps the version and rotates the changelog. See `docs/development/release.md`. -- The build number, git hash and pre-release suffix are build-time settings (`cmake -DSILKIT_BUILD_NUMBER=N`, - `-DSILKIT_BUILD_GIT_HASH=`, `-DSILKIT_VERSION_SUFFIX=rc1`). The git hash defaults to `git rev-parse HEAD`. - The installed `SilKitVersionMacros.h` only carries fallbacks for these three; query them at runtime via - `SilKit::Version` or the C API instead. -- Switching between `SetSimulationStepHandler` and `SetSimulationStepHandlerAsync` is now rejected once - `StartLifecycle()` has been called (`SilKit::StateError`, `SilKit_ReturnCode_WRONGSTATE` in the C API). Setting - another handler of the same kind at runtime, e.g., to change the step size, remains possible. diff --git a/docs/conf.py b/docs/conf.py index 500ab3e9a..dde0877ea 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,6 +18,12 @@ import sys import sphinx_rtd_theme +# The changelog of the unreleased version is assembled from one fragment file +# per change (docs/changelog/unreleased/), so that PRs don't conflict on it. +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'changelog')) +import assemble +assemble.write_latest() + # -- Project information ----------------------------------------------------- project = 'SIL Kit' @@ -76,6 +82,7 @@ '_build', 'Thumbs.db', '.DS_Store', 'overview/overview.rst', 'changelog/versions/template.md', + 'changelog/unreleased', ] # The name of the Pygments (syntax highlighting) style to use. diff --git a/docs/development/release.md b/docs/development/release.md index 5b1b83401..3546613d8 100644 --- a/docs/development/release.md +++ b/docs/development/release.md @@ -19,11 +19,24 @@ python3 SilKit/ci/bump_version.py --dry-run 5.0.9 python3 SilKit/ci/bump_version.py 5.0.9 ``` -This sets the version in the header, archives `latest.md` as `5.0.8.md`, lists it in -`docs/changelog/overview.rst` and resets `latest.md` to an empty `# [5.0.9] - UNRELEASED` stub. -The archived heading keeps the release date already in `latest.md`, or gets today's date if it -still says `UNRELEASED` (`--date YYYY-MM-DD` overrides either). Review with `git diff`, -commit as `version: bump to X.Y.Z`, and open a PR to merge the commit to main. +This sets the version in the header, assembles the changelog fragments in +`docs/changelog/unreleased/` into `docs/changelog/versions/5.0.8.md`, deletes the fragments and +lists the new page in `docs/changelog/overview.rst`. The heading gets today's date +(`--date YYYY-MM-DD` overrides it). Review with `git diff`, commit as `version: bump to X.Y.Z`, +and open a PR to merge the commit to main. + +## The changelog + +Each PR adds its changelog entry as a file of its own under +`docs/changelog/unreleased/
/`, see `docs/changelog/unreleased/README.md`. Nobody edits a +shared changelog file, so changelog entries don't cause merge conflicts between PRs. +`docs/changelog/versions/latest.md` is generated from the fragments by the docs build +(`docs/conf.py`) and is not checked in. To polish the wording or order before a release, edit +the fragments, or edit the assembled `.md` after the bump. Preview it with: + +```sh +python3 docs/changelog/assemble.py +``` ## Build identity From 49a62cc0ace1557a769105d679f0bfde41a3e502 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 2 Dec 2026 14:07:29 +0100 Subject: [PATCH 2/3] changelog: optional RELEASE_DATE for the release being prepared Before, the release manager replaced UNRELEASED with the release date in latest.md, so the release's docs and packages showed it. The fragments have no such place: docs/changelog/unreleased/RELEASE_DATE now holds it, and bump_version.py uses it as default date and deletes it. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Konrad Breitsprecher --- SilKit/ci/bump_version.py | 12 ++++++++++-- docs/changelog/assemble.py | 28 ++++++++++++++++++++++++---- docs/changelog/unreleased/README.md | 4 ++++ docs/development/release.md | 9 ++++++--- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/SilKit/ci/bump_version.py b/SilKit/ci/bump_version.py index 1a1697c3c..60ab143e3 100644 --- a/SilKit/ci/bump_version.py +++ b/SilKit/ci/bump_version.py @@ -60,7 +60,8 @@ def main(): parser = argparse.ArgumentParser(description="Bump the SIL Kit version and rotate the changelog.") parser.add_argument("version", help="new version, e.g. 5.0.9") parser.add_argument("--date", type=datetime.date.fromisoformat, - help="release date of the current version, YYYY-MM-DD (default: today)") + help="release date of the current version, YYYY-MM-DD (default: the date in " + "docs/changelog/unreleased/RELEASE_DATE, or today if there is none)") parser.add_argument("-n", "--dry-run", action="store_true", help="only print the files that would be written") args = parser.parse_args() @@ -93,7 +94,14 @@ def main(): fragment_paths = [path for found in fragments.values() for path, _ in found] if not fragment_paths: die(f"no changelog fragments in {assemble.UNRELEASED_DIR.relative_to(ROOT)}") - changelog = assemble.render(current_name, args.date or datetime.date.today(), fragments) + try: + planned = assemble.release_date() + except assemble.FragmentError as e: + die(str(e)) + if planned != "UNRELEASED": + fragment_paths.append(assemble.RELEASE_DATE) + date = args.date or (planned if planned != "UNRELEASED" else datetime.date.today()) + changelog = assemble.render(current_name, date, fragments) overview, overview_eol = read(OVERVIEW) anchor = re.search(r"^( *)versions/latest\.md$", overview, re.M) diff --git a/docs/changelog/assemble.py b/docs/changelog/assemble.py index cf5c5047c..f4d18d4b9 100644 --- a/docs/changelog/assemble.py +++ b/docs/changelog/assemble.py @@ -14,6 +14,7 @@ # # python3 docs/changelog/assemble.py # print the unreleased changelog # python3 docs/changelog/assemble.py --check # only validate the fragments +# python3 docs/changelog/assemble.py -o FILE # write it to FILE import argparse import pathlib @@ -35,7 +36,10 @@ "removed": "Removed", "fixed": "Fixed", } -IGNORED = {"README.md", ".gitkeep"} +# Holds the planned release date (YYYY-MM-DD) once the release is prepared, so +# that the docs and packages of the release show it instead of UNRELEASED. +RELEASE_DATE = UNRELEASED_DIR / "RELEASE_DATE" +IGNORED = {"README.md", ".gitkeep", RELEASE_DATE.name} class FragmentError(Exception): @@ -78,6 +82,17 @@ def current_version(): return ".".join(parts) +def release_date(): + """The date in unreleased/RELEASE_DATE, or "UNRELEASED" if there is no such file.""" + try: + text = RELEASE_DATE.read_text(encoding="utf-8").strip() + except FileNotFoundError: + return "UNRELEASED" + if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", text): + raise FragmentError(f"{RELEASE_DATE.name}: expected YYYY-MM-DD, got '{text}'") + return text + + def render(version, date="UNRELEASED", found=None): """The changelog page of `version` from the fragments, with `date` (YYYY-MM-DD or UNRELEASED).""" if found is None: @@ -108,18 +123,23 @@ def write_if_changed(path, text): def write_latest(): - write_if_changed(LATEST, render(current_version())) + write_if_changed(LATEST, render(current_version(), release_date())) def main(): parser = argparse.ArgumentParser(description="Assemble the unreleased changelog from its fragments.") parser.add_argument("--check", action="store_true", help="only validate the fragments") + parser.add_argument("-o", "--output", type=pathlib.Path, help="write to this file instead of stdout") args = parser.parse_args() try: - text = render(current_version()) + text = render(current_version(), release_date()) except FragmentError as e: sys.exit(f"error: {e}") - if not args.check: + if args.check: + return + if args.output: + write_if_changed(args.output, text) + else: sys.stdout.write(text) diff --git a/docs/changelog/unreleased/README.md b/docs/changelog/unreleased/README.md index 4b9d5264c..2d7ad0b76 100644 --- a/docs/changelog/unreleased/README.md +++ b/docs/changelog/unreleased/README.md @@ -29,6 +29,10 @@ Example, `docs/changelog/unreleased/fixed/timesync-blocking-race.md`: - Fixed a data race on `_blocking` in the time synchronization. ``` +When preparing a release, the release manager puts the planned release date into +`docs/changelog/unreleased/RELEASE_DATE` (one line, `YYYY-MM-DD`). The docs and packages built +from then on show that date instead of `UNRELEASED`. + Preview the result with `python3 docs/changelog/assemble.py` (or `--check` to only validate). The docs build generates `docs/changelog/versions/latest.md` from these files; it is not checked in. At release, `SilKit/ci/bump_version.py` writes the fragments to `versions/.md` and diff --git a/docs/development/release.md b/docs/development/release.md index 3546613d8..aa3f32552 100644 --- a/docs/development/release.md +++ b/docs/development/release.md @@ -21,8 +21,9 @@ python3 SilKit/ci/bump_version.py 5.0.9 This sets the version in the header, assembles the changelog fragments in `docs/changelog/unreleased/` into `docs/changelog/versions/5.0.8.md`, deletes the fragments and -lists the new page in `docs/changelog/overview.rst`. The heading gets today's date -(`--date YYYY-MM-DD` overrides it). Review with `git diff`, commit as `version: bump to X.Y.Z`, +lists the new page in `docs/changelog/overview.rst`. The heading gets the date from +`docs/changelog/unreleased/RELEASE_DATE` (deleted along with the fragments), or today's date if +there is no such file; `--date YYYY-MM-DD` overrides either. Review with `git diff`, commit as `version: bump to X.Y.Z`, and open a PR to merge the commit to main. ## The changelog @@ -31,7 +32,9 @@ Each PR adds its changelog entry as a file of its own under `docs/changelog/unreleased/
/`, see `docs/changelog/unreleased/README.md`. Nobody edits a shared changelog file, so changelog entries don't cause merge conflicts between PRs. `docs/changelog/versions/latest.md` is generated from the fragments by the docs build -(`docs/conf.py`) and is not checked in. To polish the wording or order before a release, edit +(`docs/conf.py`) and is not checked in. Before the release build, put the planned release date into +`docs/changelog/unreleased/RELEASE_DATE` (`YYYY-MM-DD`), so the released docs and packages show it +instead of `UNRELEASED`. To polish the wording or order before a release, edit the fragments, or edit the assembled `.md` after the bump. Preview it with: ```sh From 7cf7f1f9be21035d77dee298c7862dff4d93ef82 Mon Sep 17 00:00:00 2001 From: Konrad Breitsprecher Date: Wed, 2 Dec 2026 14:13:51 +0100 Subject: [PATCH 3/3] changelog: finalize the version's changelog at the start of a delivery Replaces RELEASE_DATE. The delivery's first step, which used to set the date in latest.md, now runs SilKit/ci/finalize_changelog.py: it writes the fragments to versions/.md with the release date and deletes them, so the delivery build carries the final changelog. bump_version.py at the end of the delivery only bumps the version, and refuses to run before the changelog is finalized. Fragments merged between the two belong to the next version; latest.md shows them as [Unreleased], and is left out of the docs while there are none. The docs build generates the version list of overview.rst, so neither script edits it. The installed CHANGELOG.md is the finalized page if there is one. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Konrad Breitsprecher --- .gitignore | 1 + SilKit/ci/bump_version.py | 51 ++------------- SilKit/ci/finalize_changelog.py | 59 +++++++++++++++++ docs/CMakeLists.txt | 9 ++- docs/changelog/assemble.py | 99 +++++++++++++++++++++-------- docs/changelog/overview.rst | 19 +----- docs/changelog/unreleased/README.md | 8 +-- docs/conf.py | 6 +- docs/development/release.md | 44 +++++++------ 9 files changed, 181 insertions(+), 115 deletions(-) create mode 100644 SilKit/ci/finalize_changelog.py diff --git a/.gitignore b/.gitignore index df091eb2e..1c3b02163 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ CMakeUserPresets.json # generated from docs/changelog/unreleased/ by docs/changelog/assemble.py /docs/changelog/versions/latest.md +/docs/changelog/versions-toctree.inc diff --git a/SilKit/ci/bump_version.py b/SilKit/ci/bump_version.py index 60ab143e3..6c53b169f 100644 --- a/SilKit/ci/bump_version.py +++ b/SilKit/ci/bump_version.py @@ -4,14 +4,12 @@ # # SPDX-License-Identifier: MIT -# Bumps the SIL Kit version: patches SilKitVersionMacros.h, assembles the -# changelog fragments in docs/changelog/unreleased/ into -# docs/changelog/versions/.md, deletes the fragments and lists -# the new page in docs/changelog/overview.rst. +# Bumps the SIL Kit version in SilKitVersionMacros.h. The changelog of the +# current version must be finalized first (finalize_changelog.py writes +# docs/changelog/versions/.md). # See docs/development/release.md. import argparse -import datetime import pathlib import re import sys @@ -21,8 +19,6 @@ import assemble # noqa: E402 HEADER = ROOT / "SilKit/include/silkit/capi/SilKitVersionMacros.h" -VERSIONS_DIR = ROOT / "docs/changelog/versions" -OVERVIEW = ROOT / "docs/changelog/overview.rst" COMPONENTS = ("MAJOR", "MINOR", "PATCH") @@ -57,11 +53,8 @@ def write(path, text, eol, dry_run): def main(): - parser = argparse.ArgumentParser(description="Bump the SIL Kit version and rotate the changelog.") + parser = argparse.ArgumentParser(description="Bump the SIL Kit version.") parser.add_argument("version", help="new version, e.g. 5.0.9") - parser.add_argument("--date", type=datetime.date.fromisoformat, - help="release date of the current version, YYYY-MM-DD (default: the date in " - "docs/changelog/unreleased/RELEASE_DATE, or today if there is none)") parser.add_argument("-n", "--dry-run", action="store_true", help="only print the files that would be written") args = parser.parse_args() @@ -81,44 +74,14 @@ def main(): if new <= current: die(f"{args.version} is not newer than {'.'.join(map(str, current))}") - current_name = ".".join(map(str, current)) - - archive = VERSIONS_DIR / (current_name + ".md") - if archive.exists(): - die(f"{archive.relative_to(ROOT)} already exists") - - try: - fragments = assemble.fragments() - except assemble.FragmentError as e: - die(str(e)) - fragment_paths = [path for found in fragments.values() for path, _ in found] - if not fragment_paths: - die(f"no changelog fragments in {assemble.UNRELEASED_DIR.relative_to(ROOT)}") - try: - planned = assemble.release_date() - except assemble.FragmentError as e: - die(str(e)) - if planned != "UNRELEASED": - fragment_paths.append(assemble.RELEASE_DATE) - date = args.date or (planned if planned != "UNRELEASED" else datetime.date.today()) - changelog = assemble.render(current_name, date, fragments) - - overview, overview_eol = read(OVERVIEW) - anchor = re.search(r"^( *)versions/latest\.md$", overview, re.M) - if not anchor: - die(f"no 'versions/latest.md' entry in {OVERVIEW.relative_to(ROOT)}") - overview = f"{overview[:anchor.end()]}\n{anchor.group(1)}versions/{current_name}.md{overview[anchor.end():]}" + page = assemble.version_page(".".join(map(str, current))) + if not page.exists(): + die(f"{page.relative_to(ROOT)} does not exist; finalize the changelog first (finalize_changelog.py)") for component, value in zip(COMPONENTS, new): header = re.sub(rf"^(#define SILKIT_VERSION_{component} )\d+$", rf"\g<1>{value}", header, flags=re.M) write(HEADER, header, header_eol, args.dry_run) - write(archive, changelog, overview_eol, args.dry_run) - write(OVERVIEW, overview, overview_eol, args.dry_run) - for path in fragment_paths: - print(f"{'[dry-run] ' if args.dry_run else ''}delete {path.relative_to(ROOT)}") - if not args.dry_run: - path.unlink() if __name__ == "__main__": diff --git a/SilKit/ci/finalize_changelog.py b/SilKit/ci/finalize_changelog.py new file mode 100644 index 000000000..2f422536e --- /dev/null +++ b/SilKit/ci/finalize_changelog.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +# SPDX-FileCopyrightText: 2026 Vector Informatik GmbH +# +# SPDX-License-Identifier: MIT + +# Finalizes the changelog of the current version when preparing a delivery: +# writes the fragments in docs/changelog/unreleased/ to +# docs/changelog/versions/.md with the release date and +# deletes them. The version bump (bump_version.py) comes later. +# See docs/development/release.md. + +import argparse +import datetime +import pathlib +import sys + +ROOT = pathlib.Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / "docs/changelog")) +import assemble # noqa: E402 + + +def die(message): + sys.exit("error: " + message) + + +def main(): + parser = argparse.ArgumentParser(description="Write the changelog fragments to the page of the current version.") + parser.add_argument("--date", type=datetime.date.fromisoformat, default=datetime.date.today(), + help="release date, YYYY-MM-DD (default: today)") + parser.add_argument("-n", "--dry-run", action="store_true", help="only print what would be done") + args = parser.parse_args() + prefix = "[dry-run] " if args.dry_run else "" + + try: + version = assemble.current_version() + found = assemble.fragments() + except assemble.FragmentError as e: + die(str(e)) + + page = assemble.version_page(version) + if page.exists(): + die(f"{page.relative_to(ROOT)} already exists; bump the version first (bump_version.py)") + paths = assemble.fragment_paths(found) + if not paths: + die(f"no changelog fragments in {assemble.UNRELEASED_DIR.relative_to(ROOT)}") + + print(f"{prefix}write {page.relative_to(ROOT)}") + if not args.dry_run: + with open(page, "w", encoding="utf-8", newline="\n") as f: + f.write(assemble.render(f"[{version}] - {args.date}", found)) + for path in paths: + print(f"{prefix}delete {path.relative_to(ROOT)}") + if not args.dry_run: + path.unlink() + + +if __name__ == "__main__": + main() diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index d05a75b8f..791ee0955 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -100,10 +100,15 @@ install(DIRECTORY ${SPHINX_BUILD}/ REGEX "\.venv$" EXCLUDE REGEX "\.buildinfo$" EXCLUDE ) -# generated by conf.py during the Sphinx build +# The changelog of this version once it is finalized (SilKit/ci/finalize_changelog.py), +# otherwise the one conf.py generates from the fragments during the Sphinx build. +set(SILKIT_DOCS_CHANGELOG changelog/versions/${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.md) +if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SILKIT_DOCS_CHANGELOG}) + set(SILKIT_DOCS_CHANGELOG changelog/versions/latest.md) +endif() install( FILES - changelog/versions/latest.md + ${SILKIT_DOCS_CHANGELOG} DESTINATION . COMPONENT docs RENAME CHANGELOG.md diff --git a/docs/changelog/assemble.py b/docs/changelog/assemble.py index f4d18d4b9..c934d281e 100644 --- a/docs/changelog/assemble.py +++ b/docs/changelog/assemble.py @@ -4,13 +4,22 @@ # # SPDX-License-Identifier: MIT -# Assembles the changelog of the unreleased version from the fragments in +# Assembles the changelog from the fragments in # docs/changelog/unreleased/
/*.md. Every pull request adds its own # fragment instead of editing a shared file, so changelog entries never # conflict. See docs/changelog/unreleased/README.md. # -# Used by docs/conf.py (writes versions/latest.md for the docs build) and by -# SilKit/ci/bump_version.py (writes versions/.md at release). +# Lifecycle of a version's changelog: +# 1. During development, the fragments are rendered as versions/latest.md, +# "# [] - UNRELEASED", by the docs build (docs/conf.py). +# 2. When preparing the delivery, SilKit/ci/finalize_changelog.py writes them +# to versions/.md with the release date and deletes them. +# Fragments merged after that belong to the next version and show up as +# "# [Unreleased]" until the version bump. +# 3. SilKit/ci/bump_version.py bumps the version; it needs step 2 done. +# +# The docs build also generates the version list of overview.rst, so neither +# script edits it. # # python3 docs/changelog/assemble.py # print the unreleased changelog # python3 docs/changelog/assemble.py --check # only validate the fragments @@ -23,7 +32,9 @@ CHANGELOG_DIR = pathlib.Path(__file__).resolve().parent UNRELEASED_DIR = CHANGELOG_DIR / "unreleased" -LATEST = CHANGELOG_DIR / "versions" / "latest.md" +VERSIONS_DIR = CHANGELOG_DIR / "versions" +LATEST = VERSIONS_DIR / "latest.md" +TOCTREE = CHANGELOG_DIR / "versions-toctree.inc" VERSION_HEADER = CHANGELOG_DIR.parents[1] / "SilKit/include/silkit/capi/SilKitVersionMacros.h" # Directory name -> heading, in the order of Keep a Changelog. "notes" holds @@ -36,10 +47,7 @@ "removed": "Removed", "fixed": "Fixed", } -# Holds the planned release date (YYYY-MM-DD) once the release is prepared, so -# that the docs and packages of the release show it instead of UNRELEASED. -RELEASE_DATE = UNRELEASED_DIR / "RELEASE_DATE" -IGNORED = {"README.md", ".gitkeep", RELEASE_DATE.name} +IGNORED = {"README.md", ".gitkeep"} class FragmentError(Exception): @@ -71,6 +79,10 @@ def fragments(): return found +def fragment_paths(found): + return [path for entries in found.values() for path, _ in entries] + + def current_version(): header = VERSION_HEADER.read_text(encoding="utf-8") parts = [] @@ -82,35 +94,61 @@ def current_version(): return ".".join(parts) -def release_date(): - """The date in unreleased/RELEASE_DATE, or "UNRELEASED" if there is no such file.""" - try: - text = RELEASE_DATE.read_text(encoding="utf-8").strip() - except FileNotFoundError: - return "UNRELEASED" - if not re.fullmatch(r"\d{4}-\d{2}-\d{2}", text): - raise FragmentError(f"{RELEASE_DATE.name}: expected YYYY-MM-DD, got '{text}'") - return text +def version_page(version): + return VERSIONS_DIR / f"{version}.md" -def render(version, date="UNRELEASED", found=None): - """The changelog page of `version` from the fragments, with `date` (YYYY-MM-DD or UNRELEASED).""" - if found is None: - found = fragments() - blocks = [f"# [{version}] - {date}"] - for section, heading in SECTIONS.items(): +def render(heading, found): + """A changelog page with the heading `heading` (without "# ") from the fragments in `found`.""" + blocks = [f"# {heading}"] + for section, title in SECTIONS.items(): texts = [text for _, text in found[section]] if not texts: continue - if heading is None: + if title is None: blocks.extend(texts) else: - blocks.append(f"## {heading}\n\n" + "\n".join(texts)) + blocks.append(f"## {title}\n\n" + "\n".join(texts)) if len(blocks) == 1: blocks.append("> This changelog entry is still empty.") return "\n\n".join(blocks) + "\n" +def render_latest(found=None): + """The page of the fragments: "[] - UNRELEASED", or "[Unreleased]" once .md is finalized.""" + if found is None: + found = fragments() + version = current_version() + if version_page(version).exists(): + return render("[Unreleased]", found) + return render(f"[{version}] - UNRELEASED", found) + + +def latest_is_listed(found): + """latest.md is left out of the docs between finalizing a version and the next fragment, when it is empty.""" + return not version_page(current_version()).exists() or bool(fragment_paths(found)) + + +def version_pages(): + """The pages in versions/, newest first: x.y.z.md by version, then the older .rst pages.""" + semver = [] + older = [] + for path in VERSIONS_DIR.iterdir(): + match = re.fullmatch(r"(\d+)\.(\d+)\.(\d+)\.md", path.name) + if match: + semver.append((tuple(int(x) for x in match.groups()), path.name)) + elif path.suffix == ".rst": + match = re.match(r"\d+", path.name) + older.append((int(match.group()) if match else -1, path.name)) + return [name for _, name in sorted(semver, reverse=True)] + [name for _, name in sorted(older, reverse=True)] + + +def render_toctree(include_latest): + entries = (["latest.md"] if include_latest else []) + version_pages() + lines = [".. toctree::", " :maxdepth: 1", ""] + [f" versions/{name}" for name in entries] + return "\n".join(lines) + "\n" + + def write_if_changed(path, text): """Writes only on change, so that the docs build doesn't see a new file every time.""" try: @@ -122,8 +160,13 @@ def write_if_changed(path, text): f.write(text) -def write_latest(): - write_if_changed(LATEST, render(current_version(), release_date())) +def write_docs_sources(): + """Called by docs/conf.py: writes latest.md and the version list. Returns whether latest.md is listed.""" + found = fragments() + listed = latest_is_listed(found) + write_if_changed(LATEST, render_latest(found)) + write_if_changed(TOCTREE, render_toctree(listed)) + return listed def main(): @@ -132,7 +175,7 @@ def main(): parser.add_argument("-o", "--output", type=pathlib.Path, help="write to this file instead of stdout") args = parser.parse_args() try: - text = render(current_version(), release_date()) + text = render_latest() except FragmentError as e: sys.exit(f"error: {e}") if args.check: diff --git a/docs/changelog/overview.rst b/docs/changelog/overview.rst index 268c50744..ba80ffa3d 100644 --- a/docs/changelog/overview.rst +++ b/docs/changelog/overview.rst @@ -4,22 +4,9 @@ Changelog All notable changes to the SIL Kit project are listed on the respective versions page. -.. toctree:: - :maxdepth: 1 - :glob: +.. The version list is generated by the docs build (docs/changelog/assemble.py), + newest first, so that releasing a version doesn't need to edit this file. - versions/latest.md - versions/5.0.8.md - versions/5.0.7.md - versions/5.0.6.md - versions/5.0.5.md - versions/5.0.4.md - versions/5.0.3.md - versions/5.0.2.md - versions/5.0.1.md - versions/5.0.0.md - versions/4.rst - versions/3.rst - versions/2-and-older.rst +.. include:: versions-toctree.inc The format is based on `Keep a Changelog `_. \ No newline at end of file diff --git a/docs/changelog/unreleased/README.md b/docs/changelog/unreleased/README.md index 2d7ad0b76..d2fefa877 100644 --- a/docs/changelog/unreleased/README.md +++ b/docs/changelog/unreleased/README.md @@ -29,11 +29,7 @@ Example, `docs/changelog/unreleased/fixed/timesync-blocking-race.md`: - Fixed a data race on `_blocking` in the time synchronization. ``` -When preparing a release, the release manager puts the planned release date into -`docs/changelog/unreleased/RELEASE_DATE` (one line, `YYYY-MM-DD`). The docs and packages built -from then on show that date instead of `UNRELEASED`. - Preview the result with `python3 docs/changelog/assemble.py` (or `--check` to only validate). The docs build generates `docs/changelog/versions/latest.md` from these files; it is not checked in. -At release, `SilKit/ci/bump_version.py` writes the fragments to `versions/.md` and -deletes them. See `docs/development/release.md`. +When a delivery is prepared, `SilKit/ci/finalize_changelog.py` writes them to +`versions/.md` with the release date and deletes them. See `docs/development/release.md`. diff --git a/docs/conf.py b/docs/conf.py index dde0877ea..272093ef5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,9 +20,11 @@ # The changelog of the unreleased version is assembled from one fragment file # per change (docs/changelog/unreleased/), so that PRs don't conflict on it. +# This writes changelog/versions/latest.md and the version list included by +# changelog/overview.rst. sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'changelog')) import assemble -assemble.write_latest() +changelog_latest_listed = assemble.write_docs_sources() # -- Project information ----------------------------------------------------- @@ -84,6 +86,8 @@ 'changelog/versions/template.md', 'changelog/unreleased', ] +if not changelog_latest_listed: + exclude_patterns.append('changelog/versions/latest.md') # The name of the Pygments (syntax highlighting) style to use. #pygments_style = 'sphinx' diff --git a/docs/development/release.md b/docs/development/release.md index aa3f32552..6a4f5f6c2 100644 --- a/docs/development/release.md +++ b/docs/development/release.md @@ -12,35 +12,43 @@ For maintainers. `_MINOR` and `_PATCH`. It is the single source of truth: `SilKit/cmake/SilKitVersion.cmake` reads the numbers from it, and the library and the utilities' Windows resources include it. -## Bump the version - -```sh -python3 SilKit/ci/bump_version.py --dry-run 5.0.9 -python3 SilKit/ci/bump_version.py 5.0.9 -``` - -This sets the version in the header, assembles the changelog fragments in -`docs/changelog/unreleased/` into `docs/changelog/versions/5.0.8.md`, deletes the fragments and -lists the new page in `docs/changelog/overview.rst`. The heading gets the date from -`docs/changelog/unreleased/RELEASE_DATE` (deleted along with the fragments), or today's date if -there is no such file; `--date YYYY-MM-DD` overrides either. Review with `git diff`, commit as `version: bump to X.Y.Z`, -and open a PR to merge the commit to main. - ## The changelog Each PR adds its changelog entry as a file of its own under `docs/changelog/unreleased/
/`, see `docs/changelog/unreleased/README.md`. Nobody edits a shared changelog file, so changelog entries don't cause merge conflicts between PRs. `docs/changelog/versions/latest.md` is generated from the fragments by the docs build -(`docs/conf.py`) and is not checked in. Before the release build, put the planned release date into -`docs/changelog/unreleased/RELEASE_DATE` (`YYYY-MM-DD`), so the released docs and packages show it -instead of `UNRELEASED`. To polish the wording or order before a release, edit -the fragments, or edit the assembled `.md` after the bump. Preview it with: +(`docs/conf.py`) and is not checked in. So is the version list of `docs/changelog/overview.rst`. +Preview the unreleased changelog with: ```sh python3 docs/changelog/assemble.py ``` +## Finalize the changelog (start of a delivery) + +```sh +python3 SilKit/ci/finalize_changelog.py --dry-run --date 2026-12-15 +python3 SilKit/ci/finalize_changelog.py --date 2026-12-15 +``` + +This writes the fragments to `docs/changelog/versions/.md` with the release date +(default: today) and deletes them. Polish the wording and order in that file, commit as +`changelog: finalize X.Y.Z`, and merge it to main before the delivery build, so the build's docs +and packages carry the final changelog. Fragments merged afterwards belong to the next version; +the docs list them as `[Unreleased]` until the version bump. + +## Bump the version (end of a delivery) + +```sh +python3 SilKit/ci/bump_version.py --dry-run 5.0.10 +python3 SilKit/ci/bump_version.py 5.0.10 +``` + +This sets the version in the header. It refuses to run before the changelog of the current +version is finalized. Review with `git diff`, commit as `version: bump to X.Y.Z`, and open a PR to +merge the commit to main. + ## Build identity The git hash, build number and pre-release suffix describe a *build*. The header only