@@ -5,88 +5,37 @@ param (
55 [Parameter (Position = 1 )]
66 [string ] $TargetCommitish = " HEAD" ,
77 [Parameter (Position = 2 )]
8- [string ] $SpecType = " data-plane|resource-manager"
8+ [string ] $SpecType = " data-plane|resource-manager" ,
9+ [string ] $CheckAllUnder
910)
1011Set-StrictMode - Version 3
1112
1213. $PSScriptRoot / ChangedFiles- Functions.ps1
1314. $PSScriptRoot / Logging- Functions.ps1
1415
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-
5416function Get-Suppression {
5517 param (
5618 [string ]$fileInSpecFolder
5719 )
5820
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
7124
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 ;
8126}
8227
8328$repoPath = Resolve-Path " $PSScriptRoot /../.."
8429$pathsWithErrors = @ ()
8530
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 ({
8736 ($_ -notmatch " /(examples|scenarios|restler|common|common-types)/" ) -and
8837 ($_ -match " specification/[^/]+/($SpecType ).*?/(preview|stable)/[^/]+/[^/]+\.json$" )
89- })
38+ })
9039
9140if (! $filesToCheck ) {
9241 LogInfo " No OpenAPI files found to check"
@@ -138,7 +87,7 @@ else {
13887 }
13988 else {
14089 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." )
14291 LogJobFailure
14392 exit 1
14493 }
@@ -170,7 +119,7 @@ else {
170119 $urlToStableFolder = " https://github.com/Azure/azure-rest-api-specs/tree/main/specification/$servicePath /stable"
171120
172121 # Avoid conflict with pipeline secret
173- $logUrlToStableFolder = $urlToStableFolder -replace ' ^https://' , ' '
122+ $logUrlToStableFolder = $urlToStableFolder -replace ' ^https://' , ' '
174123
175124 LogInfo " Checking $logUrlToStableFolder "
176125
@@ -209,15 +158,13 @@ else {
209158 }
210159}
211160
212- if ($pathsWithErrors.Count -gt 0 )
213- {
161+ if ($pathsWithErrors.Count -gt 0 ) {
214162 # DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first
215163 # and then as many of the individual ones as can be found afterwards
216164 LogError " New specs must use TypeSpec. For more detailed docs see https://aka.ms/azsdk/typespec"
217165 LogJobFailure
218166
219- foreach ($path in $pathsWithErrors )
220- {
167+ foreach ($path in $pathsWithErrors ) {
221168 LogErrorForFile $path " OpenAPI was not generated from TypeSpec, and spec appears to be new"
222169 }
223170 exit 1
0 commit comments