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

[eng/common] Update-DocsMsMetadata.ps1 can fail the build on invalid packages #6530

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
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
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"
}