This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·397 lines (344 loc) · 12.4 KB
/
release.sh
File metadata and controls
executable file
·397 lines (344 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/bash
# Script di automazione per il rilascio di Presto
# Gestisce versioning, commit, tag, push e build automaticamente
set -e # Esce immediatamente se un comando fallisce
# Colori per output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Funzioni helper
print_step() {
echo -e "${BLUE}🔄 $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# Funzione per incrementare la versione
increment_version() {
local version=$1
local type=$2
IFS='.' read -ra VERSION_PARTS <<< "$version"
local major=${VERSION_PARTS[0]}
local minor=${VERSION_PARTS[1]}
local patch=${VERSION_PARTS[2]}
case $type in
"major")
major=$((major + 1))
minor=0
patch=0
;;
"minor")
minor=$((minor + 1))
patch=0
;;
"patch")
patch=$((patch + 1))
;;
*)
echo "Tipo di versione non valido: $type"
exit 1
;;
esac
echo "$major.$minor.$patch"
}
# Funzione per aggiornare la versione nei file
update_version_in_files() {
local old_version=$1
local new_version=$2
print_step "Aggiornamento versione da $old_version a $new_version..."
# Aggiorna package.json
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
sed -i '' "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" package.json
sed -i '' "s/version = \"$old_version\"/version = \"$new_version\"/" src-tauri/Cargo.toml
sed -i '' "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" src-tauri/tauri.conf.json
# Aggiorna version.js
sed -i '' "s/APP_VERSION = '$old_version'/APP_VERSION = '$new_version'/" src/version.js
else
# Linux
sed -i "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" package.json
sed -i "s/version = \"$old_version\"/version = \"$new_version\"/" src-tauri/Cargo.toml
sed -i "s/\"version\": \"$old_version\"/\"version\": \"$new_version\"/" src-tauri/tauri.conf.json
# Aggiorna version.js
sed -i "s/APP_VERSION = '$old_version'/APP_VERSION = '$new_version'/" src/version.js
fi
print_success "Versione aggiornata nei file di configurazione"
}
# Funzione per ottenere la versione corrente
get_current_version() {
grep '"version"' package.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/'
}
# Funzione per verificare se la directory è pulita
check_git_status() {
if [[ -n $(git status --porcelain) ]]; then
print_warning "Ci sono modifiche non committate. Vuoi continuare? (y/N)"
read -r response
if [[ ! "$response" =~ ^[Yy]$ ]]; then
print_error "Operazione annullata"
exit 1
fi
fi
}
# Funzione per fare il commit e tag
commit_and_tag() {
local version=$1
local message="$2"
print_step "Aggiunta file modificati a git..."
git add package.json src-tauri/Cargo.toml src-tauri/Cargo.lock src-tauri/tauri.conf.json src/version.js
# Se ci sono altri file modificati, chiedi se aggiungerli
if [[ -n $(git status --porcelain | grep -v "package.json\|Cargo.toml\|Cargo.lock\|tauri.conf.json\|version.js") ]]; then
print_warning "Ci sono altri file modificati. Vuoi aggiungerli al commit? (y/N)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
git add .
fi
fi
print_step "Commit delle modifiche..."
git commit -m "chore: release v$version${message:+ - $message}"
print_step "Creazione tag v$version..."
git tag -a "v$version" -m "Release v$version${message:+ - $message}"
print_success "Commit e tag creati"
}
# Funzione per fare il push
push_changes() {
local version=$1
print_step "Push del commit principale..."
git push origin main
print_step "Push del tag v$version..."
git push origin "v$version"
print_success "Push completato"
}
# Funzione per aggiornare il tap Homebrew
update_homebrew_tap() {
local version=$1
local tap_repo_path="../homebrew-presto"
print_step "Aggiornamento del tap Homebrew..."
if [ ! -d "$tap_repo_path" ]; then
print_warning "Repository del tap Homebrew non trovato: $tap_repo_path"
print_warning "Saltando l'aggiornamento del tap Homebrew"
return 0
fi
# Vai nella directory del tap
cd "$tap_repo_path"
# Esegui lo script di aggiornamento
if [ -x "./update-homebrew-tap.sh" ]; then
./update-homebrew-tap.sh "$version"
print_success "Tap Homebrew aggiornato alla versione $version"
else
print_warning "Script di aggiornamento del tap non trovato o non eseguibile"
fi
# Torna alla directory originale
cd - > /dev/null
}
# Funzione per fare la build
build_app() {
print_step "Avvio build dell'applicazione..."
# Modifica per utilizzare bundles app invece di dmg
npm run tauri build -- --bundles app
print_success "Build completata"
}
# Funzione per aprire GitHub releases
open_github_releases() {
local repo_url=$(git config --get remote.origin.url)
if [[ $repo_url == *"github.com"* ]]; then
# Converte SSH URL in HTTPS
repo_url=$(echo $repo_url | sed 's/git@github.com:/https:\/\/github.com\//' | sed 's/\.git$//')
local releases_url="$repo_url/releases/new"
print_step "Aprendo pagina GitHub releases..."
if command -v open &> /dev/null; then
open "$releases_url"
elif command -v xdg-open &> /dev/null; then
xdg-open "$releases_url"
else
echo "Apri manualmente: $releases_url"
fi
fi
}
# Funzione principale
main() {
echo -e "${BLUE}"
echo "🚀 Script di Rilascio Automatico per Presto"
echo "===========================================${NC}"
# Controlla se siamo in una repo git
if [[ ! -d .git ]]; then
print_error "Non sei in una repository git"
exit 1
fi
# Ottieni versione corrente
current_version=$(get_current_version)
print_step "Versione corrente: $current_version"
# Chiedi tipo di rilascio
echo ""
echo "Che tipo di rilascio vuoi fare?"
echo "1) Patch (${current_version} → $(increment_version $current_version patch))"
echo "2) Minor (${current_version} → $(increment_version $current_version minor))"
echo "3) Major (${current_version} → $(increment_version $current_version major))"
echo "4) Versione specifica"
echo "5) Solo build (senza aggiornare versione)"
echo ""
read -p "Seleziona un'opzione (1-5): " choice
case $choice in
1)
release_type="patch"
new_version=$(increment_version $current_version patch)
;;
2)
release_type="minor"
new_version=$(increment_version $current_version minor)
;;
3)
release_type="major"
new_version=$(increment_version $current_version major)
;;
4)
read -p "Inserisci la nuova versione (formato x.y.z): " new_version
if [[ ! $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Formato versione non valido"
exit 1
fi
release_type="custom"
;;
5)
print_step "Solo build senza aggiornamento versione..."
build_app
print_success "Build completata!"
exit 0
;;
*)
print_error "Opzione non valida"
exit 1
;;
esac
# Messaggio opzionale per il rilascio
read -p "Messaggio opzionale per questo rilascio: " release_message
echo ""
print_step "Rilascio pianificato: $current_version → $new_version"
if [[ -n "$release_message" ]]; then
echo "Messaggio: $release_message"
fi
echo ""
# Conferma finale
read -p "Continuare con il rilascio? (y/N): " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
print_error "Rilascio annullato"
exit 1
fi
# Verifica stato git
check_git_status
# Aggiorna versione nei file
update_version_in_files $current_version $new_version
# Build
build_app
# Commit e tag
commit_and_tag $new_version "$release_message"
# Push
push_changes $new_version
# Aggiorna tap Homebrew
update_homebrew_tap $new_version
# Apri GitHub releases
print_step "Vuoi aprire la pagina GitHub releases per completare il rilascio? (Y/n)"
read -r open_github
if [[ ! "$open_github" =~ ^[Nn]$ ]]; then
open_github_releases
fi
echo ""
print_success "🎉 Rilascio v$new_version completato con successo!"
echo ""
echo "Prossimi passi:"
echo "1. Verifica che la build sia completata correttamente"
echo "2. Se hai aperto GitHub, crea la release con i file compilati"
echo "3. Il tag v$new_version è stato creato per il sistema di aggiornamenti automatici"
echo "4. Testa l'aggiornamento automatico dell'app"
echo ""
# Mostra informazioni sui file generati
if [[ -d "src-tauri/target" ]]; then
echo "File di build generati:"
find src-tauri/target -name "*.app.tar.gz" -o -name "*.app" -o -name "*.deb" -o -name "*.AppImage" 2>/dev/null | head -5
fi
}
# Gestione parametri da riga di comando
if [[ $# -gt 0 ]]; then
case $1 in
"--help"|"-h")
echo "Uso: $0 [opzioni]"
echo ""
echo "Opzioni:"
echo " --patch Incrementa versione patch"
echo " --minor Incrementa versione minor"
echo " --major Incrementa versione major"
echo " --version X.Y.Z Imposta versione specifica"
echo " --build-only Solo build senza aggiornare versione"
echo " --help Mostra questo messaggio"
echo ""
echo "Esempi:"
echo " $0 # Modalità interattiva"
echo " $0 --patch # Rilascio patch automatico"
echo " $0 --version 1.0.0 # Versione specifica"
exit 0
;;
"--patch")
current_version=$(get_current_version)
new_version=$(increment_version $current_version patch)
update_version_in_files $current_version $new_version
commit_and_tag $new_version
push_changes $new_version
build_app
update_homebrew_tap $new_version
print_success "Rilascio patch v$new_version completato!"
;;
"--minor")
current_version=$(get_current_version)
new_version=$(increment_version $current_version minor)
update_version_in_files $current_version $new_version
commit_and_tag $new_version
push_changes $new_version
build_app
update_homebrew_tap $new_version
print_success "Rilascio minor v$new_version completato!"
;;
"--major")
current_version=$(get_current_version)
new_version=$(increment_version $current_version major)
update_version_in_files $current_version $new_version
commit_and_tag $new_version
push_changes $new_version
build_app
update_homebrew_tap $new_version
print_success "Rilascio major v$new_version completato!"
;;
"--version")
if [[ -z $2 ]] || [[ ! $2 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
print_error "Versione non specificata o formato non valido"
exit 1
fi
current_version=$(get_current_version)
new_version=$2
update_version_in_files $current_version $new_version
commit_and_tag $new_version
push_changes $new_version
build_app
update_homebrew_tap $new_version
print_success "Rilascio v$new_version completato!"
;;
"--build-only")
build_app
print_success "Build completata!"
;;
*)
print_error "Opzione non riconosciuta: $1"
echo "Usa --help per vedere le opzioni disponibili"
exit 1
;;
esac
else
# Modalità interattiva
main
fi