mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 19:44:44 +00:00
* feat: Add Windows package manager publishing infrastructure (#343) - Add comprehensive release build scripts: - build-release.ps1: Creates portable ZIP + SHA256 checksums - build-exe.ps1: Standalone executable builder (PS2EXE) - build-msi.ps1: MSI installer builder (WiX Toolset) - Add GitHub Actions workflow: - Automated builds on version tags - Runs tests before building - Auto-creates GitHub releases with artifacts - Add package manager manifests: - WinGet: Complete manifests ready for microsoft/winget-pkgs - Chocolatey: Full package with install/uninstall scripts - Scoop: JSON manifest ready for submission - Add comprehensive documentation: - RELEASE.md: Complete guide for building and publishing - Package-specific READMEs with submission instructions - ISSUE-343-SUMMARY.md: Quick reference and next steps Successfully tested: Built mole-1.0.0-x64.zip (5 MB) with SHA256 checksums Addresses #343 * chore: update contributors [skip ci] * fix: Support uppercase V and -windows suffix in release workflow * fix: Remove duplicate parameter definitions in clean, optimize, and purge commands - bin/clean.ps1: Remove duplicate System, GameMedia, DebugMode, Whitelist params - bin/optimize.ps1: Remove duplicate DebugMode param - bin/purge.ps1: Remove duplicate DebugMode and Paths params These duplicates were causing parser errors in tests. * fix: Update test regex to match --dry-run format in help text The help output shows --dry-run (kebab-case) but test was checking for DryRun (PascalCase). Updated regex to accept both formats. * fix: Handle Pester 5.x result object properties correctly Pester 5.x uses different property names (Passed.Count, Failed.Count) instead of PassedCount, FailedCount. Added fallback logic to support both formats. * fix: Simplify Pester result parsing with better fallback logic Since Pester already prints test results, just check for failures and assume success if we can't parse the result object. This handles different Pester versions more gracefully. * feat: Add MSI and EXE builds to release workflow - Install WiX Toolset for MSI creation - Install PS2EXE module for standalone EXE - Build all three formats: ZIP, MSI, EXE - MSI and EXE builds marked optional (continue-on-error) - Upload all artifacts to GitHub release - Update release notes with installation instructions for all formats - Add SHA256 verification instructions for each format * fix: Resolve MSI and EXE build failures MSI build fix: - Use UTF8 without BOM for temp WXS file to avoid XML parsing errors - WiX compiler requires clean UTF8 encoding without byte order mark EXE build fix: - Remove hashtable iteration that modified collection during enumeration - Exclude null iconFile parameter from ps2exe params instead of removing it - Prevents 'Collection was modified' exception * fix: Properly handle encoding and version format for MSI and EXE builds MSI fix: - Use System.IO.File.ReadAllText/WriteAllText for consistent UTF8 without BOM - Prevents XML parsing errors in WiX compiler EXE fix: - Extract numeric version only (strip '-windows' suffix) for ps2exe - ps2exe requires version in format n.n.n.n (numeric only) - Fallback to 1.0.0.0 if version parsing fails * fix: Use WriteAllBytes to ensure no BOM in MSI WXS file - Convert string to UTF8 bytes manually - Write bytes directly to file - This guarantees no byte order mark is added - Prevents WiX XML parsing error at position 7 * fix: Read WXS source as bytes to completely avoid BOM issues - Read source file as raw bytes - Convert bytes to string using UTF8Encoding without BOM - Replace version in string - Convert back to bytes and write - This completely avoids PowerShell's Get-Content BOM handling * chore: Simplify release workflow - remove MSI build, minimal release notes - Remove MSI build steps (has persistent BOM/encoding issues) - Remove WiX Toolset installation - Simplify release notes to bare minimum - Focus on ZIP and EXE artifacts only --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
285 lines
8.8 KiB
PowerShell
285 lines
8.8 KiB
PowerShell
# Mole Windows - MSI Installer Builder
|
|
# Creates Windows Installer (.msi) package using WiX Toolset
|
|
# Requires: WiX Toolset v3 or v4 (https://wixtoolset.org/)
|
|
|
|
#Requires -Version 5.1
|
|
param(
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$Version,
|
|
|
|
[switch]$ShowHelp
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Set-StrictMode -Version Latest
|
|
|
|
# ============================================================================
|
|
# Configuration
|
|
# ============================================================================
|
|
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$projectRoot = Split-Path -Parent $scriptDir
|
|
$releaseDir = Join-Path $projectRoot "release"
|
|
$wixSource = Join-Path $scriptDir "mole-installer.wxs"
|
|
|
|
# Read version from mole.ps1 if not provided
|
|
if (-not $Version) {
|
|
$moleScript = Join-Path $projectRoot "mole.ps1"
|
|
$content = Get-Content $moleScript -Raw
|
|
if ($content -match '\$script:MOLE_VER\s*=\s*"([^"]+)"') {
|
|
$Version = $Matches[1]
|
|
} else {
|
|
Write-Host "Error: Could not detect version from mole.ps1" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
$msiName = "mole-$Version-x64.msi"
|
|
$msiPath = Join-Path $releaseDir $msiName
|
|
$wixObjPath = Join-Path $releaseDir "mole-installer.wixobj"
|
|
|
|
# ============================================================================
|
|
# Help
|
|
# ============================================================================
|
|
|
|
function Show-BuildHelp {
|
|
Write-Host ""
|
|
Write-Host "Mole Windows MSI Builder" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Usage: .\build-msi.ps1 [-Version <version>]"
|
|
Write-Host ""
|
|
Write-Host "Requirements:"
|
|
Write-Host " WiX Toolset v3 or v4: https://wixtoolset.org/releases/" -ForegroundColor Gray
|
|
Write-Host " Add WiX bin directory to PATH" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "Options:"
|
|
Write-Host " -Version <ver> Specify version (default: auto-detect)"
|
|
Write-Host " -ShowHelp Show this help message"
|
|
Write-Host ""
|
|
}
|
|
|
|
if ($ShowHelp) {
|
|
Show-BuildHelp
|
|
exit 0
|
|
}
|
|
|
|
# ============================================================================
|
|
# Banner
|
|
# ============================================================================
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " Mole - MSI Installer Builder" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Version: $Version" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# ============================================================================
|
|
# Check Dependencies
|
|
# ============================================================================
|
|
|
|
Write-Host "[1/5] Checking dependencies..." -ForegroundColor Cyan
|
|
|
|
# Check if WiX is installed
|
|
$wixInstalled = $false
|
|
$candleCmd = $null
|
|
$lightCmd = $null
|
|
|
|
# Try to find WiX executables
|
|
$wixPaths = @(
|
|
"${env:ProgramFiles(x86)}\WiX Toolset v3.11\bin",
|
|
"${env:ProgramFiles}\WiX Toolset v3.11\bin",
|
|
"${env:ProgramFiles(x86)}\WiX Toolset v4\bin",
|
|
"${env:ProgramFiles}\WiX Toolset v4\bin"
|
|
)
|
|
|
|
foreach ($path in $wixPaths) {
|
|
if (Test-Path "$path\candle.exe") {
|
|
$candleCmd = "$path\candle.exe"
|
|
$lightCmd = "$path\light.exe"
|
|
$wixInstalled = $true
|
|
break
|
|
}
|
|
}
|
|
|
|
# Check PATH as fallback
|
|
if (-not $wixInstalled) {
|
|
try {
|
|
$null = & candle.exe -? 2>&1
|
|
if ($LASTEXITCODE -eq 0 -or $LASTEXITCODE -eq 104) {
|
|
$candleCmd = "candle.exe"
|
|
$lightCmd = "light.exe"
|
|
$wixInstalled = $true
|
|
}
|
|
} catch {
|
|
# Not in PATH
|
|
}
|
|
}
|
|
|
|
if (-not $wixInstalled) {
|
|
Write-Host " Error: WiX Toolset not found" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host " Install WiX Toolset:" -ForegroundColor Yellow
|
|
Write-Host " https://wixtoolset.org/releases/" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host " Or use Chocolatey:" -ForegroundColor Yellow
|
|
Write-Host " choco install wixtoolset" -ForegroundColor Gray
|
|
Write-Host ""
|
|
exit 1
|
|
}
|
|
|
|
Write-Host " WiX Toolset: OK" -ForegroundColor Green
|
|
Write-Host " candle: $candleCmd" -ForegroundColor Gray
|
|
Write-Host " light: $lightCmd" -ForegroundColor Gray
|
|
|
|
# Check if source WXS file exists
|
|
if (-not (Test-Path $wixSource)) {
|
|
Write-Host " Error: WiX source file not found: $wixSource" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
Write-Host " WiX source: OK" -ForegroundColor Green
|
|
|
|
# Ensure release directory exists
|
|
if (-not (Test-Path $releaseDir)) {
|
|
New-Item -ItemType Directory -Path $releaseDir -Force | Out-Null
|
|
}
|
|
|
|
Write-Host ""
|
|
|
|
# ============================================================================
|
|
# Update WXS Version
|
|
# ============================================================================
|
|
|
|
Write-Host "[2/5] Updating installer version..." -ForegroundColor Cyan
|
|
|
|
# Read source file as bytes to avoid any encoding issues
|
|
$sourceBytes = [System.IO.File]::ReadAllBytes($wixSource)
|
|
# Convert to string using UTF8 without BOM
|
|
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
|
$wixContent = $utf8NoBom.GetString($sourceBytes)
|
|
|
|
# Replace version
|
|
$wixContent = $wixContent -replace 'Version="[^"]+"', "Version=`"$Version`""
|
|
|
|
# Write back as bytes without BOM
|
|
$tempWxs = Join-Path $releaseDir "mole-installer-temp.wxs"
|
|
$outputBytes = $utf8NoBom.GetBytes($wixContent)
|
|
[System.IO.File]::WriteAllBytes($tempWxs, $outputBytes)
|
|
|
|
Write-Host " Version set to: $Version" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# ============================================================================
|
|
# Compile WXS to WIXOBJ
|
|
# ============================================================================
|
|
|
|
Write-Host "[3/5] Compiling WiX source..." -ForegroundColor Cyan
|
|
|
|
Push-Location $projectRoot
|
|
try {
|
|
$candleArgs = @(
|
|
$tempWxs,
|
|
"-out", $wixObjPath,
|
|
"-arch", "x64",
|
|
"-ext", "WixUIExtension"
|
|
)
|
|
|
|
Write-Host " Running candle.exe..." -ForegroundColor Gray
|
|
& $candleCmd $candleArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " Compilation failed" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host " Compiled: mole-installer.wixobj" -ForegroundColor Green
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
Write-Host ""
|
|
|
|
# ============================================================================
|
|
# Link WIXOBJ to MSI
|
|
# ============================================================================
|
|
|
|
Write-Host "[4/5] Linking installer package..." -ForegroundColor Cyan
|
|
|
|
Push-Location $projectRoot
|
|
try {
|
|
$lightArgs = @(
|
|
$wixObjPath,
|
|
"-out", $msiPath,
|
|
"-ext", "WixUIExtension",
|
|
"-cultures:en-US",
|
|
"-loc", "en-US"
|
|
)
|
|
|
|
Write-Host " Running light.exe..." -ForegroundColor Gray
|
|
& $lightCmd $lightArgs
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host " Linking failed" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
if (Test-Path $msiPath) {
|
|
$msiSize = (Get-Item $msiPath).Length / 1MB
|
|
Write-Host " Created: $msiName ($([math]::Round($msiSize, 2)) MB)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " Error: MSI was not created" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|
|
Write-Host ""
|
|
|
|
# ============================================================================
|
|
# Update Checksums
|
|
# ============================================================================
|
|
|
|
Write-Host "[5/5] Updating checksums..." -ForegroundColor Cyan
|
|
|
|
$hashFile = Join-Path $releaseDir "SHA256SUMS.txt"
|
|
$msiHash = (Get-FileHash $msiPath -Algorithm SHA256).Hash.ToLower()
|
|
|
|
# Append to existing hash file
|
|
$hashLine = "$msiHash $msiName"
|
|
if (Test-Path $hashFile) {
|
|
Add-Content -Path $hashFile -Value $hashLine -Encoding UTF8
|
|
} else {
|
|
Set-Content -Path $hashFile -Value $hashLine -Encoding UTF8
|
|
}
|
|
|
|
Write-Host " $msiName" -ForegroundColor Gray
|
|
Write-Host " SHA256: $msiHash" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
# Cleanup temp files
|
|
if (Test-Path $tempWxs) { Remove-Item $tempWxs -Force }
|
|
if (Test-Path $wixObjPath) { Remove-Item $wixObjPath -Force }
|
|
if (Test-Path "$releaseDir\mole-installer.wixpdb") {
|
|
Remove-Item "$releaseDir\mole-installer.wixpdb" -Force
|
|
}
|
|
|
|
# ============================================================================
|
|
# Summary
|
|
# ============================================================================
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " Build Complete!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "MSI installer created:" -ForegroundColor Yellow
|
|
Write-Host " $msiPath" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "Test installation:" -ForegroundColor Cyan
|
|
Write-Host " msiexec /i `"$msiPath`" /qn" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "Test with UI:" -ForegroundColor Cyan
|
|
Write-Host " msiexec /i `"$msiPath`"" -ForegroundColor Gray
|
|
Write-Host ""
|