diff --git a/Scripts.md b/Scripts.md index ac121f1..f41708c 100644 --- a/Scripts.md +++ b/Scripts.md @@ -129,4 +129,133 @@ Rendre le script executable : --- -# Script Windows PowerShell — scripts/release.ps1 \ No newline at end of file +# Script Windows PowerShell — scripts/release.ps1 +``` + +#requires -Version 5.1 +# Script de release Windows pour Paycheck +# Objectif : +# - Garantir que le build est fait EXACTEMENT depuis un tag vX.Y.Z +# - Construire le frontend +# - Builder l’application Wails en Windows/amd64 +# - Renommer proprement le binaire +# - Générer une archive ZIP prête pour la release Gitea + +$ErrorActionPreference = "Stop" +# Stop : PowerShell arrête le script dès qu’une commande échoue + +$App = "paycheck" # Nom du binaire (sans .exe) +$Arch = "amd64" # Architecture cible (x86_64) +$Platform = "windows" # Plateforme cible + +Write-Host "== Paycheck - Release Windows ==" + +# Vérification que l’on est bien à la racine du dépôt +# (wails.json est un bon marqueur) +if (!(Test-Path "wails.json")) { + throw "ERREUR : wails.json introuvable. Lance ce script depuis la racine du dépôt." +} + +# Vérification que le dépôt Git est propre +# On refuse toute release avec des fichiers modifiés non commités +$porcelain = git status --porcelain +if ($porcelain) { + Write-Host "ERREUR : le dépôt Git n'est pas propre." + Write-Host "Commit ou stash tes modifications avant de lancer une release." + git status --porcelain + exit 1 +} + +# Vérification que l’on est EXACTEMENT sur un tag +# --exact-match échoue si HEAD n’est pas pointé par un tag +$tag = "" +try { + $tag = (git describe --tags --exact-match).Trim() +} catch { + $tag = "" +} + +if ([string]::IsNullOrWhiteSpace($tag)) { + throw "ERREUR : tu n'es pas positionné sur un tag. Astuce : git fetch --tags ; git checkout vX.Y.Z" +} + +# Vérification du format du tag (SemVer strict), ex: v1.0.0 +if ($tag -notmatch '^v\d+\.\d+\.\d+$') { + throw "ERREUR : le tag '$tag' ne respecte pas le format vX.Y.Z" +} + +Write-Host "Tag détecté : $tag" +Write-Host "Commit utilisé : $(git rev-parse HEAD)" + +# ========================= +# Build du frontend +# ========================= +Write-Host "== Build frontend ==" + +Push-Location frontend + +# Utilisation de npm ci si possible (build reproductible) +if (Test-Path "package-lock.json") { + npm ci +} else { + npm install +} + +# Build Vite / frontend +npm run build + +Pop-Location + +# ========================= +# Build Wails (Windows/amd64) +# ========================= +Write-Host "== Build Wails ==" + +# Nettoyage des anciens binaires +if (Test-Path "build\bin") { + Remove-Item -Recurse -Force "build\bin" +} + +# Build Wails Windows/amd64 +# -o : force le nom de sortie (ici paycheck.exe) +wails build -platform windows/amd64 -o "$App.exe" + +$outDir = "build\bin" +$src = Join-Path $outDir "$App.exe" + +# Vérification que le binaire a bien été généré +if (!(Test-Path $src)) { + throw "ERREUR : binaire attendu introuvable : $src" +} + +# Nom final standardisé du binaire +# Exemple : paycheck-v1.0.1-windows-amd64.exe +$finalExe = Join-Path $outDir "$App-$tag-$Platform-$Arch.exe" + +# Copie du binaire sous son nom final +Copy-Item $src $finalExe -Force + +# ========================= +# Création de l’archive ZIP +# ========================= +Write-Host "== Création de l'archive ZIP ==" + +$zipPath = Join-Path $outDir "$App-$tag-$Platform-$Arch.zip" + +# Nettoyage si le zip existe déjà +if (Test-Path $zipPath) { + Remove-Item -Force $zipPath +} + +# Zip du binaire final +Compress-Archive -Path $finalExe -DestinationPath $zipPath -Force + +Write-Host "Release Windows terminée avec succès." +Write-Host "Artefact prêt : $zipPath" +``` + +Exécution (si la politique PowerShell bloque) +``` +Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass +.\scripts\release.ps1 +```