feat(update): add version check to skip update when already latest
Now `nupst update` checks current version against latest release before downloading anything. Behavior: - Fetches latest version from Gitea API - Compares with current version - Shows "Already up to date!" if versions match - Only downloads/installs if newer version available Example output when up to date: Checking for updates... Current version: v4.0.8 Latest version: v4.0.8 ✓ Already up to date!
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@serve.zone/nupst",
|
"name": "@serve.zone/nupst",
|
||||||
"version": "4.0.7",
|
"version": "4.0.8",
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"dev": "deno run --allow-all mod.ts",
|
"dev": "deno run --allow-all mod.ts",
|
||||||
|
@@ -133,22 +133,43 @@ export class ServiceHandler {
|
|||||||
);
|
);
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
logger.info('Updating NUPST to latest version...');
|
logger.info('Checking for updates...');
|
||||||
console.log('');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Get current version
|
||||||
|
const currentVersion = this.nupst.getVersion();
|
||||||
|
|
||||||
|
// Fetch latest version from Gitea API
|
||||||
|
const apiUrl = 'https://code.foss.global/api/v1/repos/serve.zone/nupst/releases/latest';
|
||||||
|
const response = execSync(`curl -sSL ${apiUrl}`).toString();
|
||||||
|
const release = JSON.parse(response);
|
||||||
|
const latestVersion = release.tag_name; // e.g., "v4.0.7"
|
||||||
|
|
||||||
|
logger.dim(`Current version: ${currentVersion}`);
|
||||||
|
logger.dim(`Latest version: ${latestVersion}`);
|
||||||
|
console.log('');
|
||||||
|
|
||||||
|
// Compare versions (both are in format "v4.0.7")
|
||||||
|
if (currentVersion === latestVersion) {
|
||||||
|
logger.success('Already up to date!');
|
||||||
|
console.log('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`New version available: ${latestVersion}`);
|
||||||
|
logger.dim('Downloading and installing...');
|
||||||
|
console.log('');
|
||||||
|
|
||||||
// Download and run the install script
|
// Download and run the install script
|
||||||
// This handles everything: download binary, stop service, replace, restart
|
// This handles everything: download binary, stop service, replace, restart
|
||||||
const installUrl = 'https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh';
|
const installUrl = 'https://code.foss.global/serve.zone/nupst/raw/branch/main/install.sh';
|
||||||
|
|
||||||
logger.dim('Downloading install script...');
|
|
||||||
execSync(`curl -sSL ${installUrl} | bash`, {
|
execSync(`curl -sSL ${installUrl} | bash`, {
|
||||||
stdio: 'inherit', // Show install script output to user
|
stdio: 'inherit', // Show install script output to user
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
logger.success('Update completed successfully!');
|
logger.success(`Updated to ${latestVersion}`);
|
||||||
logger.dim('Run "nupst service status" to verify the update.');
|
|
||||||
console.log('');
|
console.log('');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('');
|
console.log('');
|
||||||
|
Reference in New Issue
Block a user