Files
navi/scripts/sync-version.py
T
M4andCursor 7ceb3a5148
ci / test (macos-latest) (push) Waiting to run
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
Release 3.8.2.13: iOS Packet Tunnel client and Clash URL subscriptions.
Add SwiftUI + Network Extension (LibXray/hev), parse Clash Meta YAML from subscription URLs into vless/trojan/hy2 share links, keep the selected server on connect, and ship Navis-3.8.2.13.ipa with versioned changelog.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-01 22:46:32 +03:00

124 lines
4.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Sync versioninfo.json, build-macos.bat, Android gradle, UI badge from update.go."""
from __future__ import annotations
import json
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
UPDATE_GO = ROOT / "internal" / "update" / "update.go"
VERSIONINFO = ROOT / "versioninfo.json"
BUILD_BAT = ROOT / "build-macos.bat"
ANDROID_GRADLE = ROOT / "android" / "app" / "build.gradle.kts"
INDEX_HTML = ROOT / "internal" / "appui" / "index.html"
IOS_README = ROOT / "ios" / "README.md"
IOS_PLISTS = (
ROOT / "ios" / "Navis" / "Info.plist",
ROOT / "ios" / "NavisTunnel" / "Info.plist",
)
def read_consts() -> tuple[str, int]:
text = UPDATE_GO.read_text(encoding="utf-8")
m = re.search(r'CurrentVersion\s*=\s*"([^"]+)"', text)
b = re.search(r"const BuildNumber\s*=\s*(\d+)", text)
if not m or not b:
raise SystemExit("cannot parse CurrentVersion/BuildNumber from update.go")
return m.group(1), int(b.group(1))
def main() -> None:
ver, build = read_consts()
parts = [int(x) for x in ver.split(".")]
while len(parts) < 3:
parts.append(0)
major, minor, patch = parts[0], parts[1], parts[2]
full = f"{ver}.{build}"
display = f"{ver}+{build}"
version_code = major * 1_000_000 + minor * 10_000 + patch * 100 + build
data = json.loads(VERSIONINFO.read_text(encoding="utf-8"))
data["FixedFileInfo"]["FileVersion"] = {
"Major": major,
"Minor": minor,
"Patch": patch,
"Build": build,
}
data["FixedFileInfo"]["ProductVersion"] = dict(data["FixedFileInfo"]["FileVersion"])
data["StringFileInfo"]["FileVersion"] = full
data["StringFileInfo"]["ProductVersion"] = full
VERSIONINFO.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
print("updated", VERSIONINFO, "->", full)
bat = BUILD_BAT.read_text(encoding="utf-8")
bat2 = re.sub(
r'-version\s+\d+\.\d+\.\d+\s+-build\s+\d+\.\d+\.\d+\.\d+',
f"-version {ver} -build {full}",
bat,
)
if bat2 != bat:
BUILD_BAT.write_text(bat2, encoding="utf-8")
print("updated", BUILD_BAT, "->", ver, full)
else:
print("build-macos.bat already in sync")
if ANDROID_GRADLE.exists():
g = ANDROID_GRADLE.read_text(encoding="utf-8")
g2 = re.sub(r"versionCode\s*=\s*[\d_]+", f"versionCode = {version_code}", g)
g2 = re.sub(r'versionName\s*=\s*"[^"]+"', f'versionName = "{display}"', g2)
if g2 != g:
ANDROID_GRADLE.write_text(g2, encoding="utf-8")
print("updated", ANDROID_GRADLE, "->", display, version_code)
else:
print("android gradle already in sync")
if INDEX_HTML.exists():
h = INDEX_HTML.read_text(encoding="utf-8")
h2 = re.sub(r'(id="badgeVer">)[^<]+', rf"\g<1>{ver}", h, count=1)
if h2 != h:
INDEX_HTML.write_text(h2, encoding="utf-8")
print("updated", INDEX_HTML, "badge ->", ver)
else:
print("index.html badge already in sync")
for plist in IOS_PLISTS:
if not plist.exists():
continue
p = plist.read_text(encoding="utf-8")
p2 = re.sub(
r"(<key>CFBundleShortVersionString</key>\s*<string>)[^<]+",
rf"\g<1>{ver}",
p,
count=1,
)
p2 = re.sub(
r"(<key>CFBundleVersion</key>\s*<string>)[^<]+",
rf"\g<1>{full}",
p2,
count=1,
)
if p2 != p:
plist.write_text(p2, encoding="utf-8")
print("updated", plist, "->", ver, full)
else:
print(plist.name, "already in sync")
if IOS_README.exists():
r = IOS_README.read_text(encoding="utf-8")
r2 = re.sub(
r"(Версия:\s*\*\*)[^*]+(\*\*)",
rf"\g<1>{display}\2",
r,
count=1,
)
if r2 != r:
IOS_README.write_text(r2, encoding="utf-8")
print("updated", IOS_README, "->", display)
else:
print("ios/README.md already in sync")
if __name__ == "__main__":
main()