Add automatic build version generation from git

Implement a script to automatically generate build version information from git commit hash and date, updating version.json and creating latest.json.
This commit is contained in:
Riyadh
2026-05-17 15:16:02 +00:00
parent 8a5bd5db51
commit cb894f7baa
5 changed files with 61 additions and 1 deletions
+22
View File
@@ -92,3 +92,25 @@ http://localhost:3000 → nginx (web container)
git pull
./start.sh rebuild
```
## تنبيه التحديثات (System Updates)
صفحة **Admin → System Updates** تعرض الإصدار الحالي وتقدر تفحص لو في إصدار أحدث على Gitea. للتفعيل:
1. تأكد أن ملف `latest.json` موجود في جذر الريبو على Gitea بنفس بنية `version.json`:
```json
{ "version": "0.2.0", "build": "20260601.abc1234" }
```
2. أضف في `.env` (أو `docker-compose.yml` تحت `services.api.environment`):
```
LATEST_VERSION_URL=https://desktop-11cj93j.tail866923.ts.net/rafraa/TX/raw/branch/main/latest.json
```
3. أعد التشغيل: `./start.sh stop && ./start.sh`.
عند كل إصدار جديد: حدّث `latest.json` في الريبو وادفع. عملاء Tx OS سيرون شارة "Update available" عند ضغطهم على Check Now.
> رقم البناء (`build`) يُولَّد تلقائياً من git قبل كل `pnpm run build` (انظر `scripts/update-version.mjs`)، فلا تحتاج تعديله يدوياً في `version.json`.
+4
View File
@@ -0,0 +1,4 @@
{
"version": "0.1.0-dev",
"build": "20260517.b5efd9eb"
}
+2
View File
@@ -4,6 +4,8 @@
"license": "MIT",
"scripts": {
"preinstall": "sh -c 'rm -f package-lock.json yarn.lock; case \"$npm_config_user_agent\" in pnpm/*) ;; *) echo \"Use pnpm instead\" >&2; exit 1 ;; esac'",
"update-version": "node scripts/update-version.mjs",
"prebuild": "pnpm run update-version",
"build": "pnpm run typecheck && pnpm -r --if-present run build",
"typecheck:libs": "tsc --build",
"typecheck": "pnpm run typecheck:libs && pnpm -r --filter \"./artifacts/**\" --filter \"./scripts\" --if-present run typecheck",
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env node
import { execSync } from "node:child_process";
import { readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
const __dirname = dirname(fileURLToPath(import.meta.url));
const versionPath = resolve(__dirname, "..", "version.json");
function git(args) {
return execSync(`git ${args}`, { encoding: "utf8" }).trim();
}
let commit = "unknown";
let date = new Date().toISOString().slice(0, 10).replace(/-/g, "");
try {
commit = git("log -1 --format=%h");
date = git("log -1 --format=%cd --date=format:%Y%m%d");
} catch (err) {
console.warn(`[update-version] git unavailable, using fallback: ${err.message}`);
}
const build = `${date}.${commit}`;
const current = JSON.parse(readFileSync(versionPath, "utf8"));
const next = { ...current, build };
if (current.build === build) {
console.log(`[update-version] build unchanged: ${build}`);
} else {
writeFileSync(versionPath, JSON.stringify(next, null, 2) + "\n");
console.log(`[update-version] ${current.build} -> ${build}`);
}
+1 -1
View File
@@ -1,4 +1,4 @@
{
"version": "0.1.0-dev",
"build": "20260517"
"build": "20260517.b5efd9eb"
}