Flow.Launcher/Scripts/post_build.ps1

140 lines
4.8 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.
Copy-Item -Force $env:USERPROFILE\.nuget\packages\squirrel.windows\1.5.2\tools\Squirrel.exe $path\Output\Update.exe
}
function Delete-Unused ($path, $config) {
$target = "$path\Output\$config"
$included = @{}
Get-ChildItem $target -Filter "*.dll" | Get-FileHash | ForEach-Object { $included.Add($_.hash, $true) }
$deleteList = Get-ChildItem $target\Plugins -Filter "*.dll" -Recurse |
Select-Object Name, VersionInfo, Directory, FullName, @{name = "hash"; expression = { (Get-FileHash $_.FullName).hash } } |
Where-Object { $included.Contains($_.hash) }
$deleteList | ForEach-Object {
Write-Host Deleting duplicated $_.Name with version $_.VersionInfo.FileVersion at location $_.Directory.FullName
}
$deleteList | Remove-Item -Path {$_.FullName}
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 |ConvertFrom-Json -depth 32
$depjson.targets.'.NETCoreApp,Version=v5.0/win-x64'.'runtimepack.Microsoft.NETCore.App.Runtime.win-x64/5.0.6'.native.PSObject.Properties.Remove("createdump.exe")
$depjson|ConvertTo-Json -Depth 32|Out-File $target\Flow.Launcher.deps.json
Remove-Item -Path $target -Include "*createdump.exe" -Recurse
}
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"
2021-01-04 23:50:19 +00:00
# making version static as multiple versions can exist in the nuget folder and in the case a breaking change is introduced.
New-Alias Nuget $env:USERPROFILE\.nuget\packages\NuGet.CommandLine\5.4.0\tools\NuGet.exe -Force
2021-06-17 10:59:15 +00:00
dotnet pack "$path\Flow.Launcher\Flow.Launcher.csproj" -p:NuspecFile=$spec -p:NuspecBasePath="$path\Output\Release" -p:PackageVersion=$version -c Release --no-build --output $output
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
New-Alias Squirrel $env:USERPROFILE\.nuget\packages\squirrel.windows\1.5.2\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
2020-05-08 21:15:54 +00:00
$file = "$output\Flow-Launcher-v$version.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) {
$csproj = Join-Path "$p" "Flow.Launcher/Flow.Launcher.csproj" -Resolve
2021-02-11 19:17:13 +00:00
$profile = Join-Path "$p" "Flow.Launcher/Properties/PublishProfiles/Net5.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.
2021-06-17 10:59:15 +00:00
2021-06-17 13:51:22 +00:00
dotnet publish -c Release $csproj /p:PublishProfile=$profile
}
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
2017-03-13 18:07:49 +00:00
}
}
Main