Skip to content

Commit 8b3521a

Browse files
authored
AzDev - tell autorest-based modules from v3/v4 (#28455)
1 parent 24d2c08 commit 8b3521a

File tree

14 files changed

+303
-67
lines changed

14 files changed

+303
-67
lines changed

tools/AzDev/AzDev/AzDev.format.ps1xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<TableColumnItem>
1717
<PropertyName>Type</PropertyName>
1818
</TableColumnItem>
19+
<TableColumnItem>
20+
<PropertyName>SubType</PropertyName>
21+
</TableColumnItem>
1922
<TableColumnItem>
2023
<PropertyName>Path</PropertyName>
2124
</TableColumnItem>

tools/AzDev/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
- Quick start templates
1111
- Versioning and publishing AzDev module
1212

13+
## 2025/8/26
14+
- Feature: Recognize AutoRest.PowerShell version (v3/v4) for AutoRest-based projects and show as `SubType` in `Get-DevProject` output.
15+
1316
## 2025/1/2
1417
- Misc: moved to azure-powershell repo
1518
- Feature: Connect common repo and ps repo

tools/AzDev/README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ Set-DevContext -RepoRoot 'C:\repos\azure-powershell'
3535
`Get-DevModule` and `Get-DevProject` are the main cmdlets to get the inventory of the repo.
3636

3737
```powershell
38+
# Get first 10 modules
3839
PS /> Get-DevModule | Select-Object -First 10
3940
40-
Name Type Path
41-
---- ---- ----
42-
Maps AutoRestBased /Users/azps/workspace/azure-powershell/src/Maps
43-
Kusto AutoRestBased /Users/azps/workspace/azure-powershell/src/Kusto
44-
StorageMover AutoRestBased /Users/azps/workspace/azure-powershell/src/StorageMover
45-
ResourceGraph Hybrid /Users/azps/workspace/azure-powershell/src/ResourceGraph
46-
Terraform AutoRestBased /Users/azps/workspace/azure-powershell/src/Terraform
47-
PostgreSql AutoRestBased /Users/azps/workspace/azure-powershell/src/PostgreSql
48-
SpringCloud AutoRestBased /Users/azps/workspace/azure-powershell/src/SpringCloud
49-
ManagedNetworkFabric AutoRestBased /Users/azps/workspace/azure-powershell/src/ManagedNetworkFabric
50-
ServiceBus Hybrid /Users/azps/workspace/azure-powershell/src/ServiceBus
51-
Mdp AutoRestBased /Users/azps/workspace/azure-powershell/src/Mdp
52-
41+
Name Type Path
42+
---- ---- ----
43+
Accounts SdkBased C:\azure-powershell\src\Accounts
44+
ADDomainServices AutoRestBased C:\azure-powershell\src\ADDomainServices
45+
Advisor AutoRestBased C:\azure-powershell\src\Advisor
46+
Aks Hybrid C:\azure-powershell\src\Aks
47+
AksArc AutoRestBased C:\azure-powershell\src\AksArc
48+
Alb AutoRestBased C:\azure-powershell\src\Alb
49+
AlertsManagement Hybrid C:\azure-powershell\src\AlertsManagement
50+
AnalysisServices SdkBased C:\azure-powershell\src\AnalysisServices
51+
ApiManagement SdkBased C:\azure-powershell\src\ApiManagement
52+
App AutoRestBased C:\azure-powershell\src\App
53+
54+
# Group all projects by type
5355
PS /> Get-DevProject | Group-Object -Property Type | Select-Object -Property Name,Count | Sort-Object -Property Count -Descending
5456
5557
Name Count
@@ -61,6 +63,14 @@ Test 70
6163
Track1Sdk 48
6264
Other 8
6365
LegacyHelper 4
66+
67+
# Get statistics of autorest v3/v4
68+
PS /> Get-DevProject -Type AutoRestBased | Group-Object -Property SubType
69+
70+
Count Name Group
71+
----- ---- -----
72+
50 v3 {Advisor.Autorest, ApplicationInsights.Autorest, ArcResourceBridge.Autorest, Attestation.Autorest…}
73+
127 v4 {ADDomainServices.Autorest, Aks.Autorest, AksArc.Autorest, Alb.Autorest…}
6474
```
6575

6676
### Update Assemblies in `src/lib`

tools/AzDev/Tests/HelperTests/ConventionTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,19 @@ public void CanDeductModuleType()
241241
sdkModule = new Module() {Projects = new List<Project> {sdkProj, track1SdkProj}};
242242
Assert.Equal(ModuleType.SdkBased, Conventions.DeductModuleType(sdkModule.Projects, out _));
243243
}
244+
245+
[Theory]
246+
[InlineData("", "v4")] // empty defaults to v4
247+
[InlineData("3.0.0", "v3")]
248+
[InlineData("3.9.1", "v3")]
249+
[InlineData("3.10.1-nightly.20240801", "v3")]
250+
[InlineData("4.0.0", "v4")]
251+
[InlineData("4.8.2", "v4")]
252+
[InlineData("preview", "Invalid")]
253+
[InlineData("5.0.0", "Invalid")]
254+
public void MapAutoRestPowerShellVersion_BasicCases(string input, string expected)
255+
{
256+
var actual = Conventions.MapAutoRestPowerShellVersion(input);
257+
Assert.Equal(expected, actual);
258+
}
244259
}

tools/AzDev/Tests/HelperTests/YamlTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void CanDeserialize()
3232
Assert.Equal("1b338481329645df2d9460738cbaab6109472488", result.Commit);
3333
Assert.Equal(2, result.Require.Count());
3434
Assert.Single(result.TryRequire);
35-
Assert.Single(result.Directive);
35+
Assert.NotNull(result.Directive);
3636
Assert.Empty(result.InputFile);
3737
}
3838

@@ -45,7 +45,7 @@ public void DefaultValues()
4545
Assert.Null(result.Commit);
4646
Assert.Empty(result.Require);
4747
Assert.Empty(result.TryRequire);
48-
Assert.Empty(result.Directive);
48+
Assert.NotNull(result.Directive);
4949
Assert.Empty(result.InputFile);
5050
}
5151
}

tools/AzDev/Tests/ModelTests/ModuleTests.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ public void CanCreateFromFileSystem()
1414
var moduleName = "Test";
1515
var path = $"{cd}{split}{moduleName}";
1616
var projectName = "Test.AutoRest";
17-
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
18-
{
19-
{ $"{path}{split}{projectName}{split}Test.csproj", new MockFileData(
20-
@""
21-
)}
22-
});
17+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
18+
{
19+
{ $"{path}{split}{projectName}{split}Test.csproj", new MockFileData(@"") },
20+
{ $"{path}{split}{projectName}{split}README.md", new MockFileData(
21+
@"### AutoRest Configuration
22+
``` yaml
23+
title: Test
24+
input-file:
25+
- $(repo)/specification/test.json
26+
```
27+
") }
28+
});
2329

2430
var module = Module.FromFileSystem(fs, new NoopLogger(), path);
2531
Assert.Equal(path, module.Path);
@@ -36,15 +42,19 @@ public void CanRecognizeBothProjectTypes()
3642
var path = $"{cd}{split}{moduleName}";
3743
var sdkProjectName = "Beta";
3844
var generatedProjectName = "Alpha.AutoRest";
39-
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
40-
{
41-
{ $"{path}{split}{generatedProjectName}{split}Alpha.csproj", new MockFileData(
42-
@""
43-
)},
44-
{ $"{path}{split}{sdkProjectName}{split}Beta.csproj", new MockFileData(
45-
@""
46-
)},
47-
});
45+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
46+
{
47+
{ $"{path}{split}{generatedProjectName}{split}Alpha.csproj", new MockFileData(@"") },
48+
{ $"{path}{split}{generatedProjectName}{split}README.md", new MockFileData(
49+
@"### AutoRest Configuration
50+
``` yaml
51+
title: Test
52+
input-file:
53+
- $(repo)/specification/test.json
54+
```
55+
") },
56+
{ $"{path}{split}{sdkProjectName}{split}Beta.csproj", new MockFileData(@"") },
57+
});
4858

4959
var module = Module.FromFileSystem(fs, new NoopLogger(), path);
5060
Assert.Equal(2, module.Projects.Count());

tools/AzDev/Tests/ModelTests/ProjectTests.cs

Lines changed: 123 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,128 @@ namespace AzDev.Tests;
55

66
public class ProjectTests
77
{
8-
[Fact]
9-
public void CanCreateFromFileSystem()
10-
{
11-
var cd = Directory.GetCurrentDirectory();
12-
var split = Path.DirectorySeparatorChar;
13-
var projectName = "Test.AutoRest";
14-
var path = $"{cd}{split}{projectName}";
15-
var readme = $"{path}{split}README.md";
16-
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
8+
[Fact]
9+
public void CanCreateFromFileSystem()
1710
{
18-
{ readme, new MockFileData(
19-
@""
20-
)}
21-
});
22-
23-
var project = Project.FromFileSystem(fs, path);
24-
Assert.Equal(path, project.Path);
25-
Assert.Equal(projectName, project.Name);
26-
}
11+
var cd = Directory.GetCurrentDirectory();
12+
var split = Path.DirectorySeparatorChar;
13+
var projectName = "Test.AutoRest";
14+
var path = $"{cd}{split}{projectName}";
15+
var readme = $"{path}{split}README.md";
16+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
17+
{
18+
{ readme, new MockFileData(
19+
@"### AutoRest Configuration
20+
``` yaml
21+
title: Test
22+
input-file:
23+
- $(repo)/specification/test.json
24+
```
25+
"
26+
)}
27+
});
28+
29+
var project = Project.FromFileSystem(fs, path);
30+
Assert.Equal(path, project.Path);
31+
Assert.Equal(projectName, project.Name);
32+
}
33+
34+
[Fact]
35+
public void AutoRestVersion_Defaults_To_v4_When_Omitted()
36+
{
37+
var cd = Directory.GetCurrentDirectory();
38+
var split = Path.DirectorySeparatorChar;
39+
var projectName = "Test2.AutoRest";
40+
var path = $"{cd}{split}{projectName}";
41+
var readme = $"{path}{split}README.md";
42+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
43+
{
44+
{ readme, new MockFileData(
45+
@"### AutoRest Configuration
46+
``` yaml
47+
title: Test
48+
input-file:
49+
- $(repo)/specification/test.json
50+
```
51+
"
52+
)}
53+
});
54+
55+
var project = Project.FromFileSystem(fs, path);
56+
var arp = Assert.IsType<AutoRestProject>(project);
57+
Assert.Equal("v4", arp.AutoRestVersion);
58+
Assert.Equal("v4", project.SubType);
59+
}
60+
61+
[Fact]
62+
public void AutoRestVersion_Recognizes_v3_And_v4()
63+
{
64+
var cd = Directory.GetCurrentDirectory();
65+
var split = Path.DirectorySeparatorChar;
66+
var projectName = "Test3.AutoRest";
67+
var path = $"{cd}{split}{projectName}";
68+
var readme = $"{path}{split}README.md";
69+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
70+
{
71+
{ readme, new MockFileData(
72+
@"### AutoRest Configuration
73+
``` yaml
74+
use-extension:
75+
""@autorest/powershell"": ""3.x""
76+
input-file:
77+
- $(repo)/specification/test.json
78+
```
79+
"
80+
)}
81+
});
82+
83+
var project = Project.FromFileSystem(fs, path);
84+
var arp = Assert.IsType<AutoRestProject>(project);
85+
Assert.Equal("v3", arp.AutoRestVersion);
86+
Assert.Equal("v3", project.SubType);
87+
88+
// Now switch to 4.x
89+
fs.File.WriteAllText(readme,
90+
@"### AutoRest Configuration
91+
``` yaml
92+
use-extension:
93+
""@autorest/powershell"": ""4.x""
94+
input-file:
95+
- $(repo)/specification/test.json
96+
```
97+
");
98+
// reconstruct to reload
99+
project = Project.FromFileSystem(fs, path);
100+
arp = Assert.IsType<AutoRestProject>(project);
101+
Assert.Equal("v4", arp.AutoRestVersion);
102+
Assert.Equal("v4", project.SubType);
103+
}
104+
105+
[Fact]
106+
public void AutoRestVersion_Invalid_Value()
107+
{
108+
var cd = Directory.GetCurrentDirectory();
109+
var split = Path.DirectorySeparatorChar;
110+
var projectName = "Test4.AutoRest";
111+
var path = $"{cd}{split}{projectName}";
112+
var readme = $"{path}{split}README.md";
113+
var fs = new MockFileSystem(new Dictionary<string, MockFileData>
114+
{
115+
{ readme, new MockFileData(
116+
@"### AutoRest Configuration
117+
``` yaml
118+
use-extension:
119+
""@autorest/powershell"": ""5.x""
120+
input-file:
121+
- $(repo)/specification/test.json
122+
```
123+
"
124+
)}
125+
});
126+
127+
var project = Project.FromFileSystem(fs, path);
128+
var arp = Assert.IsType<AutoRestProject>(project);
129+
Assert.Equal("Invalid", arp.AutoRestVersion);
130+
Assert.Equal("Invalid", project.SubType);
131+
}
27132
}

tools/AzDev/Tests/PSTests/InventoryTests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ Describe 'Repo inventory' {
2525
$others = Get-DevProject -Type Other
2626
$others.Count | Should -BeLessOrEqual 8
2727
}
28+
29+
It 'AutoRest projects expose a valid SubType (AutoRest version)' {
30+
$proj = Get-DevProject -Type AutoRestBased
31+
$proj | Should -Not -BeNullOrEmpty
32+
$proj.SubType | Should -Match '^(v3|v4)$'
33+
}
2834
}

0 commit comments

Comments
 (0)