tftsr-devops_investigation/scripts/update-version.mjs
Shaun Arman 9e1a9b1d34
Some checks failed
Test / rust-clippy (pull_request) Failing after 15s
Test / rust-tests (pull_request) Failing after 19s
Test / rust-fmt-check (pull_request) Successful in 55s
Test / frontend-typecheck (pull_request) Successful in 1m22s
Test / frontend-tests (pull_request) Successful in 1m26s
PR Review Automation / review (pull_request) Successful in 2m57s
feat: implement dynamic versioning from Git tags
- Add build.rs to read version from git describe --tags
- Create update-version.mjs script to sync version across files
- Add get_app_version() command to Rust backend
- Update App.tsx to use custom version command
- Run version update in CI before Rust checks
2026-04-13 16:12:03 -05:00

58 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
import { execSync } from 'child_process';
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = resolve(__dirname, '..');
function getVersionFromGit() {
try {
const output = execSync('git describe --tags --abbrev=0', {
encoding: 'utf-8',
cwd: projectRoot
});
const version = output.trim().replace(/^v/, '');
if (version) {
return version;
}
} catch (e) {
console.warn('Failed to get version from Git tags, using fallback');
}
return '0.2.50';
}
function updateFile(filePath, updater) {
const fullPath = resolve(projectRoot, filePath);
if (!existsSync(fullPath)) {
throw new Error(`File not found: ${fullPath}`);
}
const content = readFileSync(fullPath, 'utf-8');
const updated = updater(content);
writeFileSync(fullPath, updated, 'utf-8');
console.log(`✓ Updated ${filePath}`);
}
const version = getVersionFromGit();
console.log(`Setting version to: ${version}`);
// Update Cargo.toml (Rust)
updateFile('src-tauri/Cargo.toml', (content) => {
return content.replace(/version = "([^"]+)"/, `version = "${version}"`);
});
// Update package.json (Frontend)
updateFile('package.json', (content) => {
return content.replace(/"version": "([^"]+)"/, `"version": "${version}"`);
});
// Update tauri.conf.json
updateFile('src-tauri/tauri.conf.json', (content) => {
return content.replace(/"version": "([^"]+)"/, `"version": "${version}"`);
});
console.log(`✓ All version fields updated to ${version}`);