@@ -5,88 +5,37 @@ param (
5
5
[Parameter (Position = 1 )]
6
6
[string ] $TargetCommitish = " HEAD" ,
7
7
[Parameter (Position = 2 )]
8
- [string ] $SpecType = " data-plane|resource-manager"
8
+ [string ] $SpecType = " data-plane|resource-manager" ,
9
+ [string ] $CheckAllUnder
9
10
)
10
11
Set-StrictMode - Version 3
11
12
12
13
. $PSScriptRoot / ChangedFiles- Functions.ps1
13
14
. $PSScriptRoot / Logging- Functions.ps1
14
15
15
- $script :psYamlInstalled = $false
16
- function Ensure-PowerShell-Yaml-Installed {
17
- if ($script :psYamlInstalled ) {
18
- # If already checked once in this script, don't log anything further
19
- return ;
20
- }
21
-
22
- $script :psYamlInstalled = [bool ] (Get-Module - ListAvailable - Name powershell- yaml | Where-Object { $_.Version -eq " 0.4.7" })
23
-
24
- if ($script :psYamlInstalled ) {
25
- LogInfo
" Module [email protected] already installed"
26
- }
27
- else {
28
- LogInfo
" Installing module [email protected] "
29
- Install-Module - Name powershell- yaml - RequiredVersion 0.4 .7 - Force - Scope CurrentUser
30
- $script :psYamlInstalled = $true
31
- }
32
- }
33
-
34
- function Find-Suppressions-Yaml {
35
- param (
36
- [string ]$fileInSpecFolder
37
- )
38
-
39
- $currentDirectory = Get-Item (Split-Path - Path $fileInSpecFolder )
40
-
41
- while ($currentDirectory ) {
42
- $suppressionsFile = Join-Path - Path $currentDirectory.FullName - ChildPath " suppressions.yaml"
43
-
44
- if (Test-Path $suppressionsFile ) {
45
- return $suppressionsFile
46
- } else {
47
- $currentDirectory = $currentDirectory.Parent
48
- }
49
- }
50
-
51
- return $null
52
- }
53
-
54
16
function Get-Suppression {
55
17
param (
56
18
[string ]$fileInSpecFolder
57
19
)
58
20
59
- $suppressionsFile = Find-Suppressions - Yaml $fileInSpecFolder
60
- if ($suppressionsFile ) {
61
- Ensure- PowerShell- Yaml- Installed
62
-
63
- $suppressions = Get-Content - Path $suppressionsFile - Raw | ConvertFrom-Yaml
64
- foreach ($suppression in $suppressions ) {
65
- $tool = $suppression [" tool" ]
66
- $path = $suppression [" path" ]
67
-
68
- if ($tool -eq " TypeSpecRequirement" ) {
69
- # Paths in suppressions.yml are relative to the file itself
70
- $fullPath = Join-Path - Path (Split-Path - Path $suppressionsFile ) - ChildPath $path
21
+ # -NoEnumerate to prevent single-element arrays from being collapsed to a single object
22
+ # -AsHashtable is closer to raw JSON than PSCustomObject
23
+ $suppressions = npx get-suppressions TypeSpecRequirement $fileInSpecFolder | ConvertFrom-Json - NoEnumerate - AsHashtable
71
24
72
- # If path is not specified, suppression applies to all files
73
- if (! $path -or ($fileInSpecFolder -like $fullPath )) {
74
- return $suppression
75
- }
76
- }
77
- }
78
- }
79
-
80
- return $null
25
+ return $suppressions ? $suppressions [0 ] : $null ;
81
26
}
82
27
83
28
$repoPath = Resolve-Path " $PSScriptRoot /../.."
84
29
$pathsWithErrors = @ ()
85
30
86
- $filesToCheck = (Get-ChangedSwaggerFiles (Get-ChangedFiles $BaseCommitish $TargetCommitish )).Where ({
31
+ $filesToCheck = $CheckAllUnder ?
32
+ (Get-ChildItem - Path $CheckAllUnder - Recurse - File | Resolve-Path - Relative | ForEach-Object { $_ -replace ' \\' , ' /' }) :
33
+ (Get-ChangedSwaggerFiles (Get-ChangedFiles $BaseCommitish $TargetCommitish ))
34
+
35
+ $filesToCheck = $filesToCheck.Where ({
87
36
($_ -notmatch " /(examples|scenarios|restler|common|common-types)/" ) -and
88
37
($_ -match " specification/[^/]+/($SpecType ).*?/(preview|stable)/[^/]+/[^/]+\.json$" )
89
- })
38
+ })
90
39
91
40
if (! $filesToCheck ) {
92
41
LogInfo " No OpenAPI files found to check"
@@ -138,7 +87,7 @@ else {
138
87
}
139
88
else {
140
89
LogError (" OpenAPI was generated from TypeSpec, but folder 'specification/$rpFolder ' contains no files named 'tspconfig.yaml'." `
141
- + " The TypeSpec used to generate OpenAPI must be added to this folder." )
90
+ + " The TypeSpec used to generate OpenAPI must be added to this folder." )
142
91
LogJobFailure
143
92
exit 1
144
93
}
@@ -170,7 +119,7 @@ else {
170
119
$urlToStableFolder = " https://github.com/Azure/azure-rest-api-specs/tree/main/specification/$servicePath /stable"
171
120
172
121
# Avoid conflict with pipeline secret
173
- $logUrlToStableFolder = $urlToStableFolder -replace ' ^https://' , ' '
122
+ $logUrlToStableFolder = $urlToStableFolder -replace ' ^https://' , ' '
174
123
175
124
LogInfo " Checking $logUrlToStableFolder "
176
125
@@ -209,15 +158,13 @@ else {
209
158
}
210
159
}
211
160
212
- if ($pathsWithErrors.Count -gt 0 )
213
- {
161
+ if ($pathsWithErrors.Count -gt 0 ) {
214
162
# DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first
215
163
# and then as many of the individual ones as can be found afterwards
216
164
LogError " New specs must use TypeSpec. For more detailed docs see https://aka.ms/azsdk/typespec"
217
165
LogJobFailure
218
166
219
- foreach ($path in $pathsWithErrors )
220
- {
167
+ foreach ($path in $pathsWithErrors ) {
221
168
LogErrorForFile $path " OpenAPI was not generated from TypeSpec, and spec appears to be new"
222
169
}
223
170
exit 1
0 commit comments