Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this was only for local testing but now after your change this will happen every time and I suspect that isn't what we want. The idea was that we would get the already existing packageInfo from the artifacts but it appears that go doesn't publish those. So, the question is should we have go start publishing them? We might need to for other scenarios like APIView. However if we don't do that we shouldn't write the json files to disk we should just call the helper functions that the at save script is calling.

See https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/scripts/Save-Package-Properties.ps1#L95

For example there will be cases where looking for $PackageName.json will fail that were already handled in that save script https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/scripts/Save-Package-Properties.ps1#L115

$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