From 4070d51ee1dd55164b2106cda9b7ca03215362eb Mon Sep 17 00:00:00 2001 From: Klaudia Algiz Date: Thu, 17 May 2018 19:04:20 -0700 Subject: [PATCH] Add functions into build.psm1 to Save and Restore PSOptions between different sessions. (#6884) Add functions into build.psm1 to Save and Restore PSOptions between different sessions. --- build.psm1 | 39 ++++++++++++++++++++++++++++ tools/packaging/packaging.psm1 | 8 +++--- tools/releaseBuild/setReleaseTag.ps1 | 1 + 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/build.psm1 b/build.psm1 index ccfea6296a..6eeb7f4600 100644 --- a/build.psm1 +++ b/build.psm1 @@ -2808,6 +2808,45 @@ assembly } } +# Save PSOptions to be restored by Restore-PSOptions +function Save-PSOptions { + param( + [ValidateScript({$parent = Split-Path $_;if($parent){Test-Path $parent}else{return $true}})] + [ValidateNotNullOrEmpty()] + [string] + $PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'), + + [ValidateNotNullOrEmpty()] + [object] + $Options = (Get-PSOptions -DefaultToNew) + ) + + $Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath $PSOptionsPath +} + +# Restore PSOptions +# Optionally remove the PSOptions file +function Restore-PSOptions { + param( + [ValidateScript({Test-Path $_})] + [string] + $PSOptionsPath = (Join-Path -Path $PSScriptRoot -ChildPath 'psoptions.json'), + [switch] + $Remove + ) + + $options = Get-Content -Path $PSOptionsPath | ConvertFrom-Json + + if($Remove) + { + # Remove PSOptions. + # The file is only used to set the PSOptions. + Remove-Item -Path $psOptionsPath + } + + Set-PSOptions -Options $options +} + $script:RESX_TEMPLATE = @' diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index cfa57653cd..fd4efda2fe 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -180,7 +180,7 @@ function Start-PSPackage { # Zip symbols.zip to the root package $zipSource = Join-Path $symbolsSource -ChildPath '*' $zipPath = Join-Path -Path $Source -ChildPath 'symbols.zip' - $Script:Options | ConvertTo-Json -Depth 3 | Out-File -Encoding utf8 -FilePath (Join-Path -Path $source -ChildPath 'psoptions.json') + Save-PSOptions -PSOptionsPath (Join-Path -Path $source -ChildPath 'psoptions.json') -Options $Script:Options Compress-Archive -Path $zipSource -DestinationPath $zipPath } finally @@ -493,11 +493,9 @@ function Expand-PSSignedBuild Restore-PSModuleToBuild -PublishPath $buildPath $psOptionsPath = Join-Path $buildPath -ChildPath 'psoptions.json' - $options = Get-Content -Path $psOptionsPath | ConvertFrom-Json + Restore-PSOptions -PSOptionsPath $psOptionsPath -Remove - # Remove PSOptions. - # The file is only used to set the PSOptions. - Remove-Item -Path $psOptionsPath + $options = Get-PSOptions $options.PSModuleRestore = $true diff --git a/tools/releaseBuild/setReleaseTag.ps1 b/tools/releaseBuild/setReleaseTag.ps1 index ef45c87bad..61e4aee2df 100644 --- a/tools/releaseBuild/setReleaseTag.ps1 +++ b/tools/releaseBuild/setReleaseTag.ps1 @@ -14,6 +14,7 @@ param( # VSTS passes it as 'refs/heads/release-v6.0.2' $branchOnly = $Branch -replace '^refs/heads/'; +$branchOnly = $branchOnly -replace '[_\-]' if($ReleaseTag -eq 'fromBranch' -or !$ReleaseTag) {