Flow.Launcher/Scripts/post_build.ps1

155 lines
4.2 KiB
PowerShell
Raw Normal View History

2017-03-14 20:24:09 +00:00
param(
2024-03-24 18:41:07 +00:00
[string]$config = "Release",
[string]$solution = (Join-Path $PSScriptRoot ".." -Resolve),
2024-03-24 18:52:05 +00:00
[string]$channel = "win-x64-prerelease"
2017-03-14 20:24:09 +00:00
)
Write-Host "Config: $config"
2024-03-24 18:52:05 +00:00
Write-Host "Solution: $solution"
Write-Host "Channel: $channel"
2024-03-24 18:41:07 +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
2024-03-24 18:41:07 +00:00
}
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
}
2024-03-24 18:41:07 +00:00
function Build-Path
{
if (![string]::IsNullOrEmpty($env:APPVEYOR_BUILD_FOLDER))
{
2017-03-13 18:07:49 +00:00
$p = $env:APPVEYOR_BUILD_FOLDER
2024-03-24 18:41:07 +00:00
}
elseif (![string]::IsNullOrEmpty($solution))
{
$p = $solution
2024-03-24 18:41:07 +00:00
}
else
{
$p = Get-Location
2017-03-13 18:07:49 +00:00
}
Write-Host "Build Folder: $p"
Set-Location $p
return $p
}
2024-03-24 18:41:07 +00:00
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.
Copy-Item -Force $env:USERPROFILE\.nuget\packages\squirrel.windows\1.5.2\tools\Squirrel.exe $path\Output\Update.exe
}
2024-03-24 18:41:07 +00:00
function Delete-Unused($path, $config)
{
$target = "$path\Output\$config"
2024-03-24 18:41:07 +00:00
$included = @{ }
Get-ChildItem $target -Filter "*.dll" | Get-FileHash | ForEach-Object {
$hash = $_.hash
$filename = $_.Path | Split-Path -Leaf
$included.Add([tuple]::Create($filename, $hash), $true)
}
$deleteList = Get-ChildItem $target\Plugins -Filter "*.dll" -Recurse |
Select-Object Name, VersionInfo, Directory, @{ name = "hash"; expression = { (Get-FileHash $_.FullName) } } |
Where-Object {
$included.Contains([tuple]::Create($_.Name, $_.hash))
}
$deleteList | ForEach-Object {
Write-Host Deleting duplicated $_.Name with version $_.VersionInfo.FileVersion at location $_.Directory.FullName
}
2024-03-24 18:41:07 +00:00
$deleteList | Remove-Item -Path { $_.FullName }
Remove-Item -Path $target -Include "*.xml" -Recurse
}
2024-03-24 18:41:07 +00:00
function Remove-CreateDumpExe($path, $config)
{
2021-06-24 04:38:18 +00:00
$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
}
2024-03-24 18:41:07 +00:00
function Validate-Directory($output)
{
2017-03-13 18:07:49 +00:00
New-Item $output -ItemType Directory -Force
}
2021-06-24 04:38:18 +00:00
2024-03-24 18:41:07 +00:00
function Pack-Squirrel-Installer($path, $version, $output)
{
2017-03-13 18:07:49 +00:00
# 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
2024-03-24 18:41:07 +00:00
$repoUrl = "https://github.com/Flow-Launcher/Prereleases"
2017-03-13 18:07:49 +00:00
2024-03-24 18:41:07 +00:00
if ($channel -eq "stable")
{
$repoUrl = "https://github.com/Flow-Launcher/Flow.Launcher"
}
vpk pack --packVersion $version --packDir $input --packId FlowLauncher --mainExe Flow.Launcher.exe --channel $channel
2017-03-13 18:07:49 +00:00
}
2024-03-24 18:41:07 +00:00
function Publish-Self-Contained($p)
{
2024-03-24 18:41:07 +00:00
$csproj = Join-Path "$p" "Flow.Launcher/Flow.Launcher.csproj" -Resolve
2022-12-31 02:38:39 +00:00
$profile = Join-Path "$p" "Flow.Launcher/Properties/PublishProfiles/Net7.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
}
2024-03-24 18:41:07 +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
}
2024-03-24 18:41:07 +00:00
function Main
{
2017-03-13 18:07:49 +00:00
$p = Build-Path
$v = Build-Version
Copy-Resources $p
2017-03-13 18:07:49 +00:00
2024-03-24 18:41:07 +00:00
if ($config -eq "Release")
{
Delete-Unused $p $config
2021-01-04 23:50:19 +00:00
Publish-Self-Contained $p
$o = "$p\Output\Packages"
Validate-Directory $o
Pack-Squirrel-Installer $p $v $o
2021-07-24 08:08:25 +00:00
2024-03-24 18:41:07 +00:00
# Publish-Portable $o $v
2017-03-13 18:07:49 +00:00
}
}
Main