Przeglądaj źródła

feat(docs): label upgrade notes with the release version when tagged

Upgrade notes for unreleased changes go under "Next release (unreleased)"
in upgrade_notes.adoc. When a 3k release is tagged, a workflow moves the
notes that shipped in that release under a heading for its version on
next, which is where the docs site is built from. Notes merged after the
release was cut stay unreleased.

AGENTS.md documents how to add upgrade notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jamesread 2 dni temu
rodzic
commit
ae66a9afb0

+ 60 - 0
.github/workflows/release-upgrade-notes.yml

@@ -0,0 +1,60 @@
+---
+name: Release upgrade notes
+
+# Upgrade notes for merged but unreleased changes live under
+# "Next release (unreleased)" in upgrade_notes.adoc. When a 3k release is
+# tagged, move the notes that shipped in it under a heading for that version
+# on the next branch, which is where docs.olivetin.app is built from.
+
+on:
+  push:
+    tags:
+      - '3*.*.*'
+      - '!3*.*.*-*'
+  workflow_dispatch:
+    inputs:
+      tag:
+        description: 'Release tag to label upgrade notes with (eg 3000.23.0)'
+        required: true
+
+permissions:
+  contents: read
+
+concurrency:
+  group: release-upgrade-notes
+  cancel-in-progress: false
+
+jobs:
+  label-upgrade-notes:
+    runs-on: ubuntu-latest
+    env:
+      NOTES_PATH: docs/modules/ROOT/pages/upgrade/upgrade_notes.adoc
+      RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
+    steps:
+      - name: Checkout next
+        uses: actions/checkout@v6
+        with:
+          ref: next
+          fetch-depth: 0
+          token: ${{ secrets.CONTAINER_TOKEN }}
+
+      - name: Move released upgrade notes
+        run: |
+          released_notes="${RUNNER_TEMP}/upgrade_notes_released.adoc"
+          if ! git show "refs/tags/${RELEASE_TAG}:${NOTES_PATH}" > "${released_notes}"; then
+            echo "Tag ${RELEASE_TAG} has no ${NOTES_PATH}; nothing to do."
+            exit 0
+          fi
+          python3 -I scripts/release_upgrade_notes.py "${RELEASE_TAG}" "${released_notes}" "${NOTES_PATH}"
+
+      - name: Commit and push
+        run: |
+          if git diff --quiet -- "${NOTES_PATH}"; then
+            echo "No changes to commit."
+            exit 0
+          fi
+          git config user.name "github-actions[bot]"
+          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
+          git add "${NOTES_PATH}"
+          git commit -m "docs: label upgrade notes released in ${RELEASE_TAG}"
+          git push origin HEAD:next

+ 17 - 0
AGENTS.md

@@ -74,6 +74,23 @@ If you are looking for OliveTin's AI policy, you can find it in `AI.md`.
 - Review the AI guidance in `AI.md`.
 - Review the pull request template at `.github/PULL_REQUEST_TEMPLATE.md`.
 - When changing behaviour covered by a spec in `specs/`, ensure implementation and tests match the spec.
+- If operators need to act when upgrading, add an upgrade note (see "Upgrade Notes" below).
+
+### Upgrade Notes (changes that need operator action)
+When a change means operators may need to do something when they upgrade (a breaking behaviour change, a config change, or a security fix that stops a previously working setup), add an upgrade note in the same PR as the change.
+
+- Add the note to `docs/modules/ROOT/pages/upgrade/upgrade_notes.adoc`, under the `== Next release (unreleased)` heading. If that heading does not exist, create it directly after the page's introduction paragraph, above the newest version section.
+- Each note is an anchor line plus a level-3 heading, then what changed, who is affected, and what to do:
+  ```asciidoc
+  [#short-kebab-case-anchor]
+  === Short description of the change
+
+  What changed, and who is affected. What operators need to change.
+  ```
+- Link to the note from related docs pages with `xref:upgrade/upgrade_notes.adoc#short-kebab-case-anchor[Upgrade Notes]`. The anchor stays the same when the note moves under a version heading, so links keep working.
+- Do **not** write a version number and do **not** rename the unreleased heading by hand. When a 3k release is tagged, `.github/workflows/release-upgrade-notes.yml` runs `scripts/release_upgrade_notes.py`, which moves every note that was in the unreleased section at the tagged commit under a new `== <version>` heading on `next`. Notes merged after the release was cut stay unreleased. If the workflow fails, rerun it with `workflow_dispatch` and the release tag.
+- Do **not** mark the change with a `BREAKING CHANGE:` footer or a `!` in the commit type. semantic-release treats either as a major version bump.
+- docs.olivetin.app is built from `next`, so a note is public as soon as it merges. For security fixes the note goes in the private advisory fork PR, and should describe the behaviour change without exploit details.
 
 ### Branch Naming
 Use conventional-commit-style branch names with a type prefix, optional issue reference, and a short kebab-case description:

+ 144 - 0
scripts/release_upgrade_notes.py

@@ -0,0 +1,144 @@
+#!/usr/bin/env python3
+"""Move upgrade notes that shipped in a release under that release's heading.
+
+Upgrade notes for changes that are merged but not yet released live under the
+"Next release (unreleased)" section of upgrade_notes.adoc. When a release is
+tagged, every note that was in the unreleased section *at the tagged commit*
+moves into a new "== <version>" section. Notes added to the unreleased section
+after the release was cut stay where they are.
+
+Usage:
+    release_upgrade_notes.py <version> <released-file> <target-file>
+
+<released-file> is upgrade_notes.adoc as it was at the release tag, and
+<target-file> is the copy to update in place (normally on the next branch).
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+UNRELEASED_HEADING = "== Next release (unreleased)"
+
+
+def split_sections(lines: list[str], prefix: str) -> tuple[list[str], list[list[str]]]:
+    """Split lines into a preamble and blocks that each start at a heading.
+
+    An anchor line such as [#some-id] directly above a heading belongs to that
+    heading's block, so that anchors move with their notes.
+    """
+    preamble: list[str] = []
+    blocks: list[list[str]] = []
+
+    for line in lines:
+        if line.startswith(prefix) and not line.startswith(prefix + "="):
+            anchor = _take_anchor(preamble if not blocks else blocks[-1])
+            blocks.append(anchor + [line])
+        elif blocks:
+            blocks[-1].append(line)
+        else:
+            preamble.append(line)
+
+    return preamble, blocks
+
+
+def _take_anchor(block: list[str]) -> list[str]:
+    if block and block[-1].startswith("[#"):
+        return [block.pop()]
+    return []
+
+
+def note_key(note: list[str]) -> str:
+    """Identify a note by its anchor, falling back to its heading."""
+    for line in note:
+        if line.startswith("[#") or line.startswith("=== "):
+            return line.strip()
+    return ""
+
+
+def section_heading(section: list[str]) -> str:
+    for line in section:
+        if not line.startswith("[#"):
+            return line.rstrip()
+    return ""
+
+
+def unreleased_notes(lines: list[str]) -> tuple[list[str], list[list[str]]] | None:
+    _, sections = split_sections(lines, "== ")
+    for section in sections:
+        if section_heading(section) == UNRELEASED_HEADING:
+            return split_sections(section, "=== ")
+    return None
+
+
+def released_keys(released_lines: list[str]) -> set[str]:
+    found = unreleased_notes(released_lines)
+    if found is None:
+        return set()
+    return {note_key(note) for note in found[1]}
+
+
+def build_version_section(version: str, notes: list[list[str]]) -> list[str]:
+    section = [f"== {version}\n", "\n"]
+    for note in notes:
+        section.extend(note)
+    return section
+
+
+def build_unreleased_section(heading: list[str], notes: list[list[str]]) -> list[str]:
+    if not notes:
+        return []
+    section = list(heading)
+    for note in notes:
+        section.extend(note)
+    return section
+
+
+def move_released_notes(version: str, released_lines: list[str], target_lines: list[str]) -> list[str] | None:
+    """Return the updated target lines, or None when there is nothing to move."""
+    keys = released_keys(released_lines)
+    if not keys:
+        return None
+
+    preamble, sections = split_sections(target_lines, "== ")
+    if any(section_heading(section) == f"== {version}" for section in sections):
+        return None
+
+    result = list(preamble)
+    for section in sections:
+        if section_heading(section) != UNRELEASED_HEADING:
+            result.extend(section)
+            continue
+
+        heading, notes = split_sections(section, "=== ")
+        shipped = [note for note in notes if note_key(note) in keys]
+        remaining = [note for note in notes if note_key(note) not in keys]
+
+        result.extend(build_unreleased_section(heading, remaining))
+        result.extend(build_version_section(version, shipped))
+
+    return result
+
+
+def main(argv: list[str]) -> int:
+    if len(argv) != 4:
+        print(__doc__, file=sys.stderr)
+        return 2
+
+    version, released_path, target_path = argv[1], Path(argv[2]), Path(argv[3])
+    released_lines = released_path.read_text().splitlines(keepends=True)
+    target_lines = target_path.read_text().splitlines(keepends=True)
+
+    updated = move_released_notes(version, released_lines, target_lines)
+    if updated is None:
+        print(f"Nothing to move for {version}: no unreleased upgrade notes shipped, or the section already exists.")
+        return 0
+
+    target_path.write_text("".join(updated))
+    print(f"Moved released upgrade notes under '== {version}' in {target_path}.")
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))