fix(system): implement dynamic versioning using git tags to follow update rules

This commit is contained in:
choibk 2026-01-26 00:59:04 +09:00
parent af849ba8ec
commit 37ab4680c5
2 changed files with 24 additions and 7 deletions

View File

@ -462,13 +462,20 @@ app.get('/api/health', (req, res) => {
const kstOffset = 9 * 60 * 60 * 1000;
const kstDate = new Date(Date.now() + kstOffset);
// Read version from root package.json without caching
// Dynamic Version detection: Prioritize local Git Tag to match the "Update" rule
let version = '0.0.0.0';
try {
const rootPkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
version = rootPkg.version;
const { execSync } = require('child_process');
// Get the latest tag on the current commit
version = execSync('git describe --tags --abbrev=0', { cwd: path.join(__dirname, '..') }).toString().trim().replace(/^v/, '');
} catch (e) {
version = packageJson.version; // Fallback to server/package.json
// Fallback to root package.json if git fails
try {
const rootPkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
version = rootPkg.version;
} catch (err) {
version = packageJson.version; // Fallback to server/package.json
}
}
res.json({

View File

@ -465,9 +465,19 @@ const getGiteaAuth = async () => {
// 5. Get Version Info (Current, Remote & History from Tags)
router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res) => {
try {
const packageJsonPath = path.resolve(__dirname, '../../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const currentVersion = packageJson.version;
// Dynamic Version detection: Prioritize local Git Tag
let currentVersion = '0.0.0.0';
try {
currentVersion = execSync('git describe --tags --abbrev=0', { cwd: path.join(__dirname, '../..') }).toString().trim().replace(/^v/, '');
} catch (e) {
try {
const packageJsonPath = path.resolve(__dirname, '../../package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
currentVersion = packageJson.version;
} catch (err) {
currentVersion = '0.4.0.0'; // Ultimate fallback
}
}
// Prepare git fetch command with auth if available
const auth = await getGiteaAuth();