Skip to content

Fix the bug of PowerShellGet in tools/RunVersionController.ps1 #10412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions tools/RunVersionController.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# To version all modules in Az (standard release), run the following command: .\RunVersionController.ps1 -Release "December 2017"
# To version a single module (one-off release), run the following command: .\RunVersionController.ps1 -ModuleName "Az.Compute"

#Requires -Modules @{ModuleName="PowerShellGet"; ModuleVersion="2.2.1"}

[CmdletBinding(DefaultParameterSetName="ReleaseAz")]
Param(
[Parameter(ParameterSetName='ReleaseAz', Mandatory = $true)]
Expand Down Expand Up @@ -151,16 +154,9 @@ function Update-ChangeLog
($Content + $ChangeLogContent) | Set-Content -Path $ChangeLogFile.FullName -Encoding UTF8
}

if (!(Test-Path "C:/Program Files/PowerShell/Modules/PowerShellGet"))
function Get-ExistSerializedCmdletJsonFile
{
try
{
Save-Module -Name PowerShellGet -Repository $GalleryName -Path "C:/Program Files/PowerShell/Modules" -ErrorAction Stop
}
catch
{
throw "Please rerun in Administrator mode."
}
return $(ls "$PSScriptRoot\Tools.Common\SerializedCmdlets").Name
}

switch ($PSCmdlet.ParameterSetName)
Expand All @@ -172,6 +168,38 @@ switch ($PSCmdlet.ParameterSetName)

"ReleaseAz"
{

# clean the unnecessary SerializedCmdlets json file
$ExistSerializedCmdletJsonFile = Get-ExistSerializedCmdletJsonFile
$ExpectJsonHashSet = @{}
$SrcPath = "..\src"
foreach ($ModuleName in $(Get-ChildItem $SrcPath -Directory).Name)
{
$ModulePath = $(Join-Path -Path $SrcPath -ChildPath $ModuleName)
$Psd1FileName = "Az.{0}.psd1" -f $ModuleName
$Psd1FilePath = $(Get-ChildItem $ModulePath -Depth 2 -Recurse -Filter $Psd1FileName)
if ($null -ne $Psd1FilePath)
{
$Psd1Object = Import-PowerShellDataFile $Psd1FilePath
if ($Psd1Object.ModuleVersion -ge "1.0.0")
{
foreach ($NestedModule in $Psd1Object.NestedModules)
{
$JsonFile = $NestedModule.Replace(".\", "") + ".json"
$ExpectJsonHashSet.Add($JsonFile, $true)
}
}
}
}
foreach ($JsonFile in $ExistSerializedCmdletJsonFile)
{
$ModuleName = $JsonFile.Replace('Microsoft.Azure.PowerShell.Cmdlets.', '').Replace('.dll.json', '')
if (!$ExpectJsonHashSet.Contains($JsonFile))
{
Write-Host "Module ${ModuleName} is not GA yet. Remove the json file: ${JsonFile}." -ForegroundColor Red
rm $(Join-Path -Path "$PSScriptRoot\Tools.Common\SerializedCmdlets" -ChildPath $JsonFile)
}
}
try
{
Install-Module Az -Repository $GalleryName -Force -AllowClobber
Expand Down
Loading