-
Notifications
You must be signed in to change notification settings - Fork 4k
Rollback modules script #5140
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
Rollback modules script #5140
Conversation
@azuresdkci test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton a couple of comments to take a look at
tools/DeleteModules.ps1
Outdated
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
param( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton I would add a CmdletBinding
attribute to this file and implement SupportsShouldProcess
so we can pass -WhatIf
to see which modules are being deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
$repoName = "PSGallery" | ||
} | ||
|
||
if (($scope -eq "ModuleList") -and ($listOfModules -eq $null)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton can we create two separate parameter sets, one that takes Scope
and another that takes ListOfModules
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
$azureRmCurrent = $azureRmAllVersions[0] | ||
$azureRmPrevious = $azureRmAllVersions[1] | ||
$currentDependencies = Find-Module -Name $query -Repository $repoName -RequiredVersion $azureRmCurrent.Version -IncludeDependencies | ||
$previousDependencies = Find-Module -Name $query -Repository $repoName -RequiredVersion $azureRmPrevious.Version -IncludeDependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton these two calls to Find-Module ... -IncludeDependencies
are very time expensive. The same information we are getting with these calls (dependent module names and versions) is already contained in $azureRmCurrent.Dependencies
and $azureRmPrevious.Dependencies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Add-AzureRMAccount | ||
} | ||
|
||
$secret = Get-AzureKeyVaultSecret -VaultName kv-azuresdk -Name $vaultKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton since this cmdlet requires us to have AzureRM.KeyVault
installed, we should have a #Requires
at the top of this script for AzureRM.KeyVault
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
|
||
if ([string]::IsNullOrEmpty($nugetExe)) | ||
{ | ||
Write-Verbose "Use default nuget path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton I would change this Write-Verbose
to Write-Host
, move it below the if-statement, and change the text to
Using the following NuGet path: $nugetExe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
|
||
if ([string]::IsNullOrEmpty($repoName)) | ||
{ | ||
Write-Verbose "Deleting from PSGallery" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton I would change this to Write-Host
, moving it below the if-statement, and changing the text to
Deleting modules from the following repository: $repoName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
$ModulesToDelete = Get-TargetModules -scope $scope -moduleList $listOfModules | ||
$ModulesToDelete | ||
$azureModules = Find-Module Azure* -Repository $repoName | ||
$ModulesToDelete | ForEach-Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maddieclayton this should be wrapped in the ShouldProcess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@azuresdkci Test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor changes, otherwise LGTM
tools/DeleteModules.ps1
Outdated
[Parameter(ParameterSetName='Scope', Mandatory = $true, Position = 0)] | ||
[ValidateSet("AzureRMAndDependencies", "AzureAndDependencies", "NetCoreModules", "AzureStackAndDependencies")] | ||
[string] $scope, | ||
[Parameter(ParameterSetName='ModuleList', Mandatory = $false)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is mandatory for the ModuleList parameter set, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
[string] $scope, | ||
[Parameter(ParameterSetName='ModuleList', Mandatory = $false)] | ||
[string[]] $listOfModules, | ||
[Parameter(Mandatory = $false)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that would be nice is the ability to remove specific versions of modules - this would be useful for AzureStack client modules, for example. Having another parameter set with the module list as a HashTable Name => Version or the like would make this possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note - this is something we do not need to do for this check-in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Syntax is:
.\DeleteModules.ps1 -moduleVersionTable @(@{"Module" = "AzureRM.Websites"; "Version" = "3.0.0"}, @{"Module" = "AzureRM.Websites"; "Version" = "4.0.0"}) -repoName TestGallery
Does that look good to you?
tools/DeleteModules.ps1
Outdated
[Parameter(ParameterSetName='ModuleList', Mandatory = $false)] | ||
[string[]] $listOfModules, | ||
[Parameter(Mandatory = $false)] | ||
[ValidateSet("TestGallery", "PSGallery")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it should be a completer. It should be possible to remove a module from any registered repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I can add an argument completer to a script like this - I could refactor the whole thing into a psm1 with functions you can import but that seems like a lot of work for not much additional functionality. Just deleting the validate set for now and making the default PSGallery.
tools/DeleteModules.ps1
Outdated
[string]$repoName, | ||
[string]$moduleName, | ||
[string]$moduleVersion, | ||
$allModules, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what types are these last two parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
$allModules | ForEach-Object { | ||
if ($_.Name -eq $targetName) | ||
{ | ||
$moduleNotBeingDeleted = $false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make this $moduleBeingDeleted and reverse the sense of the bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think this would be easier to follow if we used $allModules | Where {$_.Name -eq $targetName}
to get the set of elements matching target name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
tools/DeleteModules.ps1
Outdated
} | ||
if ($dependencies.Count -ne 0) | ||
{ | ||
Write-Warning "$moduleName $moduleVersion is a dependency for $dependencies the module(s) will have an orphaned dependency." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a ShouldContinue prompt (which would mean adding a Force parameter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tools/DeleteModules.ps1
Outdated
|
||
$ModulesToDelete = Get-TargetModules -scope $scope -moduleList $listOfModules | ||
$ModulesToDeleteName = $ModulesToDelete | ForEach-Object {$_.Name} | ||
$ModulesToDeleteName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns the value on the Output stream. Use Write-Verbose to make this informational
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed - you can run whatif to get the same information.
tools/DeleteModules.ps1
Outdated
|
||
$context = $null | ||
try { | ||
$context = Get-AzureRMContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use -ErrorAction Stop
in this call to ensure that it throws whatever the setting is in the PowerShell session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Description
#4455
This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.
General Guidelines
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThru
parameter.Cmdlet Parameter Guidelines