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