Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 2605 (Azure#20187)
Browse files Browse the repository at this point in the history
* Non stop on readme checking

* Print the right variable name

Co-authored-by: sima-zhu <sizhu@microsoft.com>
Co-authored-by: Sima Zhu <48036328+sima-zhu@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 3, 2022
1 parent 981ee5a commit 53d112b
Showing 1 changed file with 27 additions and 19 deletions.
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
}

0 comments on commit 53d112b

Please sign in to comment.