Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 2605 #16958

Merged
merged 2 commits into from
Feb 3, 2022
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
46 changes: 27 additions & 19 deletions eng/common/scripts/Update-DocsMsMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ param(
[Parameter(Mandatory = $false)]
[string]$ClientSecret
)

Set-StrictMode -Version 3
. (Join-Path $PSScriptRoot common.ps1)
. (Join-Path $PSScriptRoot Helpers Metadata-Helpers.ps1)

Expand Down Expand Up @@ -145,7 +145,7 @@ function GetPackageInfoJson ($packageInfoJsonLocation) {
LogWarning "Package metadata not found for $packageInfoJsonLocation"
return
}

$packageInfoJson = Get-Content $packageInfoJsonLocation -Raw
$packageInfo = ConvertFrom-Json $packageInfoJson
if ($packageInfo.DevVersion) {
Expand All @@ -165,8 +165,10 @@ function GetPackageInfoJson ($packageInfoJsonLocation) {

function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo) {
$originalVersion = [AzureEngSemanticVersion]::ParseVersionString($packageInfo.Version)

$packageMetadataArray = (Get-CSVMetadata).Where({ $_.Package -eq $packageInfo.Name -and $_.GroupId -eq $packageInfo.Group -and $_.Hide -ne 'true' -and $_.New -eq 'true' })
$packageMetadataArray = (Get-CSVMetadata).Where({ $_.Package -eq $packageInfo.Name -and $_.Hide -ne 'true' -and $_.New -eq 'true' })
if ($packageInfo.Group) {
$packageMetadataArray = ($packageMetadataArray).Where({$_.GroupId -eq $packageInfo.Group})
}
if ($packageMetadataArray.Count -eq 0) {
LogWarning "Could not retrieve metadata for $($packageInfo.Name) from metadata CSV. Using best effort defaults."
$packageMetadata = $null
Expand All @@ -177,12 +179,30 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo)
$packageMetadata = $packageMetadataArray[0]
}

# Copy package info file to the docs repo
$metadataMoniker = 'latest'
if ($originalVersion.IsPrerelease) {
$metadataMoniker = 'preview'
}
$packageMetadataName = Split-Path $packageInfoJsonLocation -Leaf
$packageInfoLocation = Join-Path $DocRepoLocation "metadata/$metadataMoniker"
$packageInfoJson = ConvertTo-Json $packageInfo
New-Item -ItemType Directory -Path $packageInfoLocation -Force
Set-Content `
-Path $packageInfoLocation/$packageMetadataName `
-Value $packageInfoJson

# Update Readme Content
if (!$packageInfo.ReadMePath -or !(Test-Path $packageInfo.ReadMePath)) {
Write-Warning "$($packageInfo.Name) does not have Readme file. Skipping update readme."
return
}

$readmeContent = Get-Content $packageInfo.ReadMePath -Raw
$outputReadmeContent = ""
if ($readmeContent) {
$outputReadmeContent = GetAdjustedReadmeContent $readmeContent $packageInfo $packageMetadata
}

$docsMsMetadata = &$GetDocsMsMetadataForPackageFn $packageInfo
$readMePath = $docsMsMetadata.LatestReadMeLocation
if ($originalVersion.IsPrerelease) {
Expand All @@ -195,33 +215,21 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo)
$readmeLocation = Join-Path $DocRepoLocation $readMePath $readMeName

Set-Content -Path $readmeLocation -Value $outputReadmeContent

# Copy package info file to the docs repo
$metadataMoniker = 'latest'
if ($originalVersion.IsPrerelease) {
$metadataMoniker = 'preview'
}
$packageMetadataName = Split-Path $packageInfoJsonLocation -Leaf
$packageInfoLocation = Join-Path $DocRepoLocation "metadata/$metadataMoniker"
$packageInfoJson = ConvertTo-Json $packageInfo
New-Item -ItemType Directory -Path $packageInfoLocation -Force
Set-Content `
-Path $packageInfoLocation/$packageMetadataName `
-Value $packageInfoJson
}

foreach ($packageInfoLocation in $PackageInfoJsonLocations) {
Write-Host "Updating metadata for package: $packageInfoLocation"

# Convert package metadata json file to metadata json property.
$packageInfo = GetPackageInfoJson $packageInfoLocation
# Add validation step for daily update and release
if ($ValidateDocsMsPackagesFn -and (Test-Path "Function:$ValidateDocsMsPackagesFn")) {
Write-Host "Validating the package..."
&$ValidateDocsMsPackagesFn -PackageInfo $packageInfo -PackageSourceOverride $PackageSourceOverride -DocValidationImageId $DocValidationImageId -DocRepoLocation $DocRepoLocation
if ($LASTEXITCODE) {
LogError "The package failed Doc.Ms validation. Check https://aka.ms/azsdk/docs/docker for more details on how to diagnose this issue."
exit $LASTEXITCODE
}
}
Write-Host "Updating the package json ..."
UpdateDocsMsMetadataForPackage $packageInfoLocation $packageInfo
}