知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
build: one release commit holds the changelog, VERSION and the site's date, and a recut rewrites it
wquguru33be17e7d76d
diff --git a/scripts/changelog.py b/scripts/changelog.pyindex 230e4d0..82edb23 100755--- a/scripts/changelog.py+++ b/scripts/changelog.py@@ -9,7 +9,8 @@ picks it, (windows) (android) (linux) or (site) for the website, (ios) none yet,New and fix: under Fixed; chore/docs/build/test/refactor stay out. Every release ships everyplatform, so one with no feat or fix still gets a group saying so. `fix(windows,linux):` lands in both.Each line links its commit. Lines written by hand under "## Unreleased" stay on top, as the-release's one-line summary.+release's one-line summary. Run again for the same version (a draft recut after a fix), it rewrites+that version's section and keeps its summary."""import datetimeimport os@@ -86,9 +87,13 @@ def main():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.+ # The "## Unreleased" block, if any: its text becomes the summary. A recut replaces the+ # version's own section instead, keeping the summary above its first platform group.m = re.search(r"^## Unreleased\n(.*?)(?=^## |\Z)", text, re.M | re.S)summary = m.group(1).strip() if m else ""+ if not m:+ m = re.search(rf"^## {re.escape(version)} — .*?\n(.*?)(?=^## |\Z)", text, re.M | re.S)+ summary = m.group(1).split("\n### ", 1)[0].strip() if m else ""new = section(version, summary)if "--print" in sys.argv:print(new)diff --git a/scripts/deploy-site.sh b/scripts/deploy-site.shindex 1eb5692..f49abc9 100755--- a/scripts/deploy-site.sh+++ b/scripts/deploy-site.sh@@ -5,6 +5,11 @@set -euo pipefailcd "$(dirname "$0")/.."+# A version dated in site/changelog.json shows as released, and scripts/release.sh dates it in the+# release commit, before the draft is published: don't put it on the site until then.+dated=$(python3 -c 'import json; print(next(e["version"] for e in json.load(open("site/changelog.json")) if e.get("date")))')+[[ "$(gh release view "v$dated" -R wquguru/cicada --json isDraft -q .isDraft 2>/dev/null)" == false ]] ||+ { echo "v$dated is not published yet: deploy the site after scripts/publish-release.sh" >&2; exit 1; }python3 scripts/site.pyCONFIG=$(mktemp -d)trap 'rm -rf "$CONFIG"' EXITdiff --git a/scripts/publish-release.sh b/scripts/publish-release.shindex 21b5809..f243f06 100755--- a/scripts/publish-release.sh+++ b/scripts/publish-release.sh@@ -10,6 +10,12 @@ REPO=wquguru/cicada[[ "$(gh release view "$TAG" -R "$REPO" --json isDraft -q .isDraft)" == true ]] || { echo "$TAG is not a draft" >&2; exit 1; }assets=$(gh release view "$TAG" -R "$REPO" --json assets -q '.assets[].name')echo "$assets"+# Every release ships every platform: refuse a draft that is missing one (the release workflow+# leaves Android out with only a warning when its signing key is missing).+for f in checksums.txt macOS-AppleSilicon.dmg macOS-AppleSilicon.zip macOS-Intel.dmg Windows-x64.exe \+ Windows-ARM64.exe Android.apk Linux.tar.gz; do+ grep -q -- "$f\$" <<< "$assets" || { echo "$TAG has no *$f" >&2; exit 1; }+donelatest=false; grep -q '\.dmg$' <<< "$assets" && latest=trueread -r -p "Publish $TAG (latest: $latest)? [y/N] " ok[[ "$ok" == y ]] || exit 1diff --git a/scripts/release.sh b/scripts/release.shindex a9cb7ff..e159d29 100755--- a/scripts/release.sh+++ b/scripts/release.sh@@ -1,28 +1,58 @@#!/usr/bin/env bash# Cuts a release: scripts/release.sh 1.0.1-# Writes the CHANGELOG.md section from the commits since the last tag, sets VERSION (one version-# for every platform: Mac, Windows, Android, Linux all build from it), commits, tags v<version> and-# pushes; the release workflow builds a draft release with that section as its notes.+# One commit, "chore: release v<version>", holds everything the release writes: the CHANGELOG.md+# section from the commits since the last tag, VERSION (one version for every platform: Mac,+# Windows, Android, Linux all build from it) and the version's date in site/changelog.json. It is+# tagged v<version> and pushed with the tag in one go, so the release commit is the last commit of+# the release; the release workflow builds a draft release with that section as its notes.+# Runs on main or in a release worktree whose HEAD has origin/main in it. To recut a draft after a+# fix: delete the draft and its tag (gh release delete, git push --delete origin, git tag -d), commit+# the fix, run this again with the same version; it rewrites the section and makes a new release commit.set -euo pipefailcd "$(dirname "$0")/.."VERSION=${1:?usage: scripts/release.sh <version, e.g. 1.0.1>}+TAG="v$VERSION"[[ "$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; }-# 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+git fetch -q origin main --tags+git merge-base --is-ancestor origin/main HEAD || { echo "HEAD is behind origin/main: rebase first" >&2; exit 1; }+git rev-parse -q --verify "refs/tags/$TAG" >/dev/null && { echo "tag $TAG exists here: git tag -d $TAG" >&2; exit 1; }+git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null && { echo "tag $TAG exists on origin" >&2; exit 1; }-CURRENT=$(tr -d '[:space:]' < VERSION)-if [[ "$CURRENT" != "$VERSION" ]]; then- echo "$VERSION" > VERSION- git commit -m "chore: release v$VERSION" VERSION+# A run that fails before the commit leaves the tree as it was, so the next run can start.+trap 'git checkout -q -- CHANGELOG.md VERSION site/changelog.json' ERR+scripts/changelog.py "$VERSION"+echo "$VERSION" > VERSION+# The site's Chinese changelog: the undated entry (its version is a guess until now) becomes this+# version, dated today; a recut moves the date to today (a fix after the first cut adds its item to+# that dated entry, not a new undated one). scripts/deploy-site.sh won't deploy it+# while the release is still a draft.+python3 - "$VERSION" <<'PY'+import datetime, json, sys+version, path = sys.argv[1], "site/changelog.json"+with open(path, encoding="utf-8") as f:+ entries = json.load(f)+undated = [e for e in entries if e.get("date") is None]+own = [e for e in entries if e.get("version") == version and e.get("date")]+if len(undated) > 1 or (undated and own):+ sys.exit(f"{path}: merge the undated entries and any dated {version} one into one for {version}")+target = undated or own+if not target:+ sys.exit(f"{path}: no undated entry for {version}: every user-visible change needs a Chinese item")+target[0]["version"], target[0]["date"] = version, datetime.date.today().isoformat()+with open(path, "w", encoding="utf-8") as f:+ f.write(json.dumps(entries, indent=2, ensure_ascii=False) + "\n")+PY+git add CHANGELOG.md VERSION site/changelog.json+git commit -q --allow-empty -m "chore: release $TAG"+trap - ERR+git tag -a "$TAG" -m "Cicada $VERSION"+# Atomic: the tag never goes up without its commit. If someone pushed in between, undo and say so.+if ! git push --atomic origin HEAD:main "$TAG"; then+ git tag -d "$TAG" >/dev/null+ git reset -q --keep HEAD~1+ echo "push rejected (main moved): rebase on origin/main and run again" >&2+ exit 1fi-git tag -a "v$VERSION" -m "Cicada $VERSION"-git push origin main "v$VERSION"-echo "Pushed v$VERSION; follow it at https://github.com/wquguru/cicada/actions/workflows/release.yml, then try the draft and scripts/publish-release.sh $VERSION"+echo "Pushed $TAG ($(git rev-parse --short HEAD)); follow it at https://github.com/wquguru/cicada/actions/workflows/release.yml, then try the draft and scripts/publish-release.sh $VERSION"