Skip to content

Commit

Permalink
Remove package retrieval when verify pkg version (#7585)
Browse files Browse the repository at this point in the history
* Remove package retrieval when verify pkg version

* Modified description of PackageName parameter
  • Loading branch information
raych1 authored Jan 31, 2024
1 parent 2cea39b commit 37c14df
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions eng/common/scripts/Verify-RestApiSpecLocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
The directory path of the service.
.PARAMETER PackageName
The name of the package.
The name of the package, which is the artifact name in pipeline.
.PARAMETER ArtifactLocation
The location of the generated artifact for the package.
Expand All @@ -21,7 +21,7 @@
The directory path where the package information is stored.
.EXAMPLE
Verify-RestApiSpecLocation -ServiceDirectory "/home/azure-sdk-for-net/sdk/serviceab" -PackageName "MyPackage" -ArtifactLocation "/home/ab/artifacts" -GitHubPat "xxxxxxxxxxxx" -PackageInfoDirectory "/home/ab/artifacts/PackageInfo"
Verify-RestApiSpecLocation -ServiceDirectory "template" -PackageName "Azure.Template" -ArtifactLocation "/home/ab/artifacts" -GitHubPat "xxxxxxxxxxxx" -PackageInfoDirectory "/home/ab/artifacts/PackageInfo"
#>
[CmdletBinding()]
Expand Down Expand Up @@ -164,16 +164,6 @@ function Verify-YamlContent([string]$markdownContent, [string]$configFilePath) {

function Verify-PackageVersion() {
try {
$packages = @{}
if ($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiReviewFn")) {
$packages = &$FindArtifactForApiReviewFn $ArtifactLocation $PackageName
}
else {
LogError "The function for 'FindArtifactForApiReviewFn' was not found.`
Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
exit 1
}
if (-not $PackageInfoDirectory) {
$PackageInfoDirectory = Join-Path -Path $ArtifactLocation "PackageInfo"
if (-not (Test-Path -Path $PackageInfoDirectory)) {
Expand All @@ -182,39 +172,29 @@ function Verify-PackageVersion() {
& $savePropertiesScriptPath -serviceDirectory $ServiceDirectory -outDirectory $PackageInfoDirectory
}
}
$pkgPropPath = Join-Path -Path $PackageInfoDirectory "$PackageName.json"
if (-Not (Test-Path $pkgPropPath)) {
Write-Host "ServiceDir:$ServiceDirectory, no package info is found for package $PackageName at $pkgPropPath, the validation of spec location is ignored."
exit 0
}
# Get package info from json file
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
if ($null -eq $version) {
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."
exit 1
}

$continueValidation = $false
if ($packages) {
foreach ($pkgPath in $packages.Values) {
$pkgPropPath = Join-Path -Path $PackageInfoDirectory "$PackageName.json"
if (-Not (Test-Path $pkgPropPath)) {
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Package property file path $($pkgPropPath) is invalid."
continue
}
# Get package info from json file
$pkgInfo = Get-Content $pkgPropPath | ConvertFrom-Json
$version = [AzureEngSemanticVersion]::ParseVersionString($pkgInfo.Version)
if ($null -eq $version) {
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."
exit 1
}

Write-Host "Version: $($version)"
Write-Host "SDK Type: $($pkgInfo.SdkType)"
Write-Host "Release Status: $($pkgInfo.ReleaseStatus)"
Write-Host "Version: $($version)"
Write-Host "SDK Type: $($pkgInfo.SdkType)"
Write-Host "Release Status: $($pkgInfo.ReleaseStatus)"

# Ignore the validation if the package is not GA version
if ($version.IsPrerelease) {
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."
exit 0
}
$continueValidation = $true
}
}
if ($continueValidation -eq $false) {
Write-Host "ServiceDir:$ServiceDirectory, no package info is found for package $PackageName, the validation of spec location is ignored."
# Ignore the validation if the package is not GA version
if ($version.IsPrerelease) {
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."
exit 0
}

# Return the package info
return $pkgInfo
}
Expand Down Expand Up @@ -247,6 +227,7 @@ try {
$tspLocationYamlPath = Join-Path $PackageDirectory "tsp-location.yaml"
$autorestMdPath = Join-Path $PackageDirectory "src/autorest.md"
$swaggerReadmePath = Join-Path $PackageDirectory "swagger/README.md"
$autorestMdPathForGo = Join-Path $PackageDirectory "autorest.md"
$tspLocationYaml = @{}
if (Test-Path -Path $tspLocationYamlPath) {
# typespec scenario
Expand Down Expand Up @@ -281,6 +262,18 @@ try {
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Failed to parse swagger/readme.md file:$swaggerReadmePath with exception:`n$_ "
}
}
if ($Language -eq "go") {
# for go language we also need to check the 'autorest.md' file
if (Test-Path -Path $autorestMdPathForGo) {
try {
$autorestMdContent = Get-Content -Path $autorestMdPathForGo -Raw
Verify-YamlContent $autorestMdContent $autorestMdPathForGo
}
catch {
Write-Host "ServiceDir:$ServiceDirectory, PackageName:$PackageName. Failed to parse autorest.md file:$autorestMdPathForGo with exception:`n$_ "
}
}
}
}
}
catch {
Expand Down

0 comments on commit 37c14df

Please sign in to comment.