ci / verifier-pack (push) Successful in 1m33s
Le script ne cherchait que dans les dossiers de l'installeur officiel (Program Files, LOCALAPPDATA) : avec Scoop, il concluait à tort à une absence d'AutoHotkey. Détection désormais, dans l'ordre : - variables d'environnement PROMPTKEY_AHK_EXE / PROMPTKEY_AHK2EXE ; - PATH via Get-Command (shims Scoop inclus), avec résolution de la cible réelle du shim (le fichier .shim compagnon) car un shim ne peut pas servir de base à Ahk2Exe ; - dossiers usuels de l'installeur officiel ; - racines Scoop (SCOOP, ~/scoop, SCOOP_GLOBAL, ProgramData\scoop), apps\autohotkey\current et dossiers de version. Si seul le lanceur AutoHotkey.exe est trouvé, préférer le vrai AutoHotkey64.exe voisin comme base de compilation. Messages d'erreur détaillant les endroits cherchés et les contournements.
151 lines
7.2 KiB
PowerShell
151 lines
7.2 KiB
PowerShell
# PromptKey — compilation et assemblage de l'archive portable.
|
|
#
|
|
# Usage : .\build.ps1
|
|
#
|
|
# Étapes :
|
|
# 1. Vérifie la présence d'AutoHotkey v2 et du compilateur Ahk2Exe.
|
|
# 2. Lance les scripts de tests\ s'il y en a (échec = arrêt du build).
|
|
# 3. Compile PromptKey.ahk en dist\PromptKey.exe.
|
|
# 4. Assemble dist\PromptKey-portable.zip (exe + packs + README + LICENSE).
|
|
# 5. Affiche la somme SHA256 de l'exécutable.
|
|
#
|
|
# Prérequis : AutoHotkey v2.0 (64 bits) installé, Ahk2Exe fourni avec
|
|
# (dossier Compiler\ de l'installation AutoHotkey). Installations détectées :
|
|
# installeur officiel, Scoop (PATH/shims et apps\), ou chemins imposés par
|
|
# les variables d'environnement PROMPTKEY_AHK_EXE / PROMPTKEY_AHK2EXE.
|
|
|
|
#Requires -Version 5.1
|
|
$ErrorActionPreference = 'Stop'
|
|
$Racine = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location $Racine
|
|
|
|
function Echouer($Message) {
|
|
Write-Host "ERREUR : $Message" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# --- 1. Localiser AutoHotkey v2 et Ahk2Exe ----------------------------------
|
|
# Ordre de détection :
|
|
# 1. Variables d'environnement PROMPTKEY_AHK_EXE / PROMPTKEY_AHK2EXE (si définies).
|
|
# 2. Le PATH : Get-Command (couvre notamment les shims Scoop, dont on résout
|
|
# la cible réelle — le shim lui-même ne peut pas servir de « base » à Ahk2Exe).
|
|
# 3. Les dossiers d'installation usuels (installeur officiel).
|
|
# 4. Les racines Scoop : $env:SCOOP, %USERPROFILE%\scoop, $env:SCOOP_GLOBAL,
|
|
# %ProgramData%\scoop (apps\autohotkey\current\ et dossiers de version).
|
|
|
|
function Resoudre-Shim($Chemin) {
|
|
# Un shim Scoop a un fichier compagnon <nom>.shim contenant « path = "..." ».
|
|
if ($Chemin -and (Test-Path $Chemin)) {
|
|
# Le compagnon d'un shim « truc.exe » s'appelle « truc.shim ».
|
|
$CandidatsShim = @(($Chemin -replace '\.exe$', '.shim'), "$Chemin.shim")
|
|
foreach ($FichierShim in $CandidatsShim) {
|
|
if (Test-Path $FichierShim) {
|
|
foreach ($Ligne in Get-Content $FichierShim) {
|
|
if ($Ligne -match '^\s*path\s*=\s*"(.+)"\s*$' -and (Test-Path $Matches[1])) {
|
|
return $Matches[1]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $Chemin
|
|
}
|
|
|
|
function Chercher-DansDossiers($Dossiers, $Noms) {
|
|
foreach ($Dossier in $Dossiers) {
|
|
if ($Dossier -and (Test-Path $Dossier)) {
|
|
foreach ($Nom in $Noms) {
|
|
$Trouve = Get-ChildItem -Path $Dossier -Recurse -Filter $Nom -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
if ($Trouve) { return $Trouve.FullName }
|
|
}
|
|
}
|
|
}
|
|
return $null
|
|
}
|
|
|
|
function Chercher-DansPath($Noms) {
|
|
foreach ($Nom in $Noms) {
|
|
$Cmd = Get-Command $Nom -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
if ($Cmd) { return Resoudre-Shim $Cmd.Source }
|
|
}
|
|
return $null
|
|
}
|
|
|
|
$RacinesScoop = @($env:SCOOP, "$env:USERPROFILE\scoop", $env:SCOOP_GLOBAL, "$env:ProgramData\scoop") |
|
|
Where-Object { $_ } | Select-Object -Unique
|
|
$DossiersRecherche = @(
|
|
"$env:ProgramFiles\AutoHotkey",
|
|
"${env:ProgramFiles(x86)}\AutoHotkey",
|
|
"$env:LOCALAPPDATA\Programs\AutoHotkey"
|
|
)
|
|
foreach ($RacineScoop in $RacinesScoop) {
|
|
$DossiersRecherche += Join-Path $RacineScoop 'apps\autohotkey\current'
|
|
$DossiersRecherche += Join-Path $RacineScoop 'apps\autohotkey'
|
|
}
|
|
|
|
$AhkExe = $null
|
|
$Ahk2Exe = $null
|
|
if ($env:PROMPTKEY_AHK_EXE -and (Test-Path $env:PROMPTKEY_AHK_EXE)) { $AhkExe = $env:PROMPTKEY_AHK_EXE }
|
|
if (-not $AhkExe) { $AhkExe = Chercher-DansPath @('AutoHotkey64.exe', 'AutoHotkey.exe', 'autohotkey.exe') }
|
|
if (-not $AhkExe) { $AhkExe = Chercher-DansDossiers $DossiersRecherche @('AutoHotkey64.exe', 'AutoHotkey.exe') }
|
|
if ($AhkExe -and ((Split-Path -Leaf $AhkExe) -ieq 'AutoHotkey.exe')) {
|
|
# « AutoHotkey.exe » tout court est le lanceur (installeur ou shim) : comme base
|
|
# de compilation, Ahk2Exe exige le vrai interpréteur 64 bits — le chercher à côté.
|
|
$Mieux = Chercher-DansDossiers @((Split-Path -Parent $AhkExe)) @('AutoHotkey64.exe')
|
|
if ($Mieux) { $AhkExe = $Mieux }
|
|
}
|
|
if ($env:PROMPTKEY_AHK2EXE -and (Test-Path $env:PROMPTKEY_AHK2EXE)) { $Ahk2Exe = $env:PROMPTKEY_AHK2EXE }
|
|
if (-not $Ahk2Exe -and $AhkExe) {
|
|
# Cas le plus fréquent : Compiler\Ahk2Exe.exe à côté de l'interpréteur trouvé.
|
|
$Voisin = Join-Path (Split-Path -Parent $AhkExe) 'Compiler\Ahk2Exe.exe'
|
|
if (Test-Path $Voisin) { $Ahk2Exe = $Voisin }
|
|
}
|
|
if (-not $Ahk2Exe) { $Ahk2Exe = Chercher-DansPath @('Ahk2Exe.exe', 'ahk2exe.exe') }
|
|
if (-not $Ahk2Exe) { $Ahk2Exe = Chercher-DansDossiers $DossiersRecherche @('Ahk2Exe.exe') }
|
|
|
|
if (-not $AhkExe) { Echouer "AutoHotkey v2 introuvable (cherché : PATH et shims, dossiers d'installation usuels, racines Scoop [$($RacinesScoop -join ', ')]). Installez AutoHotkey v2.0 (64 bits) — installeur https://www.autohotkey.com/ ou « scoop install autohotkey » — ou définissez la variable d'environnement PROMPTKEY_AHK_EXE vers AutoHotkey64.exe." }
|
|
if (-not $Ahk2Exe) { Echouer "Ahk2Exe introuvable. Il est fourni avec AutoHotkey v2 (dossier Compiler\ de l'installation, y compris Scoop) ; à défaut, définissez la variable d'environnement PROMPTKEY_AHK2EXE vers Ahk2Exe.exe." }
|
|
|
|
# Vérifier qu'il s'agit bien de la v2 (le champ FileVersion commence par 2.)
|
|
$Version = (Get-Item $AhkExe).VersionInfo.FileVersion
|
|
if ($Version -notmatch '^2\.') { Echouer "AutoHotkey v2 requis, version trouvée : $Version ($AhkExe)" }
|
|
Write-Host "AutoHotkey $Version : $AhkExe"
|
|
Write-Host "Ahk2Exe : $Ahk2Exe"
|
|
|
|
# --- 2. Tests (si présents) --------------------------------------------------
|
|
$DossierTests = Join-Path $Racine 'tests'
|
|
if (Test-Path $DossierTests) {
|
|
$Scripts = Get-ChildItem -Path $DossierTests -Filter '*.ahk'
|
|
foreach ($Script in $Scripts) {
|
|
Write-Host "Test : $($Script.Name)"
|
|
& $AhkExe /ErrorStdOut $Script.FullName
|
|
if ($LASTEXITCODE -ne 0) { Echouer "Échec du test $($Script.Name) (code $LASTEXITCODE). Build interrompu." }
|
|
}
|
|
if ($Scripts.Count -eq 0) { Write-Host "Aucun script de test dans tests\ — étape sautée." }
|
|
}
|
|
|
|
# --- 3. Compilation ----------------------------------------------------------
|
|
$Dist = Join-Path $Racine 'dist'
|
|
if (-not (Test-Path $Dist)) { New-Item -ItemType Directory -Path $Dist | Out-Null }
|
|
$Source = Join-Path $Racine 'PromptKey.ahk'
|
|
if (-not (Test-Path $Source)) { Echouer "Fichier source introuvable : $Source" }
|
|
$Exe = Join-Path $Dist 'PromptKey.exe'
|
|
if (Test-Path $Exe) { Remove-Item $Exe -Force }
|
|
|
|
Write-Host "Compilation de PromptKey.ahk ..."
|
|
& $Ahk2Exe /in $Source /out $Exe /base $AhkExe
|
|
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $Exe)) { Echouer "La compilation a échoué." }
|
|
Write-Host "Exécutable produit : $Exe"
|
|
|
|
# --- 4. Archive portable -----------------------------------------------------
|
|
$Zip = Join-Path $Dist 'PromptKey-portable.zip'
|
|
if (Test-Path $Zip) { Remove-Item $Zip -Force }
|
|
$AInclure = @($Exe, (Join-Path $Racine 'README.md'), (Join-Path $Racine 'LICENSE'), (Join-Path $Racine 'CHANGELOG.md'), (Join-Path $Racine 'packs'))
|
|
Compress-Archive -Path $AInclure -DestinationPath $Zip
|
|
Write-Host "Archive portable : $Zip"
|
|
|
|
# --- 5. Somme de contrôle ----------------------------------------------------
|
|
$Hash = Get-FileHash -Algorithm SHA256 $Exe
|
|
Write-Host "SHA256 de l'exe : $($Hash.Hash)"
|
|
Write-Host "Build terminé."
|