Files
jiu/scripts/ci/release-client.sh
T
wangjia 7d0595105f fix(ci): version.yaml 的 build_number 改用版本号公式派生
旧法读仓库 backend/config/version.yaml 的 build_number 再 +1,但 CI 与
local-release 部署时都不回写仓库那份,它永远冻结 → 每次发版都算出同一个值
(1.1.9 / 1.1.10 线上 build_number 均为 5)。改用 major*10000+minor*100+patch
(与 pubspec CFBundleVersion 同源、天然单调),无状态依赖,CI 与本机结果一致。
自更新按版本字符串判断,build_number 仅展示,历史 5 无害。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bupi8Kdqkfx2N5acFsHTx5
2026-08-26 01:56:17 +08:00

125 lines
4.9 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# release-client.sh <tag> — client pipeline release.
# 1. Update backend/config/version.yaml: version / build_number / release_notes
# / macos+windows+android download URLs / changelog[] (latest 3 from
# CHANGELOG-client.md).
# 2. Create the Forgejo Release client-vX and upload the app artifacts +
# version.yaml (so manual rollback can re-fetch the exact manifest).
#
# version.yaml is client-owned: the backend reads it per-request, so deploying
# it does NOT require a backend restart or a server-pipeline run.
set -euo pipefail
# shellcheck source=scripts/ci/lib-forgejo.sh
. "$(dirname "$0")/lib-forgejo.sh"
TAG="$1"
VER="$(ver_from_tag "$TAG")"
echo "==> release-client: tag=${TAG} version=${VER}"
NOTES=$(extract_release_notes CHANGELOG-client.md)
echo "==> release-client: release_notes=${NOTES}"
# --- Update version.yaml (scalars + download URLs) and append changelog[] ---
python3 - "$VER" "$NOTES" "CHANGELOG-client.md" <<'PYEOF'
import sys, re, json
ver = sys.argv[1]
notes = sys.argv[2]
changelog_file = sys.argv[3]
base = "https://jiu.51yanmei.com/downloads" # 2026-07-03 备案通过回切 https 域名
mac_url = f"{base}/jiu-macos-x64.zip"
win_url = f"{base}/jiu-windows-x64-setup.exe"
android_url = f"{base}/jiu-android.apk"
# Read current version.yaml, dropping any existing trailing `changelog:` block
# (changelog is always emitted last, so everything from it to EOF is regenerated).
with open('backend/config/version.yaml', encoding='utf-8') as f:
raw = f.read()
raw = re.split(r'\nchangelog:', raw, maxsplit=1)[0].rstrip('\n') + '\n'
out = []
for line in raw.splitlines(keepends=True):
if line.startswith('version:'):
out.append('version: "%s"\n' % ver)
elif line.startswith('build_number:'):
# build_number 由版本号公式派生(major*10000+minor*100+patch),与 pubspec
# 的 CFBundleVersion 同源、天然单调。旧法「读仓库 version.yaml +1」有 bug:
# CI/本地发版都不回写仓库那份,它永远冻结 → 每次都算出同一个值(见 1.1.9/1.1.10
# 均为 5 的历史)。改公式后无状态依赖,CI 与 local-release 结果一致。
try:
_mj, _mn, _pt = (int(x) for x in ver.split('.')[:3])
b = _mj * 10000 + _mn * 100 + _pt
except Exception:
b = 1
out.append('build_number: %d\n' % b)
elif line.startswith('release_notes:'):
safe = notes.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '')
out.append('release_notes: "%s"\n' % safe)
elif line.startswith(' macos:'):
out.append(' macos: "%s"\n' % mac_url)
elif line.startswith(' windows:'):
out.append(' windows: "%s"\n' % win_url)
elif line.startswith(' android:'):
out.append(' android: "%s"\n' % android_url)
else:
out.append(line)
# Parse CHANGELOG-client.md -> latest 3 entries (same shape as web/_data/changelog.js)
versions = []
cur = None
sec = None
for line in open(changelog_file, encoding='utf-8'):
line = line.rstrip('\n')
m = re.match(r'^## \[([^\]]+)\] - (\d{4}-\d{2}-\d{2})', line)
if m:
if cur:
versions.append(cur)
if len(versions) >= 3:
cur = None
break
cur = {'version': m.group(1), 'date': m.group(2), 'intro': '', 'sections': []}
sec = None
continue
ms = re.match(r'^### (.+)', line)
if ms and cur is not None:
sec = {'type': ms.group(1).strip(), 'items': []}
cur['sections'].append(sec)
continue
mi = re.match(r'^- (.+)', line)
if mi and cur is not None and sec is not None:
sec['items'].append(mi.group(1).strip())
continue
if line.strip() and cur is not None and sec is None and not line.startswith('#'):
cur['intro'] = (cur['intro'] + ' ' + line.strip()).strip()
if cur is not None and len(versions) < 3:
versions.append(cur)
# Append changelog as a JSON array (valid YAML flow style — no pyyaml needed).
text = ''.join(out).rstrip('\n') + '\n'
text += 'changelog: ' + json.dumps(versions, ensure_ascii=False) + '\n'
with open('backend/config/version.yaml', 'w', encoding='utf-8') as f:
f.write(text)
print('version.yaml updated to', ver, '|', len(versions), 'changelog entries')
PYEOF
# Stage version.yaml as a release asset so manual rollback can re-fetch it.
mkdir -p dist
cp backend/config/version.yaml dist/version.yaml
BODY=$(python3 - "$TAG" "$NOTES" <<'PYEOF'
import sys, json
print(json.dumps('## ' + sys.argv[1] + '\n\n' + sys.argv[2]))
PYEOF
)
create_release "$TAG" "$BODY"
upload_asset dist/web.tar.gz
upload_asset dist/version.yaml
[ -f dist/jiu-macos-x64.zip ] && upload_asset dist/jiu-macos-x64.zip || true
[ -f dist/jiu-windows-x64-setup.exe ] && upload_asset dist/jiu-windows-x64-setup.exe || true
[ -f dist/jiu-android.apk ] && upload_asset dist/jiu-android.apk || true
echo "==> release-client: done — Release ${TAG} created"