Files
goldenChart/scripts/reconcile-desktop-latest-json.sh
T
2026-06-14 23:02:44 +09:00

74 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# signed updater bundle → latest.json (deploy/checkout 후 placeholder 복구)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH:-/usr/bin:/bin}"
UPDATES_DIR="${UPDATES_DIR:-${WORK_TREE:-$ROOT}/frontend/public/desktop/updates}"
BASE_URL="${DESKTOP_UPDATE_BASE_URL:-https://exdev.co.kr/desktop/updates}"
BASE_URL="${BASE_URL/http:\/\//https:\/\/}"
if [[ ! -d "$UPDATES_DIR" ]]; then
echo "[reconcile-latest] skip — no $UPDATES_DIR"
exit 0
fi
# tauri.conf(git) 는 구버전일 수 있음 — build-info·latest.json·설치 파일명 우선
VERSION="$(node -e "
const fs = require('fs');
const path = require('path');
const dir = process.argv[1];
const parse = v => String(v || '0.0.0').trim().replace(/^v/i, '').split('.').map(n => parseInt(n, 10) || 0);
const cmp = (a, b) => {
const pa = parse(a), pb = parse(b);
for (let i = 0; i < 3; i++) {
const d = (pa[i] || 0) - (pb[i] || 0);
if (d) return d;
}
return 0;
};
const maxVer = (cur, next) => (next && cmp(next, cur) > 0 ? next : cur);
let base = '0.0.0';
const bi = path.join(dir, 'build-info.json');
if (fs.existsSync(bi)) {
try { base = maxVer(base, JSON.parse(fs.readFileSync(bi, 'utf8')).version); } catch {}
}
const latest = path.join(dir, 'latest.json');
if (fs.existsSync(latest)) {
try { base = maxVer(base, JSON.parse(fs.readFileSync(latest, 'utf8')).version); } catch {}
}
if (fs.existsSync(dir)) {
for (const name of fs.readdirSync(dir)) {
const m = name.match(/GoldenChart[_-](\\d+\\.\\d+\\.\\d+)/i);
if (m) base = maxVer(base, m[1]);
}
}
if (base === '0.0.0') {
try {
const conf = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
if (conf.version) base = conf.version;
} catch {}
}
console.log(base);
" "$UPDATES_DIR" "$ROOT/desktop/src-tauri/tauri.conf.json")"
NOTES="${DESKTOP_RELEASE_NOTES:-GoldenChart Desktop $VERSION}"
echo "[reconcile-latest] version source → v${VERSION}"
set +e
node "$ROOT/scripts/generate-desktop-latest-json.mjs" \
--version "$VERSION" \
--dir "$UPDATES_DIR" \
--base-url "$BASE_URL" \
--notes "$NOTES"
RC=$?
set -e
if [[ "$RC" -eq 0 ]]; then
echo "[reconcile-latest] updated $UPDATES_DIR/latest.json"
elif [[ "$RC" -eq 2 ]]; then
echo "[reconcile-latest] no signed bundles — keeping existing latest.json (v${VERSION})"
else
exit "$RC"
fi