Skip to content

Commit 01764ba

Browse files
committed
refactor: standardize release naming conventions and improve version comparison logic
1 parent 9ee5906 commit 01764ba

File tree

4 files changed

+64
-14
lines changed

4 files changed

+64
-14
lines changed

.github/workflows/release-fast.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4747
with:
4848
tagName: ${{ github.ref_name }}
49-
releaseName: 'Presto v__VERSION__ (macOS)'
49+
releaseName: 'v__VERSION__ (macOS)'
5050
releaseBody: |
5151
## Fast macOS Release
5252

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ jobs:
5656
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
5757
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
5858
with:
59-
tagName: app-v__VERSION__ # the action automatically replaces __VERSION__ with the app version.
60-
releaseName: 'Presto v__VERSION__'
59+
tagName: v__VERSION__ # the action automatically replaces __VERSION__ with the app version.
60+
releaseName: 'v__VERSION__'
6161
releaseBody: |
6262
## What's Changed
6363

release.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ main() {
301301
echo "Prossimi passi:"
302302
echo "1. Verifica che la build sia completata correttamente"
303303
echo "2. Se hai aperto GitHub, crea la release con i file compilati"
304-
echo "3. Testa l'aggiornamento automatico dell'app"
304+
echo "3. Il tag v$new_version è stato creato per il sistema di aggiornamenti automatici"
305+
echo "4. Testa l'aggiornamento automatico dell'app"
305306
echo ""
306307

307308
# Mostra informazioni sui file generati

src/managers/update-manager.js

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ export class UpdateManager {
160160

161161
console.log('📦 Release più recente da GitHub:', latestRelease.tag_name);
162162

163-
// Rimuovi il prefisso "app-v" se presente
164-
const latestVersion = latestRelease.tag_name.replace(/^app-v/, '');
163+
// Pulisci la versione usando la stessa logica robusta
164+
const latestVersion = this.cleanVersionString(latestRelease.tag_name);
165165
const isNewer = this.compareVersions(latestVersion, currentVersion) > 0;
166166

167167
if (isNewer) {
@@ -246,18 +246,65 @@ export class UpdateManager {
246246
* Confronta due versioni (formato semver)
247247
*/
248248
compareVersions(a, b) {
249-
const aParts = a.split('.').map(Number);
250-
const bParts = b.split('.').map(Number);
249+
try {
250+
console.log('🔍 Confronto versioni:', { a, b });
251+
252+
// Pulisci le versioni da prefissi e suffissi non numerici
253+
const cleanA = this.cleanVersionString(a);
254+
const cleanB = this.cleanVersionString(b);
255+
256+
console.log('🧹 Versioni pulite:', { cleanA, cleanB });
257+
258+
const aParts = cleanA.split('.').map(part => {
259+
const num = parseInt(part, 10);
260+
return isNaN(num) ? 0 : num;
261+
});
262+
const bParts = cleanB.split('.').map(part => {
263+
const num = parseInt(part, 10);
264+
return isNaN(num) ? 0 : num;
265+
});
266+
267+
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
268+
const aPart = aParts[i] || 0;
269+
const bPart = bParts[i] || 0;
270+
271+
if (aPart > bPart) return 1;
272+
if (aPart < bPart) return -1;
273+
}
251274

252-
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
253-
const aPart = aParts[i] || 0;
254-
const bPart = bParts[i] || 0;
275+
return 0;
276+
} catch (error) {
277+
console.error('❌ Errore nel confronto versioni:', error);
278+
console.error('❌ Parametri:', { a, b });
279+
// In caso di errore, assumiamo che non ci siano aggiornamenti
280+
return 0;
281+
}
282+
}
283+
284+
/**
285+
* Pulisce una stringa di versione da prefissi e caratteri non numerici
286+
*/
287+
cleanVersionString(version) {
288+
if (!version || typeof version !== 'string') {
289+
return '0.0.0';
290+
}
255291

256-
if (aPart > bPart) return 1;
257-
if (aPart < bPart) return -1;
292+
// Rimuovi prefissi comuni come "v", "app-v", etc.
293+
let cleaned = version
294+
.replace(/^(app-)?v/i, '') // Rimuovi "v" o "app-v"
295+
.replace(/^presto\s+v?/i, '') // Rimuovi "Presto v" o "Presto"
296+
.replace(/^release\s+v?/i, '') // Rimuovi "Release v" o "Release"
297+
.trim();
298+
299+
// Estrai solo la parte numerica con punti (x.y.z)
300+
const versionMatch = cleaned.match(/^(\d+(?:\.\d+)*)/);
301+
if (versionMatch) {
302+
return versionMatch[1];
258303
}
259304

260-
return 0;
305+
// Se non riusciamo a estrarre una versione valida, ritorna 0.0.0
306+
console.warn('⚠️ Versione non valida:', version, '- usando 0.0.0');
307+
return '0.0.0';
261308
}
262309

263310
/**
@@ -427,6 +474,8 @@ export class UpdateManager {
427474
errorMessage = 'Errore di rete durante il controllo degli aggiornamenti. Verifica la connessione a Internet.';
428475
} else if (error === 'error sending request') {
429476
errorMessage = 'Errore di connessione al server degli aggiornamenti. Verifica la connessione a Internet e riprova più tardi.';
477+
} else if (error.includes('parsing') && error.includes('version')) {
478+
errorMessage = 'Errore nel formato delle informazioni di versione. Questo verrà risolto nel prossimo aggiornamento.';
430479
}
431480
} else if (error && error.message) {
432481
if (error.message.includes('network') || error.message.includes('request')) {

0 commit comments

Comments
 (0)