mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: validate version format in auto-updater and release workflow
- Added a check in the desktop release workflow to ensure version tags follow semantic versioning (semver) format. - Enhanced the auto-updater to log a message and skip updates if the app version is not valid semver. - Improved type definitions for event handlers in the auto-updater for better TypeScript support.
This commit is contained in:
parent
f428cd97d9
commit
6dd85dd365
2 changed files with 18 additions and 5 deletions
4
.github/workflows/desktop-release.yml
vendored
4
.github/workflows/desktop-release.yml
vendored
|
|
@ -52,6 +52,10 @@ jobs:
|
||||||
VERSION=${TAG#beta-}
|
VERSION=${TAG#beta-}
|
||||||
VERSION=${VERSION#v}
|
VERSION=${VERSION#v}
|
||||||
fi
|
fi
|
||||||
|
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$'; then
|
||||||
|
echo "::error::Version '$VERSION' is not valid semver (expected X.Y.Z). Fix your tag name."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,25 @@
|
||||||
import { app, dialog } from 'electron';
|
import { app, dialog } from 'electron';
|
||||||
import { autoUpdater } from 'electron-updater';
|
|
||||||
|
const SEMVER_RE = /^\d+\.\d+\.\d+/;
|
||||||
|
|
||||||
export function setupAutoUpdater(): void {
|
export function setupAutoUpdater(): void {
|
||||||
if (!app.isPackaged) return;
|
if (!app.isPackaged) return;
|
||||||
|
|
||||||
|
const version = app.getVersion();
|
||||||
|
if (!SEMVER_RE.test(version)) {
|
||||||
|
console.log(`Auto-updater: skipping — "${version}" is not valid semver`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { autoUpdater } = require('electron-updater');
|
||||||
|
|
||||||
autoUpdater.autoDownload = true;
|
autoUpdater.autoDownload = true;
|
||||||
|
|
||||||
autoUpdater.on('update-available', (info) => {
|
autoUpdater.on('update-available', (info: { version: string }) => {
|
||||||
console.log(`Update available: ${info.version}`);
|
console.log(`Update available: ${info.version}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on('update-downloaded', (info) => {
|
autoUpdater.on('update-downloaded', (info: { version: string }) => {
|
||||||
console.log(`Update downloaded: ${info.version}`);
|
console.log(`Update downloaded: ${info.version}`);
|
||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
|
|
@ -18,14 +27,14 @@ export function setupAutoUpdater(): void {
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
title: 'Update Ready',
|
title: 'Update Ready',
|
||||||
message: `Version ${info.version} has been downloaded. Restart to apply the update.`,
|
message: `Version ${info.version} has been downloaded. Restart to apply the update.`,
|
||||||
}).then(({ response }) => {
|
}).then(({ response }: { response: number }) => {
|
||||||
if (response === 0) {
|
if (response === 0) {
|
||||||
autoUpdater.quitAndInstall();
|
autoUpdater.quitAndInstall();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
autoUpdater.on('error', (err) => {
|
autoUpdater.on('error', (err: Error) => {
|
||||||
console.log('Auto-updater: update check skipped —', err.message?.split('\n')[0]);
|
console.log('Auto-updater: update check skipped —', err.message?.split('\n')[0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue