fix(system): implement dynamic versioning using git tags to follow update rules
This commit is contained in:
parent
af849ba8ec
commit
37ab4680c5
@ -462,14 +462,21 @@ app.get('/api/health', (req, res) => {
|
|||||||
const kstOffset = 9 * 60 * 60 * 1000;
|
const kstOffset = 9 * 60 * 60 * 1000;
|
||||||
const kstDate = new Date(Date.now() + kstOffset);
|
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';
|
let version = '0.0.0.0';
|
||||||
|
try {
|
||||||
|
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) {
|
||||||
|
// Fallback to root package.json if git fails
|
||||||
try {
|
try {
|
||||||
const rootPkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
|
const rootPkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'));
|
||||||
version = rootPkg.version;
|
version = rootPkg.version;
|
||||||
} catch (e) {
|
} catch (err) {
|
||||||
version = packageJson.version; // Fallback to server/package.json
|
version = packageJson.version; // Fallback to server/package.json
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
|
|||||||
@ -464,10 +464,20 @@ const getGiteaAuth = async () => {
|
|||||||
|
|
||||||
// 5. Get Version Info (Current, Remote & History from Tags)
|
// 5. Get Version Info (Current, Remote & History from Tags)
|
||||||
router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res) => {
|
router.get('/version/remote', isAuthenticated, hasRole('admin'), async (req, res) => {
|
||||||
|
try {
|
||||||
|
// 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 {
|
try {
|
||||||
const packageJsonPath = path.resolve(__dirname, '../../package.json');
|
const packageJsonPath = path.resolve(__dirname, '../../package.json');
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
const currentVersion = packageJson.version;
|
currentVersion = packageJson.version;
|
||||||
|
} catch (err) {
|
||||||
|
currentVersion = '0.4.0.0'; // Ultimate fallback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare git fetch command with auth if available
|
// Prepare git fetch command with auth if available
|
||||||
const auth = await getGiteaAuth();
|
const auth = await getGiteaAuth();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user