diff --git a/.github/scripts/release_notes_by_component.py b/.github/scripts/release_notes_by_component.py new file mode 100644 index 0000000000..1fedcdeb16 --- /dev/null +++ b/.github/scripts/release_notes_by_component.py @@ -0,0 +1,277 @@ +#!/usr/bin/env python3 +"""Regroup a GitHub release's generated notes by component. + +GitHub's generated notes are one flat list of PRs in merge order. This keeps every +line as GitHub wrote it, but sorts the PRs under component headings (S3 API, Filer, +Mount, Volume Server, ...), with dependency bumps folded at the end. + +The component comes from the PR title prefix, which nearly every PR has +("s3api: ...", "fix(mount): ...", "filer.sync: ...", "rust volume: ..."). A PR with +no recognised prefix is placed by the files it changes. + +Usage: + release_notes_by_component.py --tag 4.54 # print the regrouped notes + release_notes_by_component.py --tag 4.54 --write # also update the release + +Running it again on notes it already regrouped gives the same result. +""" + +import argparse +import json +import re +import subprocess +import sys + +# Display order. Each PR lands in exactly one section. +SECTIONS = [ + "S3 API", + "S3 Tables and Iceberg", + "Vectors", + "Filer", + "Mount", + "Volume Server", + "Rust Volume Server", + "Erasure Coding", + "Master and Topology", + "Admin UI and Workers", + "Shell", + "Security", + "Message Queue", + "Kubernetes, Helm and Deployment", + "Core and CLI", + "Documentation", + "Tests and CI", + "Other", + "Dependencies", +] + +# Title scope -> section, first match wins. Matched against each lower-cased scope +# token, e.g. "filer.sync", "s3 lifecycle", "weed/s3api" (a "weed/" prefix is +# dropped first). Order matters: specific scopes come before the general ones +# they start with (s3tables before s3, volume.fsck before volume). +SCOPE_RULES = [ + (r"(build\(deps\)|deps|dependabot)\b", "Dependencies"), + (r"(test|tests|e2e|integration)\b|.*\btests?$|test/", "Tests and CI"), + (r"(rust[ -]?volume|seaweed-volume|volume\(rust\)|rust)\b", "Rust Volume Server"), + (r"(s3 ?vectors?|vectors?|seaweed-vector|weed-vector|lance)\b", "Vectors"), + (r"(s3 ?tables|iceberg)\b", "S3 Tables and Iceberg"), + (r"(s3 sink|remote|remote_storage|filer|webdav|sftp|ftp|notification|replication|" + r"redis\d*|leveldb\d*|backup)\b", "Filer"), + (r"(s3|s3api|iam|oidc|sts|credential|sse|cors|policy|object ?lock)\b", "S3 API"), + (r"(mount|fuse)\b", "Mount"), + (r"(ec|ec_\w+|ec\.\w+|erasure[ _-]?coding|worker/ec)\b", "Erasure Coding"), + (r"(master|topology|wdclient|cluster|raft|placement)\b", "Master and Topology"), + (r"(admin|worker|weed-worker|plugin|plugin worker|maintenance)\b", + "Admin UI and Workers"), + (r"(shell|fsck|volume\.\w+|fs\.\w+|collection\.\w+|bucket\.\w+)", "Shell"), + (r"(volume|volume_\w+|storage|vacuum|operation|compression|needle)\b", "Volume Server"), + (r"(security|tls|mtls|jwt|grpc|kms)\b", "Security"), + (r"(mq|kafka|messaging)\b", "Message Queue"), + (r"(helm|k8s|kubernetes|operator|csi|docker|grafana|install\.sh|chart|snap|terraform)\b", + "Kubernetes, Helm and Deployment"), + (r"(docs?|readme|wiki)\b", "Documentation"), + (r"(ci|release|build|github|workflow|actions)\b", "Tests and CI"), + (r"(server|command|mini|weed-db|weed|util|pb|cmd|glog|stats|telemetry|query|config)\b", + "Core and CLI"), +] + +# Changed path prefix -> section, for PRs whose title has no usable prefix. +# Longest prefix wins. +PATH_RULES = { + "weed/s3api/s3tables/": "S3 Tables and Iceberg", + "weed/s3api/iceberg/": "S3 Tables and Iceberg", + "weed/s3api/s3vectors/": "Vectors", + "weed/s3api/lance/": "Vectors", + "seaweed-vector/": "Vectors", + "weed/s3api/": "S3 API", + "weed/iam/": "S3 API", + "weed/iamapi/": "S3 API", + "weed/credential/": "S3 API", + "weed/filer/": "Filer", + "weed/filer_client/": "Filer", + "weed/server/filer": "Filer", + "weed/server/webdav": "Filer", + "weed/sftpd/": "Filer", + "weed/replication/": "Filer", + "weed/notification/": "Filer", + "weed/remote_storage/": "Filer", + "weed/mount/": "Mount", + "weed/storage/erasure_coding/": "Erasure Coding", + "weed/ec/": "Erasure Coding", + "weed/worker/tasks/erasure_coding/": "Erasure Coding", + "weed/storage/": "Volume Server", + "weed/server/volume": "Volume Server", + "weed/operation/": "Volume Server", + "seaweed-volume/": "Rust Volume Server", + "weed/topology/": "Master and Topology", + "weed/server/master": "Master and Topology", + "weed/wdclient/": "Master and Topology", + "weed/cluster/": "Master and Topology", + "weed/placement/": "Master and Topology", + "weed/admin/": "Admin UI and Workers", + "weed/worker/": "Admin UI and Workers", + "weed/plugin/": "Admin UI and Workers", + "seaweed-worker/": "Admin UI and Workers", + "weed/shell/": "Shell", + "weed/security/": "Security", + "weed/kms/": "Security", + "weed/mq/": "Message Queue", + "k8s/": "Kubernetes, Helm and Deployment", + "docker/": "Kubernetes, Helm and Deployment", + "snap/": "Kubernetes, Helm and Deployment", + "terraform/": "Kubernetes, Helm and Deployment", + "weed/": "Core and CLI", + "test/": "Tests and CI", + ".github/": "Tests and CI", +} + +PR_LINE = re.compile(r"^\* (?P.+?) by @\S+ in https://github\.com/\S+/pull/(?P<num>\d+)\s*$") +# "fix(s3tables,s3vectors): ...", "s3 lifecycle: ...", "[Volume] ...", "Fix/admin ..." +CONVENTIONAL = re.compile(r"^(?P<type>[a-z]+)\((?P<scope>[^)]*)\)!?$") +TYPE_ONLY = {"fix", "feat", "feature", "perf", "refactor", "chore", "style", "revert", "improvement"} + + +def scope_of(title): + """Return the raw scope text of a PR title, or "".""" + t = title.strip() + m = re.match(r"^\[([^\]]{1,40})\]", t) + if m: + return m.group(1) + m = re.match(r"^(?:fix|feat|feature)/(\S+)", t, re.I) + if m: + return m.group(1) + head, sep, _ = t.partition(":") + if not sep or len(head) > 50: + return "" + head = head.strip() + m = CONVENTIONAL.match(head.lower()) + if m: + kind, scope = m.group("type"), m.group("scope") + if kind in ("test", "tests", "ci"): + return "test" + if kind == "docs": + return "docs" + if kind == "build" and scope == "deps": + return "build(deps)" + return scope + if head.lower() in TYPE_ONLY: + return "" + return head + + +def section_by_scope(scope): + if scope.strip().lower() == "build(deps)": + return "Dependencies" + for token in re.split(r"\s*[,+&]\s*|\s+and\s+", scope.lower()): + token = token.strip() + token = re.sub(r"^weed[/ ]", "", token) + if not token: + continue + for pattern, section in SCOPE_RULES: + if re.match(pattern, token): + return section + return "" + + +def section_by_paths(paths): + votes = {} + code = [p for p in paths if not p.endswith("_test.go") and not p.endswith("_test.rs")] + for p in code or paths: + if p.endswith(".md"): + section = "Documentation" + else: + best = max((pre for pre in PATH_RULES if p.startswith(pre)), key=len, default="") + section = PATH_RULES.get(best, "Other") + votes[section] = votes.get(section, 0) + 1 + if not votes: + return "Other" + # Most files wins; ties go to the earlier section in display order. + return max(votes, key=lambda s: (votes[s], -SECTIONS.index(s))) + + +def classify(title, author, pr_files): + if author.startswith("dependabot") or title.lower().startswith("build(deps)"): + return "Dependencies" + section = section_by_scope(scope_of(title)) + if section: + return section + return section_by_paths(pr_files()) + + +def split_notes(body): + """Split generated notes into (PR lines, the text before them, the text after).""" + lines = body.replace("\r\n", "\n").split("\n") + start = next((i for i, l in enumerate(lines) if l.strip() == "## What's Changed"), None) + if start is None: + return [], body, "" + end = next((i for i in range(start + 1, len(lines)) if lines[i].startswith("## ")), len(lines)) + prs = [l for l in lines[start + 1:end] if PR_LINE.match(l)] + before = "\n".join(lines[:start]).rstrip() + after = "\n".join(lines[end:]).strip() + return prs, before, after + + +def regroup(body, pr_files): + prs, before, after = split_notes(body) + if not prs: + return body + groups = {s: [] for s in SECTIONS} + for line in prs: + m = PR_LINE.match(line) + author = re.search(r" by @(\S+) in ", line).group(1) + num = int(m.group("num")) + groups[classify(m.group("title"), author, lambda: pr_files(num))].append(line) + + out = [before, ""] if before else [] + out.append("## What's Changed") + for section in SECTIONS: + items = groups[section] + if not items: + continue + out.append("") + if section == "Dependencies": + out.append("<details><summary>Dependencies (%d update%s)</summary>" % (len(items), "" if len(items) == 1 else "s")) + out.append("") + out.extend(items) + out.append("") + out.append("</details>") + else: + out.append("### " + section) + out.extend(items) + if after: + out.extend(["", after]) + return "\n".join(out).strip() + "\n" + + +def gh(*args, stdin=None): + return subprocess.run(["gh", *args], input=stdin, capture_output=True, text=True, check=True).stdout + + +def main(): + ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + ap.add_argument("--repo", default="seaweedfs/seaweedfs") + ap.add_argument("--tag", required=True) + ap.add_argument("--write", action="store_true", help="update the release notes on GitHub") + args = ap.parse_args() + + body = json.loads(gh("release", "view", args.tag, "-R", args.repo, "--json", "body"))["body"] + + def pr_files(num): + try: + out = gh("pr", "view", str(num), "-R", args.repo, "--json", "files", "--jq", ".files[].path") + except subprocess.CalledProcessError as e: + print("warning: files of #%d: %s" % (num, e.stderr.strip()), file=sys.stderr) + return [] + return out.split() + + notes = regroup(body, pr_files) + if notes.strip() == body.replace("\r\n", "\n").strip(): + print("release %s: notes already grouped, nothing to change" % args.tag, file=sys.stderr) + sys.stdout.write(notes) + if args.write: + gh("release", "edit", args.tag, "-R", args.repo, "--notes-file", "-", stdin=notes) + print("release %s: notes updated" % args.tag, file=sys.stderr) + + +if __name__ == "__main__": + main() diff --git a/.github/scripts/test_release_notes_by_component.py b/.github/scripts/test_release_notes_by_component.py new file mode 100644 index 0000000000..add73802a9 --- /dev/null +++ b/.github/scripts/test_release_notes_by_component.py @@ -0,0 +1,155 @@ +import importlib.util +from pathlib import Path +import unittest + + +def load(): + path = Path(__file__).with_name("release_notes_by_component.py") + spec = importlib.util.spec_from_file_location("release_notes_by_component", path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +rn = load() + + +def no_files(num): + raise AssertionError("files of #%d should not be needed" % num) + + +class ClassifyTest(unittest.TestCase): + def check(self, title, section, author="someone", files=None): + got = rn.classify(title, author, (lambda: files) if files is not None else (lambda: no_files(0))) + self.assertEqual(got, section, title) + + def test_title_prefixes(self): + cases = { + "s3: keep serving for -preStopSeconds after SIGTERM": "S3 API", + "s3api: keep a multipart upload's state on the object's owner filer": "S3 API", + "fix(s3api): reject an invalid storage class before uploading the body": "S3 API", + "s3 lifecycle: count filer entries a walk reads but skips as progress": "S3 API", + "iam/oidc: accept a list audience": "S3 API", + "fix(s3tables,s3vectors): bind DeleteNamespace to the authorized records": "S3 Tables and Iceberg", + "iceberg maintenance: expire snapshots": "S3 Tables and Iceberg", + "s3vectors: support TagResource": "Vectors", + "s3 vectors: page ListVectors": "Vectors", + "vector: compact segments": "Vectors", + "filer: fail health check when absent from lock ring": "Filer", + "filer.sync: skip a rewritten source version": "Filer", + "filer.remote.sync: retry": "Filer", + "webdav: honor locks": "Filer", + "remote.uncache, remote.meta.sync, remote.cache: keep local writes": "Filer", + "mount: cache dir": "Mount", + "fix(mount): flush on close": "Mount", + "volume: keep reads over the download limit local": "Volume Server", + "[Volume] Preserve request semantics in replica proxy reads": "Volume Server", + "operation: pad the marginal gzip test": "Volume Server", + "fix(storage): update deletion metrics": "Volume Server", + "rust volume: bulk-load needle maps": "Rust Volume Server", + "seaweed-volume: pin the status": "Rust Volume Server", + "volume(rust): fix": "Rust Volume Server", + "ec: mount shards through the encode's .vif": "Erasure Coding", + "ec.rebuild: pick the right disk": "Erasure Coding", + "ec_balance: spread shards": "Erasure Coding", + "master: unregister a volume server whose heartbeats stop": "Master and Topology", + "topology: never report negative free volume slots": "Master and Topology", + "wdclient: let master-pushed adds replace locations": "Master and Topology", + "admin: manage filer webhook targets": "Admin UI and Workers", + "Fix/admin cluster submenu": "Admin UI and Workers", + "weed-worker: retry": "Admin UI and Workers", + "shell: fix s3.circuitBreaker help examples": "Shell", + "volume.fsck: skip deleted": "Shell", + "fix(fsck): inspect references to deleted volumes": "Shell", + "security: optional dialed-host check": "Security", + "helm: drop the 4.53 vector metrics render guard": "Kubernetes, Helm and Deployment", + "install.sh: add --enterprise": "Kubernetes, Helm and Deployment", + "mq/kafka: commit offsets": "Message Queue", + "server: add -grpc.localSocketDir": "Core and CLI", + "pb: recover when a local gRPC socket file is deleted": "Core and CLI", + "docs: explain the 3-filer recommendation": "Documentation", + "test(fuse): two mounts staging the same files": "Tests and CI", + "test/s3vectors: a hardened cluster": "Tests and CI", + "s3vectors test: cover tags": "Tests and CI", + "ci: run the Python 3.9 jobs on 3.10": "Tests and CI", + "build(deps): bump actions/setup-go from 6 to 7": "Dependencies", + } + for title, section in cases.items(): + self.check(title, section) + + def test_dependabot_author(self): + self.check("Bump x from 1 to 2", "Dependencies", author="dependabot[bot]") + + def test_no_prefix_uses_files(self): + self.check("Fix s3 cancelled read relookup", "S3 API", + files=["weed/s3api/s3api_object_handlers.go", "weed/s3api/s3api_object_handlers_test.go"]) + self.check("Retry transient failures in star history generation", "Tests and CI", + files=[".github/scripts/star_history.py"]) + self.check("fix: handle empty chunk list", "Filer", + files=["weed/filer/filechunks.go", "weed/storage/needle/needle.go", "weed/filer/reader_at.go"]) + self.check("Improve everything", "Other", files=[]) + + def test_test_files_count_only_when_alone(self): + self.check("Make it faster", "Mount", + files=["weed/mount/weedfs.go", "test/fuse/a_test.go", "test/fuse/b_test.go"]) + + +NOTES = """## What's Changed +* filer: fail health check when absent from lock ring by @a in https://github.com/seaweedfs/seaweedfs/pull/12709 +* s3: answer ClientDisconnected by @b in https://github.com/seaweedfs/seaweedfs/pull/12707 +* build(deps): bump actions/setup-go from 6 to 7 by @dependabot[bot] in https://github.com/seaweedfs/seaweedfs/pull/12685 +* filer.sync: skip a rewritten source version by @a in https://github.com/seaweedfs/seaweedfs/pull/12366 +* Fix s3 cancelled read relookup by @c in https://github.com/seaweedfs/seaweedfs/pull/12600 + +## New Contributors +* @c made their first contribution in https://github.com/seaweedfs/seaweedfs/pull/12600 + +**Full Changelog**: https://github.com/seaweedfs/seaweedfs/compare/4.53...4.54 +""" + + +class RegroupTest(unittest.TestCase): + def files(self, num): + self.assertEqual(num, 12600) + return ["weed/s3api/s3api_object_handlers.go"] + + def test_regroup(self): + out = rn.regroup(NOTES, self.files) + self.assertEqual(out, """## What's Changed + +### S3 API +* s3: answer ClientDisconnected by @b in https://github.com/seaweedfs/seaweedfs/pull/12707 +* Fix s3 cancelled read relookup by @c in https://github.com/seaweedfs/seaweedfs/pull/12600 + +### Filer +* filer: fail health check when absent from lock ring by @a in https://github.com/seaweedfs/seaweedfs/pull/12709 +* filer.sync: skip a rewritten source version by @a in https://github.com/seaweedfs/seaweedfs/pull/12366 + +<details><summary>Dependencies (1 update)</summary> + +* build(deps): bump actions/setup-go from 6 to 7 by @dependabot[bot] in https://github.com/seaweedfs/seaweedfs/pull/12685 + +</details> + +## New Contributors +* @c made their first contribution in https://github.com/seaweedfs/seaweedfs/pull/12600 + +**Full Changelog**: https://github.com/seaweedfs/seaweedfs/compare/4.53...4.54 +""") + + def test_idempotent(self): + once = rn.regroup(NOTES, self.files) + self.assertEqual(rn.regroup(once, self.files), once) + + def test_every_pr_kept(self): + out = rn.regroup(NOTES, self.files) + for n in (12709, 12707, 12685, 12366, 12600): + self.assertEqual(out.count("/pull/%d\n" % n), 2 if n == 12600 else 1) + + def test_notes_without_prs_unchanged(self): + body = "Hand-written notes\n\n**Full Changelog**: x" + self.assertEqual(rn.regroup(body, no_files), body) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/release_version_bump.yml b/.github/workflows/release_version_bump.yml index 3ad9633fa4..b1989af805 100644 --- a/.github/workflows/release_version_bump.yml +++ b/.github/workflows/release_version_bump.yml @@ -4,7 +4,9 @@ name: "release: bump version and cut the release" # 1. bump MAJOR/MINOR in constants.go and the Helm Chart.yaml, commit to master # 2. push the <appVersion> tag, which fans out to the workflows that trigger on # `push: tags` (binaries_release*, container_release_unified, helm_manual_release) -# 3. create the GitHub release, with GitHub's generated notes +# 3. create the GitHub release, with GitHub's generated notes, then regroup those +# notes by component (S3 API, Filer, Mount, ...) with +# .github/scripts/release_notes_by_component.py # 4. dispatch "Prepare release" in seaweedfs-csi-driver and seaweedfs-operator, # which pick up the new master through `go get -u`, and wait for both # @@ -41,6 +43,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + pull-requests: read # the notes step reads a PR's files when its title has no component prefix outputs: app_version: ${{ steps.compute.outputs.app_version }} sha: ${{ steps.tag.outputs.sha }} @@ -174,6 +177,19 @@ jobs: TAG: ${{ steps.compute.outputs.app_version }} run: gh release create "$TAG" --title "$TAG" --generate-notes --verify-tag + # GitHub's generated notes are one flat list of PRs. Sort them under + # component headings by title prefix (or changed files). The release is + # already published, so a failure here only leaves the flat list; rerun + # the script by hand to fix it: + # python3 .github/scripts/release_notes_by_component.py --tag <tag> --write + - name: Group the release notes by component + if: ${{ !inputs.dry_run }} + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.RELEASE_PAT || secrets.GITHUB_TOKEN }} + TAG: ${{ steps.compute.outputs.app_version }} + run: python3 .github/scripts/release_notes_by_component.py --repo "$GITHUB_REPOSITORY" --tag "$TAG" --write > /dev/null + downstream: needs: release if: ${{ inputs.downstream && !inputs.dry_run }}