Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 6530 (#21199)
Browse files Browse the repository at this point in the history
* Update-DocsMsMetadata.ps1 can fail the build on invalid packages

* Better error handling and logging

* Review feedback

---------

Co-authored-by: Daniel Jurek <djurek@microsoft.com>
  • Loading branch information
azure-sdk and danieljurek authored Jul 19, 2023
1 parent ba64496 commit 38c7bb1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
11 changes: 11 additions & 0 deletions eng/common/pipelines/templates/steps/docsms-ensure-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
steps:
# Fail the build if any of the packages failed validation. Valid values are
# "true" or "false"
- pwsh: |
if ('$(DocsMsPackagesAllValid)' -eq 'true') {
Write-Host "All packages passed validation."
} else {
Write-Error "Some packages failed validation."
exit 1
}
displayName: Check package validation results
39 changes: 31 additions & 8 deletions eng/common/scripts/Update-DocsMsMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,40 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation) {
Set-Content -Path $readmeLocation -Value $outputReadmeContent
}

# For daily update and release, validate DocsMS publishing using the language-specific validation function
if ($ValidateDocsMsPackagesFn -and (Test-Path "Function:$ValidateDocsMsPackagesFn")) {
Write-Host "Validating the packages..."

$packageInfos = @($PackageInfoJsonLocations | ForEach-Object { GetPackageInfoJson $_ })
$allSucceeded = $true
foreach ($packageInfoLocation in $PackageInfoJsonLocations) {

&$ValidateDocsMsPackagesFn -PackageInfos $packageInfos -PackageSourceOverride $PackageSourceOverride -DocValidationImageId $DocValidationImageId -DocRepoLocation $DocRepoLocation
}
if ($ValidateDocsMsPackagesFn -and (Test-Path "Function:$ValidateDocsMsPackagesFn")) {
Write-Host "Validating the packages..."

$packageInfo = GetPackageInfoJson $packageInfoLocation
# This calls a function named "Validate-${Language}-DocMsPackages"
# declared in common.ps1, implemented in Language-Settings.ps1
$isValid = &$ValidateDocsMsPackagesFn `
-PackageInfos $packageInfo `
-PackageSourceOverride $PackageSourceOverride `
-DocValidationImageId $DocValidationImageId `
-DocRepoLocation $DocRepoLocation

if (!$isValid) {
Write-Host "Package validation failed for package: $packageInfoLocation"
$allSucceeded = $false

# Skip the later call to UpdateDocsMsMetadataForPackage because this
# package has not passed validation
continue
}
}

foreach ($packageInfoLocation in $PackageInfoJsonLocations) {
Write-Host "Updating metadata for package: $packageInfoLocation"
# Convert package metadata json file to metadata json property.
UpdateDocsMsMetadataForPackage $packageInfoLocation
}

# Set a variable which will be used by the pipeline later to fail the build if
# any packages failed validation
if ($allSucceeded) {
Write-Host "##vso[task.setvariable variable=DocsMsPackagesAllValid;]$true"
} else {
Write-Host "##vso[task.setvariable variable=DocsMsPackagesAllValid;]$false"
}

0 comments on commit 38c7bb1

Please sign in to comment.