2017-03-14 20:24:09 +00:00
param (
[ string ] $config = " Release " ,
2020-04-01 11:20:33 +00:00
[ string ] $solution ,
2020-05-11 16:49:39 +00:00
[ string ] $targetpath
2017-03-14 20:24:09 +00:00
)
Write-Host " Config: $config "
2017-03-14 02:10:07 +00:00
2017-03-13 18:07:49 +00:00
function Build-Version {
2020-05-11 16:49:39 +00:00
if ( [ string ] :: IsNullOrEmpty ( $env:flowVersion ) ) {
$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 {
2017-03-14 02:10:07 +00:00
if ( ! [ string ] :: IsNullOrEmpty ( $env:APPVEYOR_BUILD_FOLDER ) ) {
2017-03-13 18:07:49 +00:00
$p = $env:APPVEYOR_BUILD_FOLDER
2017-03-14 02:10:07 +00:00
} 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
}
2017-03-14 02:10:07 +00:00
function Copy-Resources ( $path , $config ) {
2020-04-21 09:12:17 +00:00
$project = " $path \Flow.Launcher "
2017-03-14 02:10:07 +00:00
$output = " $path \Output "
$target = " $output \ $config "
Copy-Item -Recurse -Force $project \ Images \ * $target \ Images \
Copy-Item -Recurse -Force $path \ JsonRPC $target \ JsonRPC
2020-03-27 08:13:22 +00:00
# making version static as multiple versions can exist in the nuget folder and in the case a breaking change is introduced.
2020-04-08 08:51:35 +00:00
Copy-Item -Force $env:USERPROFILE \ . nuget \ packages \ squirrel . windows \ 1.5 . 2 \ tools \ Squirrel . exe $output \ Update . exe
2017-03-14 02:10:07 +00:00
}
function Delete-Unused ( $path , $config ) {
$target = " $path \Output\ $config "
2017-03-30 17:52:49 +00:00
$included = Get-ChildItem $target -Filter " *.dll "
2017-03-14 02:10:07 +00:00
foreach ( $i in $included ) {
Remove-Item -Path $target \ Plugins -Include $i -Recurse
2017-03-30 17:52:49 +00:00
Write-Host " Deleting duplicated $i "
2017-03-14 02:10:07 +00:00
}
Remove-Item -Path $target -Include " *.xml " -Recurse
}
2017-03-13 18:07:49 +00:00
function Validate-Directory ( $output ) {
New-Item $output -ItemType Directory -Force
}
function Zip-Release ( $path , $version , $output ) {
Write-Host " Begin zip release "
2020-05-01 19:24:28 +00:00
$content = " $path \Output\Release\* "
2020-05-08 21:15:54 +00:00
$zipFile = " $output \Flow-Launcher-v $version .zip "
2017-03-13 18:07:49 +00:00
2020-05-01 19:24:28 +00:00
Compress-Archive -Force -Path $content -DestinationPath $zipFile
2017-03-13 18:07:49 +00:00
Write-Host " End zip release "
}
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 "
2020-05-01 19:24:28 +00:00
Write-Host " Packing: $spec "
2017-03-13 18:07:49 +00:00
Write-Host " Input path: $input "
2020-05-01 19:24:28 +00:00
# TODO: can we use dotnet pack here?
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 "
2017-03-14 02:10:07 +00:00
Write-Host " icon: $icon "
2017-03-13 18:07:49 +00:00
# Squirrel.com: https://github.com/Squirrel/Squirrel.Windows/issues/369
2020-04-08 08:51:35 +00:00
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
2020-03-27 08:13:22 +00:00
# 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 "
2017-03-14 02:10:07 +00:00
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 "
}
2020-04-10 11:39:50 +00:00
function IsDotNetCoreAppSelfContainedPublishEvent {
return Test-Path $solution \ Output \ Release \ coreclr . dll
}
function FixPublishLastWriteDateTimeError ( $solutionPath ) {
#Fix error from publishing self contained app, when nuget tries to pack core dll references throws the error 'The DateTimeOffset specified cannot be converted into a Zip file timestamp'
gci -path " $solutionPath \Output\Release " -rec -file * . dll | Where-Object { $_ . LastWriteTime -lt ( Get-Date ) . AddYears ( -20 ) } | % { try { $_ . LastWriteTime = '01/01/2000 00:00:00' } catch { } }
}
2017-03-13 18:07:49 +00:00
function Main {
$p = Build-Path
2017-03-14 02:10:07 +00:00
$v = Build-Version
Copy-Resources $p $config
2017-03-13 18:07:49 +00:00
2017-03-14 02:10:07 +00:00
if ( $config -eq " Release " ) {
2020-04-10 11:39:50 +00:00
if ( IsDotNetCoreAppSelfContainedPublishEvent ) {
FixPublishLastWriteDateTimeError $p
2020-05-11 16:49:39 +00:00
}
2020-04-10 11:39:50 +00:00
2017-03-14 02:10:07 +00:00
Delete-Unused $p $config
$o = " $p \Output\Packages "
Validate-Directory $o
2020-05-21 03:31:24 +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
2017-03-14 02:10:07 +00:00
Pack-Squirrel -Installer $p $v $o
2017-03-13 18:07:49 +00:00
2017-03-14 02:10:07 +00:00
$isInCI = $env:APPVEYOR
if ( $isInCI ) {
Zip-Release $p $v $o
}
Write-Host " List output directory "
Get-ChildItem $o
2017-03-13 18:07:49 +00:00
}
}
Main