Files
navi/scripts/build-macos-arm64.sh
T
M4andCursor 43882b95ad Release 2.7.2.4: macOS app icon, glaze UI and auto build numbers.
Add green N AppIcon to the .app bundle, keep WKWebView GUI stable, and stamp builds via BaseVersion/BuildNumber.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-29 17:57:18 +03:00

107 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# Build Navis GUI for Apple Silicon (arm64) with auto-incremented build number.
set -euo pipefail
cd "$(dirname "$0")/.."
BASE_VERSION="$(python3 - <<'PY'
import re
from pathlib import Path
t = Path('internal/update/version.go').read_text()
m = re.search(r'BaseVersion\s*=\s*"([^"]+)"', t)
print(m.group(1) if m else '0.0.0')
PY
)"
BUILD_NUM="$(tr -d '[:space:]' < buildnum.txt 2>/dev/null || echo 0)"
if ! [[ "$BUILD_NUM" =~ ^[0-9]+$ ]]; then BUILD_NUM=0; fi
BUILD_NUM=$((BUILD_NUM + 1))
echo "$BUILD_NUM" > buildnum.txt
FULL_VERSION="${BASE_VERSION}.${BUILD_NUM}"
echo "Building Navis ${FULL_VERSION} (arm64)..."
# Keep source BuildNumber in sync for non-ldflags runs / IDE
python3 - <<PY
from pathlib import Path
p = Path('internal/update/version.go')
t = p.read_text()
import re
t2 = re.sub(r'(var BuildNumber = ")[^"]*(")', r'\g<1>${BUILD_NUM}\2', t)
p.write_text(t2)
PY
# versioninfo.json (Windows metadata; also documents build)
python3 - <<PY
import json, re
from pathlib import Path
maj, minor, patch = [int(x) for x in "${BASE_VERSION}".split(".")[:3]]
build = int("${BUILD_NUM}")
full = "${FULL_VERSION}"
p = Path('versioninfo.json')
d = json.loads(p.read_text())
d['FixedFileInfo']['FileVersion'] = {"Major": maj, "Minor": minor, "Patch": patch, "Build": build}
d['FixedFileInfo']['ProductVersion'] = {"Major": maj, "Minor": minor, "Patch": patch, "Build": build}
d['StringFileInfo']['FileVersion'] = f"{full}.0" if full.count('.')==3 else full
d['StringFileInfo']['ProductVersion'] = d['StringFileInfo']['FileVersion']
# Prefer 4-part a.b.c.d
d['StringFileInfo']['FileVersion'] = f"{maj}.{minor}.{patch}.{build}"
d['StringFileInfo']['ProductVersion'] = f"{maj}.{minor}.{patch}.{build}"
p.write_text(json.dumps(d, indent=2) + "\n")
print('versioninfo.json ->', d['StringFileInfo']['FileVersion'])
PY
OUT="dist/navis-release/darwin-arm64"
mkdir -p "$OUT"
LDFLAGS="-s -w -X vpnclient/internal/update.BuildNumber=${BUILD_NUM}"
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 \
go build -ldflags="$LDFLAGS" -trimpath -o "$OUT/Navis" ./cmd/vpnapp
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 \
go build -ldflags="$LDFLAGS" -trimpath -o "$OUT/Navis-cli" ./cmd/vpnclient
# Stamp plain-text version next to binaries
printf '%s\n' "$FULL_VERSION" > "$OUT/VERSION"
printf '%s\n' "$FULL_VERSION" > "$OUT/Navis.version"
if command -v codesign >/dev/null 2>&1; then
codesign -s - --force "$OUT/Navis"
codesign -s - --force "$OUT/Navis-cli"
fi
go build -o tools/packmac/packmac ./tools/packmac
tools/packmac/packmac \
-bin "$OUT/Navis" \
-out "$OUT" \
-version "$FULL_VERSION" \
-build "$BUILD_NUM" \
-arch arm64
# Rename release copies with version in filename (keep unversioned too)
cp -f "$OUT/Navis.dmg" "$OUT/Navis-${FULL_VERSION}-arm64.dmg"
cp -f "$OUT/Navis.app.zip" "$OUT/Navis-${FULL_VERSION}-arm64.app.zip"
# update.json
python3 - <<PY
import hashlib, json
from pathlib import Path
full = "${FULL_VERSION}"
binp = Path('dist/navis-release/darwin-arm64/Navis')
h = hashlib.sha256(binp.read_bytes()).hexdigest()
for p in [Path('dist/update.json'), Path('dist/navis-release/update.json')]:
if not p.exists():
continue
d = json.loads(p.read_text())
d['version'] = full
d['notes'] = f'Navis {full}'
plats = d.setdefault('platforms', {})
if 'darwin-arm64' in plats:
plats['darwin-arm64']['sha256'] = h
p.write_text(json.dumps(d, ensure_ascii=False, indent=2) + '\n')
print('updated', p, '->', full)
PY
echo ""
echo "Done: Navis ${FULL_VERSION}"
ls -lh "$OUT"
file "$OUT/Navis.dmg"