Package-Windows.ps1 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [CmdletBinding()]
  2. param(
  3. [ValidateSet('x64')]
  4. [string] $Target = 'x64',
  5. [ValidateSet('Debug', 'RelWithDebInfo', 'Release', 'MinSizeRel')]
  6. [string] $Configuration = 'RelWithDebInfo'
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. if ( $DebugPreference -eq 'Continue' ) {
  10. $VerbosePreference = 'Continue'
  11. $InformationPreference = 'Continue'
  12. }
  13. if ( $env:CI -eq $null ) {
  14. throw "Package-Windows.ps1 requires CI environment"
  15. }
  16. if ( ! ( [System.Environment]::Is64BitOperatingSystem ) ) {
  17. throw "Packaging script requires a 64-bit system to build and run."
  18. }
  19. if ( $PSVersionTable.PSVersion -lt '7.2.0' ) {
  20. Write-Warning 'The packaging script requires PowerShell Core 7. Install or upgrade your PowerShell version: https://aka.ms/pscore6'
  21. exit 2
  22. }
  23. function Package {
  24. trap {
  25. Write-Error $_
  26. exit 2
  27. }
  28. $ScriptHome = $PSScriptRoot
  29. $ProjectRoot = Resolve-Path -Path "$PSScriptRoot/../.."
  30. $BuildSpecFile = "${ProjectRoot}/buildspec.json"
  31. $UtilityFunctions = Get-ChildItem -Path $PSScriptRoot/utils.pwsh/*.ps1 -Recurse
  32. foreach( $Utility in $UtilityFunctions ) {
  33. Write-Debug "Loading $($Utility.FullName)"
  34. . $Utility.FullName
  35. }
  36. $BuildSpec = Get-Content -Path ${BuildSpecFile} -Raw | ConvertFrom-Json
  37. $ProductName = $BuildSpec.name
  38. $ProductVersion = $BuildSpec.version
  39. $OutputName = "${ProductName}-${ProductVersion}-windows-${Target}"
  40. $RemoveArgs = @{
  41. ErrorAction = 'SilentlyContinue'
  42. Path = @(
  43. "${ProjectRoot}/release/${ProductName}-*-windows-*.zip"
  44. )
  45. }
  46. Remove-Item @RemoveArgs
  47. Log-Group "Archiving ${ProductName}..."
  48. $CompressArgs = @{
  49. Path = (Get-ChildItem -Path "${ProjectRoot}/release/${Configuration}" -Exclude "${OutputName}*.*")
  50. CompressionLevel = 'Optimal'
  51. DestinationPath = "${ProjectRoot}/release/${OutputName}.zip"
  52. Verbose = ($Env:CI -ne $null)
  53. }
  54. Compress-Archive -Force @CompressArgs
  55. Log-Group
  56. }
  57. Package