Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

build: write the release notes from feat and fix commits, one linked line each

wquguru3e49d502f8c1
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 82c5fb3..1b9b6b7 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -7,7 +7,7 @@ on:
workflow_dispatch:
inputs:
tag:
- description: "Tag to build, e.g. v2.1.0"
+ description: "Tag to build, e.g. v1.0.0"
required: true
permissions:
diff --git a/AGENTS.md b/AGENTS.md
index 4661ae4..86c8a69 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -37,7 +37,7 @@ scripts/test.sh # AGENTS.md check + unit tests
scripts/build.sh && open build/Cicada.app # dev build: own bundle id, settings, log
RELEASE=1 scripts/build.sh # release build
scripts/package.sh # DMG + zip + checksums
-scripts/release.sh <x.y.z> # needs a dated CHANGELOG section; CI publishes the tag
+scripts/release.sh <x.y.z> # writes the CHANGELOG section from commits; CI publishes the tag
scripts/deploy-site.sh # build the site, wrangler deploy to the cicada-site Worker (cicada.indaloop.app)
```
@@ -50,6 +50,7 @@ scripts/deploy-site.sh # build the site, wrangler deploy to the
## Conventions
- Match the existing naming and comment density; comments say why.
-- Every user-visible change gets a `CHANGELOG.md` line and a matching `site/changelog.json` item; keep `README.md` and `README.zh-CN.md` in step.
-- Commit messages are English only and follow Conventional Commits (`feat:`, `fix:`, `docs:`, `build:`, `refactor:`, `test:`, `chore:`).
+- Commit messages are English only and follow Conventional Commits (`feat:`, `fix:`, `docs:`, `build:`, `refactor:`, `test:`, `chore:`). `feat:` and `fix:` subjects are the release notes (`scripts/changelog.py`), one line each linked to the commit: say what the user gets in one plain sentence, one change per commit; website changes use `feat(site):` / `fix(site):`.
+- Every user-visible change also gets a Chinese item in `site/changelog.json`, the website's changelog; keep `README.md` and `README.zh-CN.md` in step.
+- Versions are semver from 1.0.0: patch for fixes only, minor for features, major only when users must grant permissions again.
- This file stays under 6 KB with these sections; `scripts/check-agents.py` enforces it in `scripts/test.sh`, CI and the pre-commit hook. Implementation detail belongs in code comments, not here.
diff --git a/scripts/changelog.py b/scripts/changelog.py
new file mode 100755
index 0000000..4b189ac
--- /dev/null
+++ b/scripts/changelog.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+"""Writes a version's CHANGELOG.md section from the commits since the last tag.
+
+scripts/changelog.py 1.0.1 # replaces "## Unreleased" (or adds a section) dated today
+scripts/changelog.py 1.0.1 --print # only prints the section
+
+Release notes are the commit subjects: feat: goes under New, fix: under Fixed, and a (site) scope
+under Website; chore/docs/build/test/refactor stay out. Each line links its commit. Lines written by
+hand under "## Unreleased" stay on top, as the release's one-line summary.
+"""
+import datetime
+import os
+import re
+import subprocess
+import sys
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+REPO = "https://github.com/wquguru/cicada"
+SUBJECT = re.compile(r"^(feat|fix|perf)(?:\(([^)]*)\))?!?: (.+)$")
+
+
+def git(*args):
+ return subprocess.check_output(["git", *args], cwd=ROOT, text=True).strip()
+
+
+def commits():
+ try:
+ since = git("describe", "--tags", "--abbrev=0") + "..HEAD"
+ except subprocess.CalledProcessError:
+ since = "HEAD" # no tag yet: everything
+ out = git("log", "--reverse", "--format=%H%x09%s", since)
+ return [line.split("\t", 1) for line in out.splitlines() if line]
+
+
+def section(version, summary):
+ groups = {"New": [], "Fixed": [], "Website": []}
+ for sha, subject in commits():
+ m = SUBJECT.match(subject)
+ if not m:
+ continue
+ kind, scope, text = m.groups()
+ group = "Website" if scope == "site" else ("New" if kind == "feat" else "Fixed")
+ groups[group].append(f"- {text[0].upper() + text[1:]} ([{sha[:7]}]({REPO}/commit/{sha}))")
+ lines = [f"## {version} — {datetime.date.today().isoformat()}", ""]
+ if summary:
+ lines += [summary, ""]
+ for name, items in groups.items():
+ if items:
+ lines += [f"### {name}", "", *items, ""]
+ return "\n".join(lines)
+
+
+def main():
+ if len(sys.argv) < 2 or not re.fullmatch(r"\d+\.\d+\.\d+", sys.argv[1]):
+ sys.exit("usage: scripts/changelog.py <x.y.z> [--print]")
+ version = sys.argv[1]
+ path = os.path.join(ROOT, "CHANGELOG.md")
+ text = open(path, encoding="utf-8").read()
+ # The "## Unreleased" block, if any: its text becomes the summary.
+ m = re.search(r"^## Unreleased\n(.*?)(?=^## |\Z)", text, re.M | re.S)
+ summary = m.group(1).strip() if m else ""
+ new = section(version, summary)
+ if "--print" in sys.argv:
+ print(new)
+ return
+ if m:
+ text = text[:m.start()] + new + "\n" + text[m.end():]
+ else:
+ first = re.search(r"^## ", text, re.M)
+ at = first.start() if first else len(text)
+ text = text[:at] + new + "\n" + text[at:]
+ open(path, "w", encoding="utf-8").write(text)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/scripts/release.sh b/scripts/release.sh
index 37c33ca..707316f 100755
--- a/scripts/release.sh
+++ b/scripts/release.sh
@@ -1,17 +1,22 @@
#!/usr/bin/env bash
-# Cuts a release: scripts/release.sh 2.1.0
-# Needs a "## 2.1.0 — <today>" section in CHANGELOG.md. Sets the version in Resources/Info.plist,
-# commits, tags v<version> and pushes; the release workflow builds and publishes the DMG.
+# Cuts a release: scripts/release.sh 1.0.1
+# Writes the CHANGELOG.md section from the commits since the last tag, sets the version in
+# Resources/Info.plist, commits, tags v<version> and pushes; the release workflow builds and
+# publishes the DMG with that section as its notes.
set -euo pipefail
cd "$(dirname "$0")/.."
-VERSION=${1:?usage: scripts/release.sh <version, e.g. 2.1.0>}
+VERSION=${1:?usage: scripts/release.sh <version, e.g. 1.0.1>}
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "version must look like 1.2.3" >&2; exit 1; }
[[ -z "$(git status --porcelain)" ]] || { echo "working tree is not clean" >&2; exit 1; }
[[ "$(git branch --show-current)" == main ]] || { echo "release from main" >&2; exit 1; }
git rev-parse "v$VERSION" >/dev/null 2>&1 && { echo "tag v$VERSION already exists" >&2; exit 1; }
-grep -q "^## $VERSION — $(date +%Y-%m-%d)" CHANGELOG.md \
- || { echo "add \"## $VERSION — $(date +%Y-%m-%d)\" to CHANGELOG.md first" >&2; exit 1; }
+# The CHANGELOG.md section comes from the feat:/fix: commits since the last tag (scripts/changelog.py);
+# a section already dated today, written by hand, is kept as it is.
+if ! grep -q "^## $VERSION — $(date +%Y-%m-%d)" CHANGELOG.md; then
+ scripts/changelog.py "$VERSION"
+ git commit -m "docs: changelog for $VERSION" CHANGELOG.md
+fi
CURRENT=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" Resources/Info.plist)
if [[ "$CURRENT" != "$VERSION" ]]; then
diff --git a/scripts/release_notes.sh b/scripts/release_notes.sh
index 30854b9..fcd6d16 100755
--- a/scripts/release_notes.sh
+++ b/scripts/release_notes.sh
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
-# Prints the release notes for one version: its CHANGELOG.md section, then .github/release-notes.md.
-# scripts/release_notes.sh 2.0.0
+# Prints the release notes for one version: its CHANGELOG.md section, a compare link to the version
+# below it, the Chinese changelog on the website, then .github/release-notes.md.
+# scripts/release_notes.sh 1.0.0
set -euo pipefail
cd "$(dirname "$0")/.."
VERSION=${1:?usage: scripts/release_notes.sh <version>}
@@ -8,5 +9,11 @@ awk -v v="$VERSION" '
/^## / { on = ($2 == v) ; next }
on { print }
' CHANGELOG.md | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
+PREV=$(awk -v v="$VERSION" '/^## / { if (seen) { print $2; exit } if ($2 == v) seen = 1 }' CHANGELOG.md)
+echo
+echo "---"
+echo
+[[ -n "$PREV" ]] && echo "**Full changelog**: https://github.com/wquguru/cicada/compare/v$PREV...v$VERSION" && echo
+echo "中文更新说明:https://cicada.indaloop.app/changelog/"
echo
cat .github/release-notes.md
diff --git a/scripts/site.py b/scripts/site.py
index 1ef80b2..cb626bd 100755
--- a/scripts/site.py
+++ b/scripts/site.py
@@ -46,7 +46,7 @@ SPEAK_AT = 5.5
LANGS = [("zh", ""), ("en", "en/"), ("ja", "ja/"), ("ko", "ko/")]
FONT_BASE = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&amp;family=Noto+Sans+SC:wght@400;500;700;900"
FONT_EXTRA = {"ja": "&amp;family=Noto+Sans+JP:wght@400;500;700;900", "ko": "&amp;family=Noto+Sans+KR:wght@400;500;700;900"}
-KINDS = [("new", "新功能"), ("improved", "改进"), ("fixed", "修复")]
+KINDS = [("new", "新功能"), ("improved", "改进"), ("changed", "改动"), ("fixed", "修复")]
e = html.escape