Skip to content

Commit ed55678

Browse files
committed
feat: add Windows release script with MSI installer and update artifacts
1 parent e51550a commit ed55678

File tree

1 file changed

+68
-41
lines changed

1 file changed

+68
-41
lines changed

scripts/release-windows.ps1

Lines changed: 68 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
param(
99
[string]$Version,
10-
[switch]$Help
10+
[switch]$Help,
11+
[switch]$SkipBuild
1112
)
1213

1314
# Colors for PowerShell output
@@ -19,10 +20,10 @@ function Write-ColorOutput {
1920
Write-Host $Message -ForegroundColor $Color
2021
}
2122

22-
function Write-Success { param([string]$Message) Write-ColorOutput " $Message" "Green" }
23-
function Write-Warning { param([string]$Message) Write-ColorOutput " $Message" "Yellow" }
23+
function Write-Success { param([string]$Message) Write-ColorOutput "[OK] $Message" "Green" }
24+
function Write-Warning { param([string]$Message) Write-ColorOutput "[WARN] $Message" "Yellow" }
2425
function Write-Error { param([string]$Message) Write-ColorOutput "$Message" "Red" }
25-
function Write-Info { param([string]$Message) Write-ColorOutput " $Message" "Cyan" }
26+
function Write-Info { param([string]$Message) Write-ColorOutput "[INFO] $Message" "Cyan" }
2627
function Write-Step { param([string]$Message) Write-ColorOutput "🚀 $Message" "Magenta" }
2728

2829
# Show help
@@ -36,6 +37,7 @@ It is designed to run AFTER the macOS release script has created the release.
3637
Usage:
3738
.\scripts\release-windows.ps1 # Use version from package.json
3839
.\scripts\release-windows.ps1 1.4.0 # Use specific version
40+
.\scripts\release-windows.ps1 -SkipBuild # Skip build, use existing artifacts
3941
.\scripts\release-windows.ps1 -Help # Show this help
4042
4143
Requirements:
@@ -62,6 +64,9 @@ Environment Variables:
6264

6365
Write-Step "Starting VoiceTypr Windows Release Process"
6466

67+
# Remember initial directory so we can return even on errors
68+
$InitialDir = Get-Location
69+
6570
# Error handling
6671
$ErrorActionPreference = "Stop"
6772

@@ -154,6 +159,9 @@ Write-Success "Created output directory: $OutputDir"
154159
$HasSigningKey = $false
155160
$keyPath = "$env:USERPROFILE\.tauri\voicetypr.key"
156161

162+
# If needed you can export TAURI_SIGNING_PRIVATE_KEY_PATH before running this script
163+
# $env:TAURI_SIGNING_PRIVATE_KEY_PATH = "C:\Users\moinu\.tauri\voicetypr.key"
164+
157165
# Auto-detect and set key path if file exists
158166
if (Test-Path $keyPath) {
159167
$env:TAURI_SIGNING_PRIVATE_KEY_PATH = $keyPath
@@ -171,25 +179,36 @@ if (Test-Path $keyPath) {
171179
}
172180

173181
# Build Windows NSIS installer
174-
Write-Step "Building Windows NSIS installer..."
175-
try {
176-
Set-Location "src-tauri"
177-
$buildOutput = cargo tauri build --target x86_64-pc-windows-msvc 2>&1
178-
Set-Location ".."
179-
180-
if ($LASTEXITCODE -ne 0) {
181-
Write-Error "Build failed. Output: $buildOutput"
182+
if (-not $SkipBuild) {
183+
Write-Step "Building Windows NSIS installer..."
184+
try {
185+
# Run Tauri build with verbose output
186+
Write-Info "Building Tauri application (this may take several minutes)..."
187+
188+
# Set environment to skip signing if no key
189+
if (-not $HasSigningKey) {
190+
$env:TAURI_SIGNING_PRIVATE_KEY = ""
191+
$env:TAURI_SIGNING_PRIVATE_KEY_PATH = ""
192+
}
193+
194+
# Run build with full output
195+
& pnpm tauri build --verbose
196+
197+
if ($LASTEXITCODE -ne 0) {
198+
Write-Error "Tauri build failed with exit code: $LASTEXITCODE"
199+
exit 1
200+
}
201+
Write-Success "NSIS build completed"
202+
} catch {
203+
Write-Error "Failed to build: $($_.Exception.Message)"
182204
exit 1
183205
}
184-
Write-Success "NSIS build completed"
185-
} catch {
186-
Set-Location ".." -ErrorAction SilentlyContinue
187-
Write-Error "Failed to build NSIS: $($_.Exception.Message)"
188-
exit 1
206+
} else {
207+
Write-Info "Skipping build step (using existing artifacts)"
189208
}
190209

191210
# Find the built NSIS installer
192-
$NsisPath = Get-ChildItem -Path "src-tauri\target\x86_64-pc-windows-msvc\release\bundle\nsis" -Filter "*-setup.exe" | Select-Object -First 1
211+
$NsisPath = Get-ChildItem -Path "src-tauri\target\release\bundle\nsis" -Filter "VoiceTypr_${Version}_x64-setup.exe" | Select-Object -First 1
193212
if (-not $NsisPath) {
194213
Write-Error "NSIS installer not found in build output"
195214
exit 1
@@ -220,35 +239,43 @@ $NsisZipSignature = "SIGNATURE_PLACEHOLDER"
220239
if ($HasSigningKey) {
221240
Write-Info "Signing update artifacts..."
222241
try {
223-
Set-Location "src-tauri"
242+
# Get absolute path for the zip file
243+
$zipFullPath = (Get-Item $NsisZipPath).FullName
224244

225-
# Sign the .msi.zip file
226-
$signArgs = @("tauri", "signer", "sign")
245+
# Try multiple approaches to make signing work on Windows
246+
$keyContent = Get-Content $env:TAURI_SIGNING_PRIVATE_KEY_PATH -Raw
227247

228-
if ($env:TAURI_SIGNING_PRIVATE_KEY_PATH) {
229-
$signArgs += @("-f", $env:TAURI_SIGNING_PRIVATE_KEY_PATH)
230-
}
248+
# Approach 1: Use -f flag with key file path (most reliable)
249+
Write-Info "Attempting to sign with: pnpm tauri signer sign -f $keyPath -p '' <file>"
250+
$signOutput = & pnpm tauri signer sign -f $keyPath $zipFullPath 2>&1
231251

232-
# No password for the key
233-
$signArgs += @("-p", "")
234-
235-
$signArgs += $NsisZipPath
252+
if ($LASTEXITCODE -ne 0) {
253+
# Approach 2: Set environment variables (npm version uses TAURI_PRIVATE_KEY)
254+
Write-Warning "Direct signing failed, trying with environment variables..."
255+
$env:TAURI_PRIVATE_KEY = $keyContent
256+
$env:TAURI_PRIVATE_KEY_PATH = $env:TAURI_SIGNING_PRIVATE_KEY_PATH
257+
$env:TAURI_SIGNING_PRIVATE_KEY = $keyContent
258+
259+
$signOutput = & pnpm tauri signer sign $zipFullPath 2>&1
260+
}
236261

237-
$signOutput = & cargo @signArgs 2>&1
238-
Set-Location ".."
262+
if ($LASTEXITCODE -ne 0) {
263+
Write-Error "Failed to sign. Output: $signOutput"
264+
exit 1
265+
}
239266

240267
if ($LASTEXITCODE -eq 0 -and (Test-Path "$NsisZipPath.sig")) {
241268
$NsisZipSignature = Get-Content "$NsisZipPath.sig" -Raw
242269
$NsisZipSignature = $NsisZipSignature.Trim()
243270
Write-Success "Update artifact signed successfully"
244271
} else {
245-
Write-Warning "Failed to sign update artifact. Output: $signOutput"
246-
Write-Warning "Proceeding without signature"
272+
Write-Error "Failed to sign update artifact. Output: $signOutput"
273+
exit 1
247274
}
248275
} catch {
249-
Set-Location ".." -ErrorAction SilentlyContinue
250-
Write-Warning "Error during signing: $($_.Exception.Message)"
251-
Write-Warning "Proceeding without signature"
276+
Set-Location $InitialDir -ErrorAction SilentlyContinue
277+
Write-Error "Error during signing: $($_.Exception.Message)"
278+
exit 1
252279
}
253280
} else {
254281
Write-Warning "Skipping signature generation (no signing key configured)"
@@ -327,26 +354,26 @@ try {
327354
Write-Step "Windows Release Complete!"
328355
Write-Success "Successfully created and uploaded Windows release artifacts for v$Version"
329356
Write-Host ""
330-
Write-Info "📦 Windows Release Artifacts:"
357+
Write-Info "Windows Release Artifacts:"
331358
Get-ChildItem $OutputDir | ForEach-Object {
332359
$size = if ($_.Length -gt 1MB) { "{0:N2} MB" -f ($_.Length / 1MB) } else { "{0:N2} KB" -f ($_.Length / 1KB) }
333360
Write-Host " $($_.Name) ($size)" -ForegroundColor White
334361
}
335362

336363
Write-Host ""
337-
Write-Info "🔗 Release URL: https://github.com/moinulmoin/voicetypr/releases/tag/$ReleaseTag"
364+
Write-Info "Release URL: https://github.com/moinulmoin/voicetypr/releases/tag/$ReleaseTag"
338365

339366
if ($HasSigningKey) {
340-
Write-Success "Update signatures generated - auto-updater ready"
367+
Write-Success "Update signatures generated - auto-updater ready"
341368
} else {
342-
Write-Warning "No update signatures - auto-updater won't work"
369+
Write-Warning "No update signatures - auto-updater won`'t work"
343370
}
344371

345372
Write-Host ""
346-
Write-Info "📋 Next Steps:"
373+
Write-Info "Next Steps:"
347374
Write-Host "1. Test the MSI installer on a clean Windows machine" -ForegroundColor Yellow
348375
Write-Host "2. Verify the Tauri updater works with the new artifacts" -ForegroundColor Yellow
349376
Write-Host "3. Update release notes if needed" -ForegroundColor Yellow
350377
Write-Host "4. Publish the release when ready" -ForegroundColor Yellow
351378

352-
Write-Success "🎉 Windows release process completed successfully!"
379+
Write-Success "Windows release process completed successfully!"

0 commit comments

Comments
 (0)