mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
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.
This commit is contained in:
committed by
Travis Plunk
parent
2df9aac811
commit
4070d51ee1
+39
@@ -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 = @'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user