Last active
June 10, 2020 22:19
-
-
Save tygor/b75130f1904ae9cc5adc771ce958e398 to your computer and use it in GitHub Desktop.
Squirrel.Windows Powershell Releasify script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Packs and deploys a Squirrel.Windows app | |
.DESCRIPTION | |
Nuget Pack and Squirrel.Windows Releasify. The parameters taken will then run the --signWithParams flag which signs your executables with the given certificate. | |
.EXAMPLE | |
Deploy-SquirrelApp -NuSpec C:\Temp\MyApp.nuspec -OutputDir .\bin\Release\ -ReleaseDir C:\Network\Folder\ -CertificatePath .\Certificate.pfx | |
#> | |
function Deploy-SquirrelApp { | |
[CmdletBinding()] | |
[Alias()] | |
[OutputType([int])] | |
Param | |
( | |
# Location of the NuGet .NUSPEC file | |
[Parameter(Mandatory = $true)] | |
[ValidateScript({Test-Path $_ -PathType 'Leaf'})] | |
[string] | |
$NuSpec, | |
# Build path | |
[Parameter(Mandatory = $true)] | |
[ValidateScript({Test-Path $_ -PathType 'Container'})] | |
[string] | |
$OutputDir, | |
# Release path | |
[Parameter(Mandatory = $true)] | |
[ValidateScript({Test-Path $_ -PathType 'Container'})] | |
[string] | |
$ReleaseDir, | |
# The certificate file location | |
[Parameter(Mandatory = $true)] | |
[ValidateScript({Test-Path $_ -PathType 'Leaf'})] | |
[string] | |
$CertificatePath, | |
# The certificate password | |
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | |
[Security.SecureString] | |
${Type your secret password} | |
) | |
Process { | |
# Get the typed password as plain text | |
$SecretPassword = ${Type your secret password} | |
$marshal = [Runtime.InteropServices.Marshal] | |
$PlainTextPassword = $marshal::PtrToStringAuto( $marshal::SecureStringToBSTR($SecretPassword) ) | |
# Read the NuSpec file (likely passed in via parameter) | |
[xml]$SpecData = Get-Content $NuSpec | |
# Find the last NUPKG and pull out the version number | |
$PackagePath = Join-Path $OutputDir "*.nupkg" | Get-ChildItem | Select-Object -Last 1 | |
$VersionArray = $PackagePath.Name.Split(".") | Select-Object -Skip 1 -First 3 | |
$Version = $VersionArray -join '.' | |
# Command 1: Nuget pack | |
& nuget pack $NuSpec -Version $Version -Properties Configuration=Release -OutputDirectory $OutputDir -BasePath $OutputDir | Out-Null | |
# Command 2: Squirrel releasify | |
$nugetPath = Join-Path $env:USERPROFILE ".nuget\packages" | |
$squirrelPath = Join-Path $nugetPath "squirrel.windows\*\tools\Squirrel.exe" | Convert-Path | Select-Object -Last 1 | |
& $squirrelPath --releasify $PackagePath --releaseDir $ReleaseDir --signWithParams "/a /fd sha256 /tr http://timestamp.digicert.com /td sha256 /f $CertificatePath /p '$PlainTextPassword'" | Out-Null | |
# Fin | |
Write-Output @" | |
----------------------------------------- | |
______ _ _ _ _ | |
| ____(_) (_) | | | | | |
| |__ _ _ __ _ ___| |__ ___ __| | | |
| __| | | '_ \| / __| '_ \ / _ \/ _` | | |
| | | | | | | \__ \ | | | __/ (_| | | |
|_| |_|_| |_|_|___/_| |_|\___|\__,_| | |
"@ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment