- Add version.properties file as single source of truth for VERSION_NAME and VERSION_CODE - Create build.ps1 script with automated version bumping (Major/Minor/Patch/None) and build orchestration - Update app/build.gradle.kts to read version from version.properties instead of hardcoded values - Display dynamic version info in Settings screen using BuildConfig.VERSION_NAME and VERSION_CODE - Add
209 lines
7.5 KiB
PowerShell
209 lines
7.5 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Script de build et de versioning pour ShaarIt.
|
|
.DESCRIPTION
|
|
Incrémente la version (Major, Minor, Patch) dans version.properties
|
|
et lance le build Gradle approprié (Debug/Release) avec le format de sortie choisi (APK/AAB).
|
|
.PARAMETER Type
|
|
Le type de build : 'Debug' ou 'Release'. Défaut: Debug.
|
|
.PARAMETER Bump
|
|
Quelle partie de la version augmenter : 'Major', 'Minor', 'Patch' (défaut), ou 'None'.
|
|
.PARAMETER OutputFormat
|
|
Format de sortie : 'APK' (défaut) ou 'AAB' (pour Google Play Store).
|
|
.PARAMETER Clean
|
|
Si spécifié, effectue un clean avant le build.
|
|
.EXAMPLE
|
|
.\build.ps1
|
|
# Incrémente le Patch (ex: 1.0.0 -> 1.0.1), augmente le VersionCode, build Debug APK.
|
|
.EXAMPLE
|
|
.\build.ps1 -Type Release -Bump Minor
|
|
# Passe à 1.1.0, augmente le VersionCode, build Release APK.
|
|
.EXAMPLE
|
|
.\build.ps1 -Type Release -Bump Minor -OutputFormat AAB
|
|
# Passe à 1.1.0, augmente le VersionCode, build Release AAB (pour Play Store).
|
|
.EXAMPLE
|
|
.\build.ps1 -Type Debug -Bump None
|
|
# Recompile en Debug sans changer la version.
|
|
.EXAMPLE
|
|
.\build.ps1 -Type Release -Bump Major -Clean
|
|
# Passe à 2.0.0, augmente le VersionCode, build Release APK avec clean.
|
|
#>
|
|
param (
|
|
[ValidateSet("Debug", "Release")]
|
|
[string]$Type = "Debug",
|
|
|
|
[ValidateSet("Major", "Minor", "Patch", "None")]
|
|
[string]$Bump = "Patch",
|
|
|
|
[ValidateSet("APK", "AAB")]
|
|
[string]$OutputFormat = "APK",
|
|
|
|
[switch]$Clean
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$PropFile = Join-Path $PSScriptRoot "version.properties"
|
|
|
|
# --- 1. Vérifier que le fichier version.properties existe ---
|
|
if (-not (Test-Path $PropFile)) {
|
|
Write-Error "Le fichier version.properties est introuvable à : $PropFile"
|
|
exit 1
|
|
}
|
|
|
|
# --- 2. Lire les propriétés actuelles ---
|
|
$VersionName = $null
|
|
$VersionCode = $null
|
|
|
|
foreach ($line in (Get-Content $PropFile)) {
|
|
$line = $line.Trim()
|
|
if ($line.StartsWith("#") -or [string]::IsNullOrWhiteSpace($line)) { continue }
|
|
if ($line -match "^VERSION_NAME=(.+)$") { $VersionName = $Matches[1] }
|
|
if ($line -match "^VERSION_CODE=(\d+)$") { $VersionCode = [int]$Matches[1] }
|
|
}
|
|
|
|
if (-not $VersionName -or -not $VersionCode) {
|
|
Write-Error "Impossible de lire VERSION_NAME ou VERSION_CODE depuis $PropFile"
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor DarkCyan
|
|
Write-Host " ShaarIt Build Script" -ForegroundColor DarkCyan
|
|
Write-Host "========================================" -ForegroundColor DarkCyan
|
|
Write-Host " Version actuelle : $VersionName (code: $VersionCode)" -ForegroundColor Cyan
|
|
Write-Host " Type de build : $Type" -ForegroundColor Cyan
|
|
Write-Host " Format sortie : $OutputFormat" -ForegroundColor Cyan
|
|
Write-Host " Bump : $Bump" -ForegroundColor Cyan
|
|
Write-Host " Clean avant build: $(if ($Clean) { 'Oui' } else { 'Non' })" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor DarkCyan
|
|
Write-Host ""
|
|
|
|
# --- 3. Logique d'incrémentation ---
|
|
if ($Bump -ne "None") {
|
|
$Parts = $VersionName.Split('.')
|
|
if ($Parts.Count -ne 3) {
|
|
Write-Error "VERSION_NAME '$VersionName' n'est pas au format semver (X.Y.Z)"
|
|
exit 1
|
|
}
|
|
|
|
$Major = [int]$Parts[0]
|
|
$Minor = [int]$Parts[1]
|
|
$Patch = [int]$Parts[2]
|
|
|
|
switch ($Bump) {
|
|
"Major" { $Major++; $Minor = 0; $Patch = 0 }
|
|
"Minor" { $Minor++; $Patch = 0 }
|
|
"Patch" { $Patch++ }
|
|
}
|
|
|
|
$VersionCode++
|
|
$NewVersionName = "$Major.$Minor.$Patch"
|
|
|
|
# --- 4. Sauvegarde dans le fichier ---
|
|
$Timestamp = Get-Date -Format "ddd MMM dd HH:mm:ss yyyy"
|
|
$Content = @"
|
|
#$Timestamp
|
|
VERSION_NAME=$NewVersionName
|
|
VERSION_CODE=$VersionCode
|
|
"@
|
|
Set-Content -Path $PropFile -Value $Content -NoNewline -Encoding UTF8
|
|
|
|
Write-Host " Nouvelle version : $NewVersionName (code: $VersionCode)" -ForegroundColor Green
|
|
Write-Host ""
|
|
} else {
|
|
$NewVersionName = $VersionName
|
|
Write-Host " Aucun changement de version." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
}
|
|
|
|
# --- 5. Lancement du Build Gradle ---
|
|
$GradleCmd = Join-Path $PSScriptRoot "gradlew.bat"
|
|
|
|
if (-not (Test-Path $GradleCmd)) {
|
|
Write-Error "gradlew.bat introuvable à : $GradleCmd"
|
|
exit 1
|
|
}
|
|
|
|
# Déterminer la commande Gradle en fonction des paramètres
|
|
$GradleTask = ""
|
|
if ($Type -eq "Debug") {
|
|
if ($OutputFormat -eq "APK") {
|
|
$GradleTask = "assembleDebug"
|
|
} else {
|
|
Write-Error "Le format AAB n'est pas disponible pour les builds Debug. Utilisez -Type Release avec -OutputFormat AAB."
|
|
exit 1
|
|
}
|
|
} else { # Release
|
|
if ($OutputFormat -eq "APK") {
|
|
$GradleTask = "assembleRelease"
|
|
} else {
|
|
$GradleTask = "bundleRelease"
|
|
}
|
|
}
|
|
|
|
# Ajouter clean si demandé
|
|
if ($Clean) {
|
|
$GradleTask = "clean $GradleTask"
|
|
}
|
|
|
|
Write-Host " Lancement : gradlew $GradleTask" -ForegroundColor Magenta
|
|
Write-Host ""
|
|
& $GradleCmd $GradleTask.Split(" ")
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host " Build $Type terminé avec succès !" -ForegroundColor Green
|
|
Write-Host " Version : $NewVersionName (code: $VersionCode)" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
|
|
# --- 6. Renommage des fichiers générés ---
|
|
Write-Host ""
|
|
Write-Host " Renommage des fichiers..." -ForegroundColor Cyan
|
|
|
|
$ProjectRoot = $PSScriptRoot
|
|
$BuildDir = Join-Path $ProjectRoot "app\build\outputs"
|
|
|
|
if ($Type -eq "Debug") {
|
|
$SourceFile = Join-Path $BuildDir "apk\debug\app-debug.apk"
|
|
if (Test-Path $SourceFile) {
|
|
$NewFileName = "ShaarIt-debug-$NewVersionName.apk"
|
|
$DestFile = Join-Path $BuildDir "apk\debug\$NewFileName"
|
|
Rename-Item -Path $SourceFile -NewName $NewFileName -Force
|
|
Write-Host " ✓ Renommé: $NewFileName" -ForegroundColor Green
|
|
Write-Host " Emplacement: $DestFile" -ForegroundColor Gray
|
|
}
|
|
} else { # Release
|
|
if ($OutputFormat -eq "APK") {
|
|
$SourceFile = Join-Path $BuildDir "apk\release\app-release.apk"
|
|
if (Test-Path $SourceFile) {
|
|
$NewFileName = "ShaarIt-$NewVersionName.apk"
|
|
$DestFile = Join-Path $BuildDir "apk\release\$NewFileName"
|
|
Rename-Item -Path $SourceFile -NewName $NewFileName -Force
|
|
Write-Host " ✓ Renommé: $NewFileName" -ForegroundColor Green
|
|
Write-Host " Emplacement: $DestFile" -ForegroundColor Gray
|
|
}
|
|
} else {
|
|
$SourceFile = Join-Path $BuildDir "bundle\release\app-release.aab"
|
|
if (Test-Path $SourceFile) {
|
|
$NewFileName = "ShaarIt-$NewVersionName.aab"
|
|
$DestFile = Join-Path $BuildDir "bundle\release\$NewFileName"
|
|
Rename-Item -Path $SourceFile -NewName $NewFileName -Force
|
|
Write-Host " ✓ Renommé: $NewFileName" -ForegroundColor Green
|
|
Write-Host " Emplacement: $DestFile" -ForegroundColor Gray
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host " Opérations terminées avec succès !" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
} else {
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Red
|
|
Write-Host " ERREUR lors du build $Type" -ForegroundColor Red
|
|
Write-Host "========================================" -ForegroundColor Red
|
|
exit $LASTEXITCODE
|
|
}
|