-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
105 lines (90 loc) · 4.32 KB
/
Copy pathbuild.ps1
File metadata and controls
105 lines (90 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#Requires -Version 5.1
<#
.SYNOPSIS
One-command full build for Grex (Windows only).
.DESCRIPTION
Does everything: restore -> build (Release|x64) -> test -> publish the
self-contained win-x64 GUI and CLI -> package versioned zips, and (if Inno
Setup is installed) a setup.exe with a built-in uninstaller, into .\dist\.
WinUI 3 only builds on Windows. No parameters - just run: .\build.ps1
#>
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue' # keeps Compress-Archive fast
Set-Location -LiteralPath $PSScriptRoot # the script lives at the repo root
# WinUI 3 cannot build off-Windows - fail early with a clear message.
if ($PSVersionTable.PSVersion.Major -ge 6 -and -not $IsWindows) {
throw 'Grex is a WinUI 3 app and can only be built on Windows.'
}
$Platform = 'x64'
$Config = 'Release'
$Rid = 'win-x64'
function Step([string] $Name) { Write-Host "`n==> $Name" -ForegroundColor Cyan }
function Confirm-Exit([string] $What) {
if ($LASTEXITCODE -ne 0) { throw "$What failed (exit code $LASTEXITCODE)." }
}
# Version comes from the single source of truth, Directory.Build.props.
$match = Select-String -LiteralPath 'Directory.Build.props' -Pattern '<Version>\s*([\d.]+)\s*</Version>' |
Select-Object -First 1
$Version = if ($match) { $match.Matches[0].Groups[1].Value } else { '0.0.0' }
Write-Host "Grex build v$Version ($Config | $Platform | $Rid)" -ForegroundColor White
Step 'Restore'
dotnet restore grex.sln
Confirm-Exit 'Restore'
Step 'Build'
dotnet build grex.sln -p:Platform=$Platform -c $Config --no-restore
Confirm-Exit 'Build'
Step 'Test'
dotnet test grex.sln -p:Platform=$Platform -p:WindowsAppSdkBootstrapInitialize=false -c $Config --no-restore
$testsPassed = ($LASTEXITCODE -eq 0)
if (-not $testsPassed) {
Write-Warning "Tests failed (exit $LASTEXITCODE) - continuing so artifacts are still produced."
}
$dist = Join-Path $PSScriptRoot 'dist'
$guiDir = Join-Path $dist "grex-$Version-$Rid"
$cliDir = Join-Path $dist "grex-cli-$Version-$Rid"
Step "Publish GUI -> $guiDir"
dotnet publish Grex.csproj -p:Platform=$Platform -c $Config -r $Rid --self-contained -o $guiDir
Confirm-Exit 'GUI publish'
Step "Publish CLI -> $cliDir"
dotnet publish Grex.Cli/Grex.Cli.csproj -p:Platform=$Platform -c $Config -r $Rid --self-contained -o $cliDir
Confirm-Exit 'CLI publish'
Step 'Package'
$guiZip = Join-Path $dist "grex-$Version-$Rid.zip"
$cliZip = Join-Path $dist "grex-cli-$Version-$Rid.zip"
Remove-Item -LiteralPath $guiZip, $cliZip -ErrorAction SilentlyContinue
Compress-Archive -Path (Join-Path $guiDir '*') -DestinationPath $guiZip
Compress-Archive -Path (Join-Path $cliDir '*') -DestinationPath $cliZip
# Build a setup.exe (with a built-in uninstaller) via Inno Setup, if its compiler is present.
Step 'Installer (setup.exe)'
$iscc = (Get-Command 'iscc.exe' -ErrorAction SilentlyContinue).Source
if (-not $iscc) {
# Find ISCC.exe under any "Inno Setup <n>" folder (6, 7, ...), newest first.
foreach ($base in @(${env:ProgramFiles(x86)}, ${env:ProgramFiles})) {
if (-not $base) { continue }
$hit = Get-ChildItem -LiteralPath $base -Directory -Filter 'Inno Setup *' -ErrorAction SilentlyContinue |
ForEach-Object { Join-Path $_.FullName 'ISCC.exe' } |
Where-Object { Test-Path -LiteralPath $_ } |
Sort-Object -Descending | Select-Object -First 1
if ($hit) { $iscc = $hit; break }
}
}
$setupExe = Join-Path $dist "grex-$Version-setup.exe"
if ($iscc) {
& $iscc "/DAppVersion=$Version" "/DSourceDir=$guiDir" "/DCliDir=$cliDir" "/DOutputDir=$dist" (Join-Path $PSScriptRoot 'Grex.iss')
Confirm-Exit 'Inno Setup compile'
}
else {
$setupExe = $null
Write-Warning 'Inno Setup compiler (ISCC.exe) not found - skipping setup.exe. Get it from https://jrsoftware.org/isdl.php'
}
Step 'Done'
$artifacts = @($guiZip, $cliZip)
if ($setupExe -and (Test-Path -LiteralPath $setupExe)) { $artifacts += $setupExe }
foreach ($artifact in $artifacts) {
$file = Get-Item -LiteralPath $artifact
Write-Host (' {0} ({1:N1} MB)' -f $file.FullName, ($file.Length / 1MB)) -ForegroundColor Green
}
if (-not $testsPassed) {
Write-Warning 'Artifacts were produced, but TESTS FAILED above - review before shipping.'
exit 1
}