forked from NetKeyer/NetKeyer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-installer.ps1
More file actions
186 lines (168 loc) · 8.36 KB
/
build-installer.ps1
File metadata and controls
186 lines (168 loc) · 8.36 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env pwsh
# Build script for creating NetKeyer cross-platform installers with Velopack
# Usage: ./build-installer.ps1 -Version "1.0.0" [-Platform "all|windows|linux"] [-AzureSignMetadata "path/to/metadata.json"]
# Examples:
# ./build-installer.ps1 -Version "1.0.0" # Build all platforms
# ./build-installer.ps1 -Version "1.0.0" -Platform windows # Build Windows only
# ./build-installer.ps1 -Version "1.0.0" -Platform windows -AzureSignMetadata "azure-signing.json" # Build and sign with Azure
param(
[Parameter(Mandatory=$true)]
[string]$Version,
[Parameter(Mandatory=$false)]
[ValidateSet("all", "windows", "linux", "macos")]
[string]$Platform = "all",
[Parameter(Mandatory=$false)]
[string]$AzureSignMetadata = ""
)
$ErrorActionPreference = "Stop"
Write-Host "Building NetKeyer installer(s) v$Version" -ForegroundColor Cyan
# Step 1: Install vpk tool if not already installed
Write-Host "`n[1/5] Checking vpk tool..." -ForegroundColor Yellow
$vpkInstalled = dotnet tool list -g | Select-String "vpk"
if (-not $vpkInstalled) {
Write-Host "Installing vpk tool..." -ForegroundColor Yellow
dotnet tool install -g vpk
}
# Step 2: Clean previous builds
Write-Host "`n[2/5] Cleaning previous builds..." -ForegroundColor Yellow
dotnet clean -c Release
# Remove all obj and bin directories to prevent cross-platform build contamination
Get-ChildItem -Path . -Include "obj","bin" -Recurse -Directory -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem -Path . -Filter "publish-*" -Directory | Remove-Item -Recurse -Force
if (Test-Path "Releases") { Remove-Item -Recurse -Force "Releases" }
# Function to build for a specific platform
function Build-Platform {
param(
[string]$PlatformName,
[string]$RuntimeId,
[string]$VpkTarget,
[string]$MainExe
)
Write-Host "`n=== Building for $PlatformName ($RuntimeId) ===" -ForegroundColor Blue
# Step 3: Publish the application
Write-Host "`n[3/5] Publishing $PlatformName application..." -ForegroundColor Yellow
dotnet publish NetKeyer.csproj `
-c Release `
--self-contained true `
-r $RuntimeId `
-p:PublishSingleFile=false `
-p:Version=$Version `
-o "publish-$PlatformName"
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed for $PlatformName!" -ForegroundColor Red
exit 1
}
# Step 4: Package with Velopack
Write-Host "`n[4/5] Creating $PlatformName installer package..." -ForegroundColor Yellow
# Use platform name as channel to ensure unique filenames
$Channel = $PlatformName
if ($VpkTarget -eq "windows") {
# Windows - use normal pack command when on Windows, or [win] directive for cross-compilation
if ($IsWindows -or ($PSVersionTable.Platform -eq $null)) {
# Check if Azure signing is enabled
if ($AzureSignMetadata -and (Test-Path $AzureSignMetadata)) {
Write-Host "Using Azure Trusted Signing with metadata file: $AzureSignMetadata" -ForegroundColor Cyan
vpk pack `
--packId "NetKeyer" `
--packVersion $Version `
--packDir "publish-$PlatformName" `
--mainExe $MainExe `
--packTitle "NetKeyer" `
--packAuthors "NetKeyer Contributors" `
--runtime $RuntimeId `
--channel $Channel `
--outputDir "Releases/$PlatformName" `
--azureTrustedSignFile $AzureSignMetadata
} else {
vpk pack `
--packId "NetKeyer" `
--packVersion $Version `
--packDir "publish-$PlatformName" `
--mainExe $MainExe `
--packTitle "NetKeyer" `
--packAuthors "NetKeyer Contributors" `
--runtime $RuntimeId `
--channel $Channel `
--outputDir "Releases/$PlatformName"
}
} else {
# Cross-compile from Linux/Mac
if ($AzureSignMetadata -and (Test-Path $AzureSignMetadata)) {
Write-Host "Using Azure Trusted Signing with metadata file: $AzureSignMetadata" -ForegroundColor Cyan
vpk "[win]" pack `
--packId "NetKeyer" `
--packVersion $Version `
--packDir "publish-$PlatformName" `
--mainExe $MainExe `
--packTitle "NetKeyer" `
--packAuthors "NetKeyer Contributors" `
--runtime $RuntimeId `
--channel $Channel `
--outputDir "Releases/$PlatformName" `
--azureTrustedSignFile $AzureSignMetadata
} else {
vpk "[win]" pack `
--packId "NetKeyer" `
--packVersion $Version `
--packDir "publish-$PlatformName" `
--mainExe $MainExe `
--packTitle "NetKeyer" `
--packAuthors "NetKeyer Contributors" `
--runtime $RuntimeId `
--channel $Channel `
--outputDir "Releases/$PlatformName"
}
}
} else {
# Linux/macOS uses regular pack command
vpk pack `
--packId "NetKeyer" `
--packVersion $Version `
--packDir "publish-$PlatformName" `
--mainExe $MainExe `
--packTitle "NetKeyer" `
--packAuthors "NetKeyer Contributors" `
--runtime $RuntimeId `
--channel $Channel `
--outputDir "Releases/$PlatformName"
}
if ($LASTEXITCODE -ne 0) {
Write-Host "Packaging failed for $PlatformName!" -ForegroundColor Red
exit 1
}
# Step 5: Display results for this platform
Write-Host "`n=== $PlatformName Build Complete ===" -ForegroundColor Green
Write-Host "Installer files located in: Releases/$PlatformName" -ForegroundColor Cyan
Write-Host "`nGenerated files:" -ForegroundColor Yellow
Get-ChildItem "Releases/$PlatformName" -File -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host " - $($_.Name) ($([math]::Round($_.Length / 1MB, 2)) MB)" -ForegroundColor White
}
}
# Build based on platform selection
switch ($Platform) {
"windows" {
Build-Platform -PlatformName "win-x64" -RuntimeId "win-x64" -VpkTarget "windows" -MainExe "NetKeyer.exe"
}
"linux" {
Build-Platform -PlatformName "linux-x64" -RuntimeId "linux-x64" -VpkTarget "linux" -MainExe "NetKeyer"
Build-Platform -PlatformName "linux-arm64" -RuntimeId "linux-arm64" -VpkTarget "linux" -MainExe "NetKeyer"
}
"macos" {
Write-Host "`nNote: macOS builds must be created on a Mac due to code signing requirements." -ForegroundColor Red
Write-Host "To build for macOS, run this script on a Mac with Xcode installed." -ForegroundColor Yellow
Build-Platform -PlatformName "osx-x64" -RuntimeId "osx-x64" -VpkTarget "macos" -MainExe "NetKeyer"
Build-Platform -PlatformName "osx-arm64" -RuntimeId "osx-arm64" -VpkTarget "macos" -MainExe "NetKeyer"
}
"all" {
Build-Platform -PlatformName "win-x64" -RuntimeId "win-x64" -VpkTarget "windows" -MainExe "NetKeyer.exe"
Build-Platform -PlatformName "linux-x64" -RuntimeId "linux-x64" -VpkTarget "linux" -MainExe "NetKeyer"
Build-Platform -PlatformName "linux-arm64" -RuntimeId "linux-arm64" -VpkTarget "linux" -MainExe "NetKeyer"
Write-Host "`nNote: macOS builds must be created on a Mac (see GitHub Actions workflow)." -ForegroundColor Yellow
}
}
Write-Host "`n=== All Builds Complete ===" -ForegroundColor Green
Write-Host "`nTo distribute:" -ForegroundColor Yellow
Write-Host " 1. Upload all files in Releases/* to your hosting service" -ForegroundColor White
Write-Host " 2. Windows: NetKeyer-$Version-Setup.exe" -ForegroundColor White
Write-Host " 3. Linux: NetKeyer-$Version.AppImage (x64/arm64)" -ForegroundColor White
Write-Host " 4. macOS: NetKeyer-$Version.dmg (x64/arm64)" -ForegroundColor White