Skip to content

Commit ab636b1

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 7585 (#34071)
* Remove package retrieval when verify pkg version * Modified description of PackageName parameter --------- Co-authored-by: Ray Chen <[email protected]>
1 parent c6f3f01 commit ab636b1

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

eng/common/scripts/Verify-RestApiSpecLocation.ps1

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
The directory path of the service.
1010
1111
.PARAMETER PackageName
12-
The name of the package.
12+
The name of the package, which is the artifact name in pipeline.
1313
1414
.PARAMETER ArtifactLocation
1515
The location of the generated artifact for the package.
@@ -21,7 +21,7 @@
2121
The directory path where the package information is stored.
2222
2323
.EXAMPLE
24-
Verify-RestApiSpecLocation -ServiceDirectory "/home/azure-sdk-for-net/sdk/serviceab" -PackageName "MyPackage" -ArtifactLocation "/home/ab/artifacts" -GitHubPat "xxxxxxxxxxxx" -PackageInfoDirectory "/home/ab/artifacts/PackageInfo"
24+
Verify-RestApiSpecLocation -ServiceDirectory "template" -PackageName "Azure.Template" -ArtifactLocation "/home/ab/artifacts" -GitHubPat "xxxxxxxxxxxx" -PackageInfoDirectory "/home/ab/artifacts/PackageInfo"
2525
2626
#>
2727
[CmdletBinding()]
@@ -164,16 +164,6 @@ function Verify-YamlContent([string]$markdownContent, [string]$configFilePath) {
164164

165165
function Verify-PackageVersion() {
166166
try {
167-
$packages = @{}
168-
if ($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn")) {
169-
$packages = &$FindArtifactForApiReviewFn $ArtifactLocation $PackageName
170-
}
171-
else {
172-
LogError "The function for 'FindArtifactForApiReviewFn' was not found.`
173-
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
174-
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
175-
exit 1
176-
}
177167
if (-not $PackageInfoDirectory) {
178168
$PackageInfoDirectory = Join-Path -Path $ArtifactLocation "PackageInfo"
179169
if (-not (Test-Path -Path $PackageInfoDirectory)) {
@@ -182,39 +172,29 @@ function Verify-PackageVersion() {
182172
& $savePropertiesScriptPath -serviceDirectory $ServiceDirectory -outDirectory $PackageInfoDirectory
183173
}
184174
}
175+
$pkgPropPath = Join-Path -Path $PackageInfoDirectory "$PackageName.json"
176+
if (-Not (Test-Path $pkgPropPath)) {
177+
Write-Host "ServiceDir:$ServiceDirectory, no package info is found for package $PackageName at $pkgPropPath, the validation of spec location is ignored."
178+
exit 0
179+
}
180+
# Get package info from json file
181+
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
182+
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
183+
if ($null -eq $version) {
184+
LogError "ServiceDir:$ServiceDirectory, Version info is not available for package $PackageName, because version '$(pkgInfo.Version)' is invalid. Please check if the version follows Azure SDK package versioning guidelines."
185+
exit 1
186+
}
185187

186-
$continueValidation = $false
187-
if ($packages) {
188-
foreach ($pkgPath in $packages.Values) {
189-
$pkgPropPath = Join-Path -Path $PackageInfoDirectory "$PackageName.json"
190-
if (-Not (Test-Path $pkgPropPath)) {
191-
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Package property file path $($pkgPropPath) is invalid."
192-
continue
193-
}
194-
# Get package info from json file
195-
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
196-
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
197-
if ($null -eq $version) {
198-
LogError "ServiceDir:$ServiceDirectory, Version info is not available for package $PackageName, because version '$(pkgInfo.Version)' is invalid. Please check if the version follows Azure SDK package versioning guidelines."
199-
exit 1
200-
}
201-
202-
Write-Host "Version: $($version)"
203-
Write-Host "SDK Type: $($pkgInfo.SdkType)"
204-
Write-Host "Release Status: $($pkgInfo.ReleaseStatus)"
188+
Write-Host "Version: $($version)"
189+
Write-Host "SDK Type: $($pkgInfo.SdkType)"
190+
Write-Host "Release Status: $($pkgInfo.ReleaseStatus)"
205191

206-
# Ignore the validation if the package is not GA version
207-
if ($version.IsPrerelease) {
208-
Write-Host "ServiceDir:$ServiceDirectory, Package $PackageName is marked with version $version, the version is a prerelease version and the validation of spec location is ignored."
209-
exit 0
210-
}
211-
$continueValidation = $true
212-
}
213-
}
214-
if ($continueValidation -eq $false) {
215-
Write-Host "ServiceDir:$ServiceDirectory, no package info is found for package $PackageName, the validation of spec location is ignored."
192+
# Ignore the validation if the package is not GA version
193+
if ($version.IsPrerelease) {
194+
Write-Host "ServiceDir:$ServiceDirectory, Package $PackageName is marked with version $version, the version is a prerelease version and the validation of spec location is ignored."
216195
exit 0
217196
}
197+
218198
# Return the package info
219199
return $pkgInfo
220200
}
@@ -247,6 +227,7 @@ try {
247227
$tspLocationYamlPath = Join-Path $PackageDirectory "tsp-location.yaml"
248228
$autorestMdPath = Join-Path $PackageDirectory "src/autorest.md"
249229
$swaggerReadmePath = Join-Path $PackageDirectory "swagger/README.md"
230+
$autorestMdPathForGo = Join-Path $PackageDirectory "autorest.md"
250231
$tspLocationYaml = @{}
251232
if (Test-Path -Path $tspLocationYamlPath) {
252233
# typespec scenario
@@ -281,6 +262,18 @@ try {
281262
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Failed to parse swagger/readme.md file:$swaggerReadmePath with exception:`n$_ "
282263
}
283264
}
265+
if ($Language -eq "go") {
266+
# for go language we also need to check the 'autorest.md' file
267+
if (Test-Path -Path $autorestMdPathForGo) {
268+
try {
269+
$autorestMdContent = Get-Content -Path $autorestMdPathForGo -Raw
270+
Verify-YamlContent $autorestMdContent $autorestMdPathForGo
271+
}
272+
catch {
273+
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Failed to parse autorest.md file:$autorestMdPathForGo with exception:`n$_ "
274+
}
275+
}
276+
}
284277
}
285278
}
286279
catch {

0 commit comments

Comments
 (0)