mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 13:34:09 +01:00
- auto-update.sh holt Images weiter alle 5 Minuten, spielt aber erst ein, wenn das Spiel es erlaubt (POST /api/ops/update-ok per docker exec): Update-Fenster (Standard 03:00–05:00), Börse zu ohne Battle, sofort, dringende Version (urgent: true im Changelog), Admin-Knopf „Jetzt einspielen“; Rückfall: einspielen - Hinweis an Spieler einige Minuten vorher (updSoon), Sicherung per VACUUM INTO unmittelbar vor dem Neustart mit eigener Rotation, Gesundheitsprüfung über /healthz, automatisch zurück auf das vorige Image und notfalls Spielstand zurückspielen, Ausfall-Meldung an die Spielleitung - Admin: Gruppe „Update-Fenster“ und Karte „Update“ (wartende Version, Plan, Verlauf, Zurücksetzen mit Bestätigung); rollback.sh --vorher [--mit-daten] mit Rückfrage; gemeinsame Bausteine in scripts/lib-update.sh - „Was ist neu“: gebündelt seit der zuletzt gesehenen Version des Kontos, gruppiert, höchstens 8 Punkte sichtbar, ohne Admin-Zeilen, nicht für neue Spieler - Test-Instanz (docker compose --profile test): Kopie der neuesten Live-Sicherung, Mails/Push/Taby aus, TESTINSTANZ im Kopf - Tests: updgate, whatsnew/testinst, Skripte mit Attrappen; docs/BETRIEB.md mit Einrichtung, Umstellung, Was tun wenn Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
57 lines
2.7 KiB
JavaScript
57 lines
2.7 KiB
JavaScript
// Versionsangaben: Versionsnummer aus package.json, Build (Git-Commit) und Bauzeit aus dem Docker-Image.
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
import { execFileSync } from 'node:child_process';
|
||
import { fileURLToPath } from 'node:url';
|
||
import { CHANGELOG } from './changelog.js';
|
||
|
||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
|
||
|
||
function gitCommit() {
|
||
try { return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000 }).toString().trim(); } catch { return ''; }
|
||
}
|
||
const envBuild = process.env.WIBOSIM_VERSION && process.env.WIBOSIM_VERSION !== 'dev' ? process.env.WIBOSIM_VERSION : '';
|
||
const commit = envBuild || gitCommit();
|
||
|
||
export const VERSION = {
|
||
version: pkg.version,
|
||
commit: commit || null,
|
||
build: commit ? commit.slice(0, 7) : 'dev',
|
||
builtAt: process.env.WIBOSIM_BUILT_AT || null,
|
||
startedAt: Date.now(),
|
||
test: process.env.WIBOSIM_TEST === '1', // Test-Instanz (testinst.js): Hinweis „TESTINSTANZ“ im Kopf
|
||
};
|
||
export { CHANGELOG };
|
||
export const versionLabel = () => `${VERSION.version}${VERSION.build !== 'dev' ? ` (${VERSION.build})` : ''}`;
|
||
|
||
/**
|
||
* Prüft (für das Admin-Menü), ob auf GitHub ein neuerer Stand liegt. Fehler sind egal – dann eben keine Angabe.
|
||
* repo: "owner/name"
|
||
*/
|
||
export class UpdateCheck {
|
||
constructor(repo, everyMs = 30 * 60_000) {
|
||
this.repo = repo;
|
||
this.everyMs = everyMs;
|
||
this.state = { latest: null, latestDate: null, latestMessage: null, available: false, checkedAt: 0, error: null };
|
||
}
|
||
start() { this.check(); this.timer = setInterval(() => this.check(), this.everyMs); this.timer.unref?.(); }
|
||
stop() { clearInterval(this.timer); }
|
||
async check() {
|
||
if (!VERSION.commit) { this.state.error = 'Unbekannter Build (Entwicklungsstand)'; return this.state; }
|
||
try {
|
||
const res = await fetch(`https://api.github.com/repos/${this.repo}/commits/main`, {
|
||
headers: { accept: 'application/vnd.github+json', 'user-agent': 'WiBoSim-Updatecheck' }, signal: AbortSignal.timeout(10_000),
|
||
});
|
||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||
const j = await res.json();
|
||
this.state = {
|
||
latest: String(j.sha ?? '').slice(0, 7), latestDate: j.commit?.committer?.date ?? null,
|
||
latestMessage: String(j.commit?.message ?? '').split('\n')[0].slice(0, 160),
|
||
available: !!j.sha && j.sha !== VERSION.commit, checkedAt: Date.now(), error: null,
|
||
};
|
||
} catch (e) { this.state = { ...this.state, checkedAt: Date.now(), error: String(e.message ?? e).slice(0, 120) }; }
|
||
return this.state;
|
||
}
|
||
}
|