From d6579fedc4ef9180db7a5cf370ee68efed40ceb7 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 2 Feb 2022 16:58:34 -0800 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 2605 (#16958) * Non stop on readme checking * Print the right variable name Co-authored-by: sima-zhu Co-authored-by: Sima Zhu <48036328+sima-zhu@users.noreply.github.com> --- eng/common/scripts/Update-DocsMsMetadata.ps1 | 46 ++++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/eng/common/scripts/Update-DocsMsMetadata.ps1 b/eng/common/scripts/Update-DocsMsMetadata.ps1 index a51a1dfb932c..1684e967c09a 100644 --- a/eng/common/scripts/Update-DocsMsMetadata.ps1 +++ b/eng/common/scripts/Update-DocsMsMetadata.ps1 @@ -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) @@ -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) { @@ -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 @@ -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) { @@ -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 }