Flow.Launcher/Scripts/post_build.ps1

137 lines
4.6 KiB
PowerShell
Raw Permalink Normal View History

2017-03-14 20:24:09 +00:00
param(
[string]$config = "Release",
2021-01-04 23:50:19 +00:00
[string]$solution = (Join-Path $PSScriptRoot ".." -Resolve)
2017-03-14 20:24:09 +00:00
)
Write-Host "Config: $config"
2017-03-13 18:07:49 +00:00
function Build-Version {
if ([string]::IsNullOrEmpty($env:flowVersion)) {
2021-01-04 23:50:19 +00:00
$targetPath = Join-Path $solution "Output/Release/Flow.Launcher.dll" -Resolve
$v = (Get-Command ${targetPath}).FileVersionInfo.FileVersion
} else {
2020-05-08 21:19:17 +00:00
$v = $env:flowVersion
2017-03-13 18:07:49 +00:00
}
Write-Host "Build Version: $v"
return $v
}
function Build-Path {
if (![string]::IsNullOrEmpty($env:APPVEYOR_BUILD_FOLDER)) {
2017-03-13 18:07:49 +00:00
$p = $env:APPVEYOR_BUILD_FOLDER
} elseif (![string]::IsNullOrEmpty($solution)) {
$p = $solution
} else {
$p = Get-Location
2017-03-13 18:07:49 +00:00
}
Write-Host "Build Folder: $p"
Set-Location $p
return $p
}
function Copy-Resources ($path) {
# making version static as multiple versions can exist in the nuget folder and in the case a breaking change is introduced.
2025-09-16 04:12:35 +00:00
Copy-Item -Force $env:USERPROFILE\.nuget\packages\squirrel.windows\1.9.0\tools\Squirrel.exe $path\Output\Update.exe
}
function Delete-Unused ($path, $config) {
$target = "$path\Output\$config"
2017-03-30 17:52:49 +00:00
$included = Get-ChildItem $target -Filter "*.dll"
foreach ($i in $included){
$deleteList = Get-ChildItem $target\Plugins -Include $i -Recurse | Where { $_.VersionInfo.FileVersion -eq $i.VersionInfo.FileVersion -And $_.Name -eq "$i" }
2021-01-01 13:09:02 +00:00
$deleteList | ForEach-Object{ Write-Host Deleting duplicated $_.Name with version $_.VersionInfo.FileVersion at location $_.Directory.FullName }
$deleteList | Remove-Item
}
Remove-Item -Path $target -Include "*.xml" -Recurse
}
2021-06-24 04:38:18 +00:00
function Remove-CreateDumpExe ($path, $config) {
$target = "$path\Output\$config"
$depjson = Get-Content $target\Flow.Launcher.deps.json -raw
2021-06-28 04:16:59 +00:00
$depjson -replace '(?s)(.createdump.exe": {.*?}.*?\n)\s*', "" | Out-File $target\Flow.Launcher.deps.json -Encoding UTF8
2021-06-28 03:26:18 +00:00
Remove-Item -Path $target -Include "*createdump.exe" -Recurse
2021-06-24 04:38:18 +00:00
}
2017-03-13 18:07:49 +00:00
function Validate-Directory ($output) {
New-Item $output -ItemType Directory -Force
}
2021-06-24 04:38:18 +00:00
2017-03-13 18:07:49 +00:00
function Pack-Squirrel-Installer ($path, $version, $output) {
# msbuild based installer generation is not working in appveyor, not sure why
Write-Host "Begin pack squirrel installer"
2020-04-21 12:54:41 +00:00
$spec = "$path\Scripts\flowlauncher.nuspec"
2017-03-13 18:07:49 +00:00
$input = "$path\Output\Release"
Write-Host "Packing: $spec"
2017-03-13 18:07:49 +00:00
Write-Host "Input path: $input"
2022-12-08 19:38:13 +00:00
# dotnet pack is not used because ran into issues, need to test installation and starting up if to use it.
nuget pack $spec -Version $version -BasePath $input -OutputDirectory $output -Properties Configuration=Release
2017-03-13 18:07:49 +00:00
2020-05-12 22:33:36 +00:00
$nupkg = "$output\FlowLauncher.$version.nupkg"
2017-03-13 18:07:49 +00:00
Write-Host "nupkg path: $nupkg"
2020-04-21 09:12:17 +00:00
$icon = "$path\Flow.Launcher\Resources\app.ico"
Write-Host "icon: $icon"
2017-03-13 18:07:49 +00:00
# Squirrel.com: https://github.com/Squirrel/Squirrel.Windows/issues/369
2025-09-16 04:12:35 +00:00
New-Alias Squirrel $env:USERPROFILE\.nuget\packages\squirrel.windows\1.9.0\tools\Squirrel.exe -Force
2017-03-13 18:07:49 +00:00
# why we need Write-Output: https://github.com/Squirrel/Squirrel.Windows/issues/489#issuecomment-156039327
# directory of releaseDir in squirrel can't be same as directory ($nupkg) in releasify
2017-03-13 18:07:49 +00:00
$temp = "$output\Temp"
Squirrel --releasify $nupkg --releaseDir $temp --setupIcon $icon --no-msi | Write-Output
2017-03-13 18:07:49 +00:00
Move-Item $temp\* $output -Force
Remove-Item $temp
$file = "$output\Flow-Launcher-Setup.exe"
2017-03-13 18:07:49 +00:00
Write-Host "Filename: $file"
Move-Item "$output\Setup.exe" $file -Force
Write-Host "End pack squirrel installer"
}
2021-01-04 23:50:19 +00:00
function Publish-Self-Contained ($p) {
2021-01-04 23:50:19 +00:00
$csproj = Join-Path "$p" "Flow.Launcher/Flow.Launcher.csproj" -Resolve
2025-02-26 14:46:08 +00:00
$profile = Join-Path "$p" "Flow.Launcher/Properties/PublishProfiles/Net9.0-SelfContained.pubxml" -Resolve
2021-01-04 23:50:19 +00:00
# we call dotnet publish on the main project.
# The other projects should have been built in Release at this point.
dotnet publish -c Release $csproj /p:PublishProfile=$profile
}
2021-07-24 08:08:25 +00:00
function Publish-Portable ($outputLocation, $version) {
& $outputLocation\Flow-Launcher-Setup.exe --silent | Out-Null
2021-07-24 08:08:25 +00:00
mkdir "$env:LocalAppData\FlowLauncher\app-$version\UserData"
Compress-Archive -Path $env:LocalAppData\FlowLauncher -DestinationPath $outputLocation\Flow-Launcher-Portable.zip
2021-07-24 08:08:25 +00:00
}
2017-03-13 18:07:49 +00:00
function Main {
$p = Build-Path
$v = Build-Version
Copy-Resources $p
2017-03-13 18:07:49 +00:00
if ($config -eq "Release"){
Delete-Unused $p $config
2021-01-04 23:50:19 +00:00
Publish-Self-Contained $p
2021-06-24 04:38:18 +00:00
Remove-CreateDumpExe $p $config
$o = "$p\Output\Packages"
Validate-Directory $o
Pack-Squirrel-Installer $p $v $o
2021-07-24 08:08:25 +00:00
Publish-Portable $o $v
2017-03-13 18:07:49 +00:00
}
}
Main