Files
LMEMappeCatastaliProApp/scripts/build-android-test.ps1
T
2026-09-28 20:29:51 +02:00

112 lines
4.9 KiB
PowerShell

param(
[string]$Configuration = "Release"
)
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $PSScriptRoot
$dotnet = Join-Path $env:USERPROFILE ".dotnet10\dotnet.exe"
$androidSdk = Join-Path $env:LOCALAPPDATA "Android\Sdk"
$keytool = "C:\Program Files\Microsoft\jdk-17.0.19.10-hotspot\bin\keytool.exe"
$signingDirectory = Join-Path $env:LOCALAPPDATA "LME\Signing"
$keyStore = Join-Path $signingDirectory "lme-pro-test.keystore"
$passwordFile = Join-Path $signingDirectory "lme-pro-test-password.dpapi"
$outputDirectory = Join-Path $projectRoot "artifacts\android-test"
$projectPath = Join-Path $projectRoot "LMEMappeCatastaliApp.csproj"
[xml]$projectXml = Get-Content -Raw -LiteralPath $projectPath
$appVersion = ($projectXml.Project.PropertyGroup | Where-Object ApplicationDisplayVersion | Select-Object -First 1).ApplicationDisplayVersion
if ([string]::IsNullOrWhiteSpace($appVersion)) {
throw "ApplicationDisplayVersion non trovata nel progetto."
}
foreach ($requiredPath in @($dotnet, $keytool, $androidSdk)) {
if (-not (Test-Path -LiteralPath $requiredPath)) {
throw "Componente richiesto non trovato: $requiredPath"
}
}
New-Item -ItemType Directory -Force -Path $signingDirectory, $outputDirectory | Out-Null
if (-not (Test-Path -LiteralPath $passwordFile)) {
$passwordBytes = [System.Security.Cryptography.RandomNumberGenerator]::GetBytes(36)
$password = [Convert]::ToBase64String($passwordBytes).TrimEnd('=').Replace('+', '-').Replace('/', '_')
$password | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Set-Content -LiteralPath $passwordFile
}
$securePassword = (Get-Content -Raw -LiteralPath $passwordFile).Trim() | ConvertTo-SecureString
$credential = [System.Net.NetworkCredential]::new("lme-pro-test", $securePassword)
$plainPassword = $credential.Password
if (-not (Test-Path -LiteralPath $keyStore)) {
& $keytool -genkeypair -noprompt `
-keystore $keyStore `
-storepass $plainPassword `
-keypass $plainPassword `
-alias "lme-pro-test" `
-keyalg RSA `
-keysize 3072 `
-validity 3650 `
-dname "CN=LME Pro Test, OU=Testing, O=LME, L=Rome, C=IT"
if ($LASTEXITCODE -ne 0) {
throw "Creazione della chiave di test non riuscita."
}
}
$env:LME_ANDROID_TEST_STORE_PASS = $plainPassword
$env:LME_ANDROID_TEST_KEY_PASS = $plainPassword
$copiedPackages = [System.Collections.Generic.List[System.IO.FileInfo]]::new()
try {
foreach ($format in @("apk", "aab")) {
& $dotnet publish $projectPath `
-f net10.0-android `
-c $Configuration `
-p:AndroidSdkDirectory=$androidSdk `
-p:AndroidPackageFormat=$format `
-p:RunAOTCompilation=false `
-p:AndroidKeyStore=true `
-p:AndroidSigningKeyStore=$keyStore `
-p:AndroidSigningKeyAlias=lme-pro-test `
-p:AndroidSigningStorePass=env:LME_ANDROID_TEST_STORE_PASS `
-p:AndroidSigningKeyPass=env:LME_ANDROID_TEST_KEY_PASS
if ($LASTEXITCODE -ne 0) {
throw "Pubblicazione Android $format non riuscita."
}
$publishDirectory = Join-Path $projectRoot "bin\$Configuration\net10.0-android\publish"
$package = Get-ChildItem -LiteralPath $publishDirectory -Filter "*-Signed.$format" -File |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($null -eq $package) {
throw "Nessun pacchetto $format firmato prodotto in $publishDirectory"
}
$destination = Join-Path $outputDirectory "LME-Mappe-Catastali-Pro-$appVersion-test.$format"
Copy-Item -LiteralPath $package.FullName -Destination $destination -Force
$copiedPackages.Add((Get-Item -LiteralPath $destination))
}
}
finally {
Remove-Item Env:LME_ANDROID_TEST_STORE_PASS -ErrorAction SilentlyContinue
Remove-Item Env:LME_ANDROID_TEST_KEY_PASS -ErrorAction SilentlyContinue
$plainPassword = $null
$credential = $null
}
$licenseManagerArchive = Join-Path $outputDirectory "LME-Pro-LicenseManager-win-x64.zip"
$filesToHash = @($copiedPackages)
if (Test-Path -LiteralPath $licenseManagerArchive) {
$filesToHash += Get-Item -LiteralPath $licenseManagerArchive
}
$publicKeySource = Join-Path $projectRoot "tools\LmeLicenseManager\manual-license-public.pem"
if (Test-Path -LiteralPath $publicKeySource) {
$publicKeyDestination = Join-Path $outputDirectory "manual-license-public.pem"
Copy-Item -LiteralPath $publicKeySource -Destination $publicKeyDestination -Force
$filesToHash += Get-Item -LiteralPath $publicKeyDestination
}
$hashLines = $filesToHash | ForEach-Object {
$hash = Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName
"$($hash.Hash.ToLowerInvariant()) $($_.Name)"
}
$hashLines | Set-Content -LiteralPath (Join-Path $outputDirectory "SHA256SUMS.txt")
$copiedPackages | Select-Object Name, Length, LastWriteTime