diff --git a/docs/modules/ROOT/pages/development/release.adoc b/docs/modules/ROOT/pages/development/release.adoc index fcce1720..9b1ed3fa 100644 --- a/docs/modules/ROOT/pages/development/release.adoc +++ b/docs/modules/ROOT/pages/development/release.adoc @@ -191,8 +191,9 @@ A release does not end on PyPI: it ends with a GitHub Release, as in the upstrea * `A.B.C.devN` becomes a GitHub pre-release. `A.B.C` and `A.B.C.postN` become a normal release, marked as the latest. * The notes come from `scripts/release_notes.py`. The milestone is named after the base `A.B.C` (`26.11.1` for `26.11.1`, `26.11.1.dev2` and `26.11.1.post1`). A pull request is listed when it is merged, has that milestone and its merge commit is in the tag, grouped by its first matching label: `bug` (Bug fixes), `performance` (Performance), `enhancement` (Features), `documentation` (Documentation), everything else under Other. Each line is the title and `(#N)`. The notes also have the install lines, the engine version and the PyPI pages of both packages. +* A pull request that changes only files under `.github/`, `tests/` or `scripts/` is listed in one collapsed *Internal* block instead, whatever its labels. * The notes of a final or `devN` release start with a *Changed behaviour* line that links `docs/modules/ROOT/pages/upgrading.adoc` in the tag, only when the title of that page is `Upgrading to A.B.C` for the release. Write the page, or move its title to the new version, before the tag. -* A final release lists the whole milestone. A `devN` lists only what is not in the previous dev tag of the same base. A pull request without the milestone is not in the notes of a final or dev release, so check the milestone before the tag. +* A final release lists the whole milestone, and a `devN` lists only what is not in the previous dev tag of the same base. Both leave out what an earlier release shipped (the newest final or `postN` tag of an earlier base): a pull request whose merge commit is in that tag, or that a commit of that `postN` line names as the source of a cherry-pick. Port a fix to a release line with `git cherry-pick -x`, which writes that line. A pull request without the milestone is not in the notes of a final or dev release, so check the milestone before the tag. * A `postN` does not use a milestone, because the final release closed it. Its notes list every pull request merged between the previous tag of the same base (the final or `post(N-1)`) and the tag, found from the commits of that range, whatever milestone the pull request has or none. * After a final release (not `devN`, not `postN`) the milestone `A.B.C` is closed, after what is still open in it moves to the next milestone. The next milestone is the open one with the earliest due date after this one; an open milestone without a due date counts as the latest, as it does for the auto-assignment, so it is taken when no dated one follows. When there is none, the workflow creates one named after the next upstream engine version (the base of the upstream `main` version, the same command as in <>) and due 30 days after the closed one. When that version cannot be read, or is the same version, nothing is moved or closed and the run fails with a message: create the next milestone with a due date and re-run the workflow. Every move is logged. The milestone auto-assignment of merged pull requests, where it is set up, then picks the next milestone, because the closed one is no longer open. * A run for a release that already exists edits its notes and flag, so a re-run is safe. diff --git a/scripts/release_notes.py b/scripts/release_notes.py index aa757651..2ea6aabd 100644 --- a/scripts/release_notes.py +++ b/scripts/release_notes.py @@ -5,7 +5,8 @@ by label, then the install lines, the engine version and the PyPI pages of the two packages. The notes of a `devN` and of a final release start with a `Changed behaviour` line that links the docs page `upgrading.adoc` as it is in the tag, when the title of that page is `Upgrading to A.B.C` for the base of the tag. The pull requests of a `devN` and of a -final release come from the milestone named after the base `A.B.C`; a `postN` does not use a milestone (see below). +final release come from the milestone named after the base `A.B.C`; a `postN` does not use a milestone (see below). A pull request +that changes only files under `.github/`, `tests/` or `scripts/` goes into one collapsed `Internal` block, whatever its labels. Which pull requests a tag lists: @@ -16,6 +17,10 @@ from the commits of that range, with whatever milestone it has or none: the final release closes the milestone `A.B.C`, so a fix made after it is not in it +A `devN` and a final release also leave out what an earlier release already shipped: the newest final or `postN` tag of an earlier +base. A pull request is shipped there when its merge commit is in that tag, or when a commit of that `postN` line says it is a +cherry-pick of the merge commit (`git cherry-pick -x`). + For `devN` and the final release "in a tag" means the merge commit of the pull request is an ancestor of the tag (the GitHub compare API), so a pull request that merges after the tag, while the release still runs, is not listed. A tag that does not exist yet (a dry run before the release) is read as the tip of the default branch. @@ -55,6 +60,10 @@ ("Documentation", "documentation"), ] OTHER = "Other" +# a pull request whose every file is under one of these is internal: a user of the packages does not see it +INTERNAL_PATHS = (".github/", "tests/", "scripts/") +# the line `git cherry-pick -x` adds to a commit message +PICKED_RE = re.compile(r"\(cherry picked from commit ([0-9a-f]{40})\)") # what behaves differently in a release; the title of the page names the release it is about UPGRADE_PAGE = "docs/modules/ROOT/pages/upgrading.adoc" @@ -121,6 +130,50 @@ def previous_tag(tag, existing): return best[1] if best else None +def previous_release(tag, existing): + """The newest final or postN tag of a base before the base of `tag`, or None: what a devN or final release comes after.""" + + def version(base): + return tuple(int(part) for part in base.split(".")) + + mine = version(parse_tag(tag)[0]) + best = None + for other in existing: + m = TAG_RE.match(other) + if not m or m.group("kind") == "dev" or version(m.group("base")) >= mine: + continue + key = ( + version(m.group("base")), + order_key(m.group("kind") or "final", int(m.group("n") or 0)), + ) + if best is None or key > best[0]: + best = (key, other) + return best[1] if best else None + + +def ported_shas(repo, release): + """The commits that the `postN` line of `release` carries as cherry-picks, empty for a release that is not a `postN`.""" + base, kind, _ = parse_tag(release) + if kind != "post": + return set() + shas = set() + for commit in compare_commits(repo, base, release): + shas.update(PICKED_RE.findall(commit.get("commit", {}).get("message") or "")) + return shas + + +def is_internal(repo, number): + """True when every file the pull request changes, under its new and its old name, is under one of INTERNAL_PATHS.""" + files = gh_pages(f"repos/{repo}/pulls/{number}/files") + names = [ + name + for entry in files + for name in (entry.get("filename"), entry.get("previous_filename")) + if name + ] + return bool(names) and all(name.startswith(INTERNAL_PATHS) for name in names) + + def section_of(labels): names = set(labels) for title, label in SECTIONS: @@ -255,6 +308,12 @@ def upgrade_page_url(repo, base, tag, ref): return f"https://github.com/{repo}/blob/{tag}/{UPGRADE_PAGE}" +def pr_line(pr): + """One line of the change list.""" + shown = safe_title(clean_title(pr["title"], pr["number"])) + return f"- {shown} (#{pr['number']})" + + def build_notes(repo, tag): base, kind, n = parse_tag(tag) default_branch = (gh_api(f"repos/{repo}") or {}).get("default_branch", "main") @@ -272,6 +331,8 @@ def build_notes(repo, tag): prev = previous_tag(tag, [t for t in tags if t != tag]) milestone = None listed = [] + shipped = None + skipped = 0 if kind == "post": if prev: listed = range_prs(repo, prev, ref) @@ -279,11 +340,18 @@ def build_notes(repo, tag): print(f"warning: no earlier tag of {base} for {tag}", file=sys.stderr) else: milestone, prs = milestone_prs(repo, base) + shipped = previous_release(tag, tags) + ported = ported_shas(repo, shipped) if shipped and prs else set() for pr in prs: if not is_ancestor(repo, pr["sha"], ref): continue if prev and is_ancestor(repo, pr["sha"], prev): continue + if shipped and ( + pr["sha"] in ported or is_ancestor(repo, pr["sha"], shipped) + ): + skipped += 1 + continue listed.append(pr) listed.sort(key=lambda p: p["number"]) # a pull request that only merges a release line back into main is bookkeeping: it is not listed, and a release that has nothing else says so @@ -291,8 +359,12 @@ def build_notes(repo, tag): groups = {title: [] for title, _ in SECTIONS} groups[OTHER] = [] + internal = [] for pr in listed: - groups[section_of(pr["labels"])].append(pr) + if is_internal(repo, pr["number"]): + internal.append(pr) + else: + groups[section_of(pr["labels"])].append(pr) engine, engine_kind = engine_of(repo, kind, base, ref) lines = [] @@ -324,6 +396,11 @@ def build_notes(repo, tag): scope = "since the previous release" lines.append(f"## What changed {scope}") lines.append("") + if skipped: + lines.append( + f"What shipped in `{shipped}` or an earlier release is not listed again." + ) + lines.append("") if not listed: lines.append("No merged pull request.") lines.append("") @@ -332,9 +409,17 @@ def build_notes(repo, tag): continue lines.append(f"### {title}") lines.append("") - for pr in groups[title]: - shown = safe_title(clean_title(pr["title"], pr["number"])) - lines.append(f"- {shown} (#{pr['number']})") + lines.extend(pr_line(pr) for pr in groups[title]) + lines.append("") + if internal: + lines.append("
") + lines.append( + f"Internal: CI, tests, and release tooling only ({len(internal)})" + ) + lines.append("") + lines.extend(pr_line(pr) for pr in internal) + lines.append("") + lines.append("
") lines.append("") lines.append("## Install") diff --git a/tests/test_release_notes_shipped_and_internal.py b/tests/test_release_notes_shipped_and_internal.py new file mode 100644 index 00000000..e08650e5 --- /dev/null +++ b/tests/test_release_notes_shipped_and_internal.py @@ -0,0 +1,164 @@ +"""scripts/release_notes.py: what an earlier release already shipped is not listed again, and internal pull requests are collapsed. + +A final or `devN` release lists its milestone. Fixes that also went out in a `postN` release of the base before it (as an ancestor of +the tag, or as a cherry-pick that names the commit) are left out, and a pull request that changes only `.github/`, `tests/` or +`scripts/` goes into one collapsed block. No network: the API calls are faked. +""" + +from __future__ import annotations + +import importlib.util +from pathlib import Path + +import pytest + +SCRIPT = Path(__file__).resolve().parents[1] / "scripts" / "release_notes.py" + + +def _load(): + spec = importlib.util.spec_from_file_location( + "release_notes_shipped_and_internal", SCRIPT + ) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + spec.loader.exec_module(module) + return module + + +notes = _load() + + +@pytest.mark.parametrize( + "tag,previous", + [ + ("26.12.1", "26.11.1.post10"), + ("26.12.1.dev0", "26.11.1.post10"), + ("27.1.1", "26.12.1"), + ("26.11.1", None), + ("26.11.1.post3", None), + ], +) +def test_the_previous_release_is_the_newest_final_or_post_of_an_earlier_base( + tag, previous +): + tags = [ + "26.11.1.dev0", + "26.11.1", + "26.11.1.post2", + "26.11.1.post10", + "26.12.1.dev2", + "26.12.1", + "not-a-release", + ] + assert notes.previous_release(tag, [t for t in tags if t != tag]) == previous + + +def _sha(n): + return f"{n:040x}" + + +# number: (title, labels, the files it changes) +PULLS = { + 1: ("A fix a user sees", ["bug"], ["src/arcadedb/core.py", "tests/test_core.py"]), + 2: ("Merged before the post release", ["bug"], ["src/arcadedb/core.py"]), + 3: ("Ported to the post release", ["performance"], ["src/arcadedb/results.py"]), + 4: ("A flaky test", ["bug"], ["tests/test_a.py", ".github/workflows/x.yml"]), + 5: ("A release script", [], ["scripts/release_notes.py"]), + 6: ("A build script and a page", [], ["scripts/build.sh", "docs/page.adoc"]), + 7: ("A module that moved into tests", [], [("tests/helper.py", "src/helper.py")]), +} +TAGS = ["26.11.1", "26.11.1.post1", "26.12.1.dev0"] + + +def _fake(monkeypatch, tags=TAGS): + """A repository whose milestone 26.12.1 holds PULLS: #2 is an ancestor of 26.11.1.post1, #3 is cherry-picked into it.""" + + def gh_api(path): + if path == "repos/o/r": + return {"default_branch": "main"} + if path.startswith("repos/o/r/pulls/"): + number = int(path.rsplit("/", 1)[1]) + return {"merge_commit_sha": _sha(number)} + if path == "repos/o/r/compare/26.11.1...26.11.1.post1?per_page=100&page=1": + message = f"Port a fix\n\n(cherry picked from commit {_sha(3)})\n" + return {"commits": [{"sha": _sha(99), "commit": {"message": message}}]} + if path.startswith("repos/o/r/compare/"): + pair = path[len("repos/o/r/compare/") :].split("?")[0] + sha, ref = pair.split("...") + number = int(sha, 16) + inside = ref == "main" or (ref == "26.11.1.post1" and number == 2) + return {"status": "ahead" if inside else "diverged"} + return None + + def gh_pages(path): + if path == "repos/o/r/tags": + return [{"name": name} for name in tags] + if path.startswith("repos/o/r/milestones"): + return [{"title": "26.12.1", "number": 2}] + if path.startswith("repos/o/r/issues?milestone=2"): + return [ + { + "number": number, + "title": title, + "labels": [{"name": label} for label in labels], + "pull_request": {"merged_at": "2026-11-20T00:00:00Z"}, + } + for number, (title, labels, _) in PULLS.items() + ] + if path.startswith("repos/o/r/pulls/") and path.endswith("/files"): + files = PULLS[int(path.split("/")[4])][2] + return [ + ( + {"filename": f[0], "previous_filename": f[1]} + if isinstance(f, tuple) + else {"filename": f} + ) + for f in files + ] + return [] + + monkeypatch.setattr(notes, "gh_api", gh_api) + monkeypatch.setattr(notes, "gh_pages", gh_pages) + + +def _split(text): + """(the notes before the collapsed block, the block).""" + head, _, rest = text.partition("
") + return head, rest.partition("
")[0] + + +def test_a_final_release_leaves_out_what_shipped_and_collapses_internal_changes( + monkeypatch, +): + _fake(monkeypatch) + text = notes.build_notes("o/r", "26.12.1") + head, block = _split(text) + + assert "(#2)" not in text and "(#3)" not in text + assert "What shipped in `26.11.1.post1` or an earlier release is not listed" in head + assert "### Bug fixes\n\n- A fix a user sees (#1)\n" in head + assert "- A build script and a page (#6)" in head + assert "- A module that moved into tests (#7)" in head + assert "(#4)" not in head and "(#5)" not in head + assert "Internal: CI, tests, and release tooling only (2)" in block + assert "- A flaky test (#4)\n- A release script (#5)\n" in block + + +def test_without_an_earlier_release_nothing_is_left_out(monkeypatch): + _fake(monkeypatch, tags=["26.12.1.dev0"]) + text = notes.build_notes("o/r", "26.12.1") + assert "(#2)" in text and "(#3)" in text + assert "is not listed again" not in text + + +def test_a_release_with_only_internal_changes_still_lists_them(monkeypatch): + _fake(monkeypatch) + monkeypatch.setitem(PULLS, 1, ("A test only", ["bug"], ["tests/test_core.py"])) + for number in (6, 7): + monkeypatch.setitem(PULLS, number, ("Tooling", [], ["scripts/x.sh"])) + text = notes.build_notes("o/r", "26.12.1") + assert "###" not in text + assert "No merged pull request." not in text + assert ( + "Internal: CI, tests, and release tooling only (5)" in text + )