Skip to content

Commit 94ffdec

Browse files
azure-powershell-botazurepowershell
and
azurepowershell
authored
Sync tools folder from main branch to generation branch (#25871)
Co-authored-by: azurepowershell <azurepowershell@ms.com>
1 parent 263135c commit 94ffdec

File tree

13 files changed

+286
-166
lines changed

13 files changed

+286
-166
lines changed

.azure-pipelines/daily-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
script: |
5959
$command = "`$PSVersionTable `
6060
Get-PSRepository `
61-
./tools/RunVersionController.ps1 -Release 'Daily Build $(today)' `
61+
./tools/RunVersionController.ps1 -Release 'Daily Build $(today)' -ReleaseType $(ReleaseType)`
6262
Exit"
6363
dotnet tool run pwsh -c $command
6464

tools/RunVersionController.ps1

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ Param(
2121
[string]$GalleryName = "PSGallery",
2222

2323
[Parameter()]
24-
[string]$ArtifactsOutputPath = "$PSScriptRoot/../artifacts/Release/"
24+
[string]$ArtifactsOutputPath = "$PSScriptRoot/../artifacts/Release/",
25+
26+
[Parameter()]
27+
[ValidateSet("STS", "LTS")]
28+
[string]$ReleaseType = "STS"
2529
)
2630

2731
enum PSVersion
@@ -194,15 +198,18 @@ function Bump-AzVersion
194198
{
195199
Write-Host "Getting local Az information..." -ForegroundColor Yellow
196200
$localAz = Import-PowerShellDataFile -Path "$PSScriptRoot\Az\Az.psd1"
197-
198-
Write-Host "Getting gallery Az information..." -ForegroundColor Yellow
199-
$galleryAz = Find-Module -Name Az -Repository $GalleryName
201+
Write-Host "Getting Az $ReleaseType information from gallery..." -ForegroundColor Yellow
202+
if("LTS" -eq $ReleaseType){
203+
$galleryAz = (Find-Module -Name Az -Repository $GalleryName -AllVersions | Where-Object {([System.Version]($_.Version)).Major%2 -eq 0} | Sort-Object {[System.Version]$_.Version} -Descending)[0]
204+
}else{
205+
$galleryAz = Find-Module -Name Az -Repository $GalleryName
206+
}
200207

201208
$versionBump = [PSVersion]::NONE
202209
$updatedModules = @()
203210
foreach ($localDependency in $localAz.RequiredModules)
204211
{
205-
$galleryDependency = $galleryAz.Dependencies | where { $_.Name -eq $localDependency.ModuleName }
212+
$galleryDependency = $galleryAz.Dependencies | Where-Object { $_.Name -eq $localDependency.ModuleName }
206213
if ($null -eq $galleryDependency)
207214
{
208215
$updatedModules += $localDependency.ModuleName
@@ -313,7 +320,7 @@ function Update-AzPreview
313320
$Psd1Object = Import-PowerShellDataFile $Psd1FilePath
314321
$moduleName = [System.IO.Path]::GetFileName($Psd1FilePath) -replace ".psd1"
315322
$moduleVersion = $Psd1Object.ModuleVersion.ToString()
316-
if('Az.Accounts' -eq $moduleName)
323+
if('Az.Accounts' -eq $moduleName -and "STS" -eq $ReleaseType)
317324
{
318325
$requiredModulesString += "@{ModuleName = '$moduleName'; ModuleVersion = '$moduleVersion'; }, `n "
319326
}
@@ -482,8 +489,8 @@ switch ($PSCmdlet.ParameterSetName)
482489
{
483490
"ReleaseSingleModule"
484491
{
485-
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName
486-
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName
492+
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName $ReleaseType
493+
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $PSScriptRoot/../artifacts/VersionController/Exceptions $ModuleName $ReleaseType
487494
Update-AzPreview
488495
}
489496

@@ -521,8 +528,8 @@ switch ($PSCmdlet.ParameterSetName)
521528
}
522529
}
523530

524-
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll
525-
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll
531+
Write-Host executing dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $ReleaseType
532+
dotnet $PSScriptRoot/../artifacts/VersionController/VersionController.Netcore.dll $ReleaseType
526533

527534
$versionBump = Bump-AzVersion
528535
# Each release needs to update AzPreview.psd1 and dotnet csv

tools/Tools.Common/Loaders/MetadataLoader.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ namespace Tools.Common.Loaders
3030
{
3131
public class MetadataLoader
3232
{
33+
private static string _rootPath = Path.GetFullPath(Path.Combine(Assembly.GetExecutingAssembly().Location, "..", "..", ".."));
34+
3335
public static ModuleMetadata GetModuleMetadata(string moduleName)
3436
{
35-
string rootPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", ".."));
36-
string modulePsd1Path = Directory.GetFiles(Path.Combine(rootPath, "artifacts"), $"{moduleName}.psd1", SearchOption.AllDirectories)[0];
37+
// bez: notice that this search way always find artifacts/Debug/{moduleName}/psd1 first, which may cause some issues
38+
// to work around this issue, clear Debug folder if we are intended to bump version for Release
39+
string modulePsd1Path = Directory.GetFiles(Path.Combine(_rootPath, "artifacts"), $"{moduleName}.psd1", SearchOption.AllDirectories)[0];
3740
if (modulePsd1Path == null)
3841
{
39-
Console.Error.WriteLine($"Cannot find {moduleName}.psd1 in {Path.Combine(rootPath, "artifacts")}!");
42+
Console.Error.WriteLine($"Cannot find {moduleName}.psd1 in {Path.Combine(_rootPath, "artifacts")}!");
4043
}
4144
return GetModuleMetadata(moduleName, modulePsd1Path);
4245
}
43-
public static ModuleMetadata GetModuleMetadata(string moduleName, string modulePsd1Path)
46+
47+
private static ModuleMetadata GetModuleMetadata(string moduleName, string modulePsd1Path)
4448
{
4549
using (var powershell = PowerShell.Create(RunspaceMode.NewRunspace))
4650
{
@@ -49,15 +53,14 @@ public static ModuleMetadata GetModuleMetadata(string moduleName, string moduleP
4953
powershell.AddScript("Set-ExecutionPolicy Unrestricted -Scope Process -ErrorAction Ignore");
5054
}
5155
powershell.AddScript("$error.clear()");
52-
powershell.AddScript($"Write-Debug \"current directory: { AppDomain.CurrentDomain.BaseDirectory }\"");
53-
string rootPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", ".."));
54-
string repoToolsPath = Path.Combine(rootPath, "tools");
56+
powershell.AddScript($"Write-Debug \"current directory: { Assembly.GetExecutingAssembly().Location}\"");
57+
string repoToolsPath = Path.Combine(_rootPath, "tools");
5558
powershell.AddScript($"cd {repoToolsPath}\\ModuleMetadata");
5659
powershell.AddScript($"Import-Module {repoToolsPath}\\ModuleMetadata\\GetModuleMetadata.psm1");
57-
string accountsPsd1Path = Directory.GetFiles(Path.Combine(rootPath, "artifacts"), "Az.Accounts.psd1", SearchOption.AllDirectories)[0];
60+
string accountsPsd1Path = Directory.GetFiles(Path.Combine(_rootPath, "artifacts"), "Az.Accounts.psd1", SearchOption.AllDirectories)[0];
5861
if (accountsPsd1Path == null)
5962
{
60-
Console.Error.WriteLine($"Cannot find Az.Accounts.psd1 in {Path.Combine(rootPath, "artifacts", "Accounts")}!");
63+
Console.Error.WriteLine($"Cannot find Az.Accounts.psd1 in {Path.Combine(_rootPath, "artifacts", "Accounts")}!");
6164
}
6265
powershell.AddScript($"Import-Module {accountsPsd1Path}");
6366
powershell.AddScript($"(Get-ModuleMetadata -Psd1Path {modulePsd1Path} -ModuleName {moduleName}).ToJsonString()");

tools/Tools.Common/Models/CmdletMetadata.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,17 @@ public override bool Equals(Object obj)
354354
var otherParameterSet = other.ParameterSets.Find(p => string.Equals(p.Name, thisParameterSet.Name, StringComparison.OrdinalIgnoreCase));
355355
if (otherParameterSet == null)
356356
{
357+
// Console.WriteLine($"Parameter set {thisParameterSet.Name} in cmdlet {this.Name} is not found in new module.");
357358
return false;
358359
}
359360

360361
cmdletsEqual &= thisParameterSet.Equals(otherParameterSet);
361362
}
362363

364+
/*if (this.ParameterSets.Count != other.ParameterSets.Count)
365+
{
366+
Console.WriteLine($"The number of parameter sets in cmdlet {this.Name} is unmatched.");
367+
}*/
363368
cmdletsEqual &= this.ParameterSets.Count == other.ParameterSets.Count;
364369
return cmdletsEqual;
365370
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace VersionController.Netcore.Models
4+
{
5+
public class CommonInfo
6+
{
7+
public static List<string> ExcludedParameters = new List<string>{
8+
"AzureRMContext", "Break", "Debug", "DefaultProfile", "EnableTestCoverage",
9+
"ErrorAction", "ErrorVariable", "HttpPipelineAppend", "HttpPipelinePrepend", "InformationAction",
10+
"InformationVariable", "OutBuffer", "OutVariable", "PipelineVariable", "Proxy",
11+
"ProxyCredential", "ProxyUseDefaultCredentials", "Verbose", "WarningAction", "WarningVariable",
12+
"ProgressAction",
13+
// excluded runtime dynamic parameters
14+
// "EnableTestCoverage", "TestCoverageLocation", "TargetName"
15+
};
16+
}
17+
}

tools/Tools.Common/Models/ModuleMetadata.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ public override bool Equals(Object obj)
8787
var otherCmdlet = other.Cmdlets.Find(c => thisCmdletNames.ContainsKey(c.Name) || c.AliasList.Find(a => thisCmdletNames.ContainsKey(a)) != null);
8888
if (otherCmdlet == null)
8989
{
90+
// Console.WriteLine($"Cannot find cmdlet {thisCmdletNames} in new version.");
9091
return false;
9192
}
92-
9393
modulesEqual &= thisCmdlet.Equals(otherCmdlet);
9494
}
95-
95+
/*if(this.Cmdlets.Count != other.Cmdlets.Count)
96+
{
97+
Console.WriteLine($"The number of cmdlets is unmatched in old and new module");
98+
}*/
9699
modulesEqual &= this.Cmdlets.Count == other.Cmdlets.Count;
97100
return modulesEqual;
98101
}

tools/Tools.Common/Models/ParameterSetMetadata.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections;
1617
using System.Collections.Generic;
18+
using System.Linq;
19+
20+
using VersionController.Netcore.Models;
1721

1822
namespace Tools.Common.Models
1923
{
@@ -58,13 +62,24 @@ public override bool Equals(Object obj)
5862
var otherParameter = other.Parameters.Find(p => thisParameterNames.ContainsKey(p.ParameterMetadata.Name) || p.ParameterMetadata.AliasList.Find(a => thisParameterNames.ContainsKey(a)) != null);
5963
if (otherParameter == null)
6064
{
65+
// Console.WriteLine($"Parameter {thisParameter.ParameterMetadata.Name} in parameter set {this.Name} is not found in new module.");
6166
return false;
6267
}
63-
6468
paramsSetEqual &= thisParameter.Equals(otherParameter);
6569
}
6670

67-
paramsSetEqual &= this.Parameters.Count == other.Parameters.Count;
71+
var curParameters = this.Parameters.Where(p => !CommonInfo.ExcludedParameters.Contains(p.ParameterMetadata.Name)).ToList();
72+
var otherParameters = other.Parameters.Where(p => !CommonInfo.ExcludedParameters.Contains(p.ParameterMetadata.Name)).ToList();
73+
/*if (curParameters.Count != otherParameters.Count)
74+
{
75+
Console.WriteLine($"The number of parameters in parameter set {this.Name} is not same.");
76+
Console.WriteLine("Parameters in old version: ");
77+
this.Parameters.ForEach(p => Console.Write(p.ParameterMetadata.Name + " "));
78+
Console.WriteLine(Environment.NewLine + "Parameters in new version: ");
79+
other.Parameters.ForEach(p => Console.Write(p.ParameterMetadata.Name + " "));
80+
Console.WriteLine();
81+
}*/
82+
paramsSetEqual &= curParameters.Count == otherParameters.Count;
6883
return paramsSetEqual;
6984
}
7085

@@ -232,13 +247,13 @@ public override bool Equals(Object obj)
232247
{
233248
return false;
234249
}
235-
236250
var paramsEqual = true;
237251
paramsEqual &= this.Mandatory == other.Mandatory &&
238252
this.Position == other.Position &&
239253
this.ValueFromPipeline == other.ValueFromPipeline &&
240254
this.ValueFromPipelineByPropertyName == other.ValueFromPipelineByPropertyName &&
241255
this.ParameterMetadata.Equals(other.ParameterMetadata);
256+
// if (!paramsEqual) Console.WriteLine($"The attributes of {this.ParameterMetadata.Name} is different in new version");
242257
return paramsEqual;
243258
}
244259

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Management.Automation;
4+
5+
using Tools.Common.Models;
6+
7+
namespace VersionController.Netcore.Models
8+
{
9+
internal class ModuleHelper
10+
{
11+
/// <summary>
12+
/// Get the version of latest Az.Accounts in LTS status from PSGallery
13+
/// </summary>
14+
/// <returns></returns>
15+
internal static string GetLatestVersionFromPSGallery(string moduleName, ReleaseType releaseType = ReleaseType.STS)
16+
{
17+
18+
string version = null;
19+
string findModuleScript = releaseType == ReleaseType.STS ? $"Find-Module {moduleName} -Repository PSGallery -AllVersions" : "Find-Module Az -Repository PSGallery -AllVersions";
20+
string filterRequiredReleaseTypeScript = releaseType == ReleaseType.STS ? "" : "| Where-Object {([System.Version]($_.Version)).Major%2 -eq 0}";
21+
string sortModuleScript = "| Sort-Object {[System.Version]$_.Version} -Descending";
22+
string getLastModuleVersionScript = releaseType == ReleaseType.STS ?
23+
$"({findModuleScript}{filterRequiredReleaseTypeScript}{sortModuleScript})[0].Version" :
24+
$"(({findModuleScript}{filterRequiredReleaseTypeScript}{sortModuleScript})[0].Dependencies | Where-Object {{$_.Name -eq '{moduleName}'}})[1]";
25+
using (PowerShell powershell = PowerShell.Create())
26+
{
27+
powershell.AddScript(getLastModuleVersionScript);
28+
var cmdletResult = powershell.Invoke();
29+
version = cmdletResult[0]?.ToString();
30+
}
31+
return version;
32+
}
33+
34+
/// <summary>
35+
/// Get version from PSGallery and TestGallery and merge into one list.
36+
/// </summary>
37+
/// <returns>A list of version</returns>
38+
internal static List<AzurePSVersion> GetAllVersionsFromGallery(string moduleName, string psRepository)
39+
{
40+
HashSet<AzurePSVersion> galleryVersion = new HashSet<AzurePSVersion>();
41+
using (PowerShell powershell = PowerShell.Create())
42+
{
43+
powershell.AddScript($"Find-Module -Name {moduleName} -Repository {psRepository} -AllowPrerelease -AllVersions");
44+
var cmdletResult = powershell.Invoke();
45+
foreach (var versionInformation in cmdletResult)
46+
{
47+
if (versionInformation.Properties["Version"]?.Value != null)
48+
{
49+
galleryVersion.Add(new AzurePSVersion(versionInformation.Properties["Version"]?.Value?.ToString()));
50+
}
51+
}
52+
}
53+
return galleryVersion.ToList();
54+
}
55+
56+
57+
/// <summary>
58+
/// Under the same Major version, check if there exist preview version in gallery that has greater version.
59+
/// </summary>
60+
/// <returns>True if exist a version, false otherwise.</returns>
61+
internal static AzurePSVersion GetLatestVersionFromGalleryUnderSameMajorVersion(AzurePSVersion bumpedVersion, List<AzurePSVersion> galleryVersion, bool IsPreview)
62+
{
63+
var maxVersionInGallery = new AzurePSVersion(0, 0, 0);
64+
65+
foreach (var version in galleryVersion)
66+
{
67+
if (version.Major == bumpedVersion.Major && (version.IsPreview == IsPreview) && version > maxVersionInGallery)
68+
{
69+
maxVersionInGallery = version;
70+
}
71+
}
72+
return maxVersionInGallery;
73+
}
74+
}
75+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace VersionController.Netcore.Models
8+
{
9+
public enum ReleaseType
10+
{
11+
STS,
12+
LTS
13+
}
14+
}

tools/VersionController/Models/SyntaxChangelogGenerator.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ public class SyntaxChangelogGenerator
1616
public AnalysisLogger Logger { get; set; }
1717
public string Name { get; set; }
1818
public string CmdletDiffIssueReportLoggerName { get; set; }
19-
private List<string> _ignoreParameters = new List<string>
20-
{
21-
"AzureRMContext", "Break", "Debug", "DefaultProfile", "EnableTestCoverage",
22-
"ErrorAction", "ErrorVariable", "HttpPipelineAppend", "HttpPipelinePrepend", "InformationAction",
23-
"InformationVariable", "OutBuffer", "OutVariable", "PipelineVariable", "Proxy",
24-
"ProxyCredential", "ProxyUseDefaultCredentials", "Verbose", "WarningAction", "WarningVariable"
25-
};
19+
private List<string> _ignoreParameters = CommonInfo.ExcludedParameters;
2620
private List<CmdletDiffInformation> diffInfo = new List<CmdletDiffInformation>();
2721
public void Analyze(String rootDirectory)
2822
{
2923
var srcDirs = Path.Combine(rootDirectory, @"src\");
3024
var toolsCommonDirs = Path.Combine(rootDirectory, @"tools\Tools.Common");
25+
// bez: Will include psd1 files under test proj
3126
var manifestFiles = Directory.EnumerateFiles(srcDirs, "*.psd1", SearchOption.AllDirectories)
3227
.Where(file =>
3328
!Path.GetDirectoryName(file)

0 commit comments

Comments
 (0)