Skip to content

Commit

Permalink
Use docker validation on release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Dec 2, 2021
1 parent a660690 commit 169546c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
19 changes: 16 additions & 3 deletions eng/common/pipelines/templates/steps/update-docsms-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ parameters:
type: object
default:
- '**'

- name: PackageSourceOverride
type: string
default: ''
- name: DocValidationImageId
type: string
default: ''
steps:
- template: /eng/common/pipelines/templates/steps/enable-long-path-support.yml

Expand Down Expand Up @@ -73,15 +78,23 @@ steps:
parameters:
WorkingDirectory: $(DocRepoLocation)
DefaultBranchVariableName: TargetBranchName

# Pull and build the docker image.
- ${{ if ne(parameters.DocValidationImageId, '') }}:
- template: /eng/common/pipelines/templates/steps/docker-pull-image.yml
parameters:
ContainerRegistryClientId: $(azuresdkimages-cr-clientid)
ContainerRegistryClientSecret: $(azuresdkimages-cr-clientsecret)
ImageId: '${{ parameters.DocValidationImageId }}'
- pwsh: |
$packageInfoJson = '${{ convertToJson(parameters.PackageInfoLocations) }}'.Trim('"').Replace("\\", "/")
$packageInfoLocations = ConvertFrom-Json $packageInfoJson
${{ parameters.ScriptDirectory }}/Update-DocsMsMetadata.ps1 `
-PackageInfoJsonLocations $packageInfoLocations `
-DocRepoLocation "$(DocRepoLocation)" `
-Language '${{parameters.Language}}' `
-RepoId '${{ parameters.RepoId }}'
-RepoId '${{ parameters.RepoId }}' `
-DocValidationImageId '${{ parameters.DocValidationImageId }}' `
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}'
displayName: Apply Documentation Updates

- template: /eng/common/pipelines/templates/steps/git-push-changes.yml
Expand Down
45 changes: 37 additions & 8 deletions eng/common/scripts/Update-DocsMsMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,37 @@ path information is provided by $GetDocsMsMetadataForPackageFn
Programming language to supply to metadata
.PARAMETER RepoId
GitHub repository ID of the SDK. Typically of the form: 'Azure/azure-sdk-for-js'
GitHub repository ID of the SDK. Typically of the form: 'Azure/azure-sdk-for-js'
.PARAMETER DocValidationImageId
The docker image id in format of '$containerRegistry/$imageName:$tag'
e.g. azuresdkimages.azurecr.io/jsrefautocr:latest
.PARAMETER PackageSourceOverride
Optional parameter to supply a different package source (useful for daily dev
docs generation from pacakges which are not published to the default feed). This
variable is meant to be used in the domain-specific business logic in
&$ValidateDocsMsPackagesFn
#>

param(
[Parameter(Mandatory = $true)]
[array]$PackageInfoJsonLocations,

[Parameter(Mandatory = $true)]
[string]$DocRepoLocation,

[Parameter(Mandatory = $true)]
[string]$Language,

[Parameter(Mandatory = $true)]
[string]$RepoId
[string]$RepoId,

[Parameter(Mandatory = $false)]
[string]$DocValidationImageId,

[Parameter(Mandatory = $false)]
[string]$PackageSourceOverride
)

. (Join-Path $PSScriptRoot common.ps1)
Expand Down Expand Up @@ -104,21 +119,19 @@ ms.technology: azure
ms.devlang: $Language
ms.service: $service
---
"@

return "$header`n$ReadmeContent"
}

function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation) {
function GetPackageInfoJson ($packageInfoJsonLocation) {
if (!(Test-Path $packageInfoJsonLocation)) {
LogWarning "Package metadata not found for $packageInfoJsonLocation"
return
}

$packageInfoJson = Get-Content $packageInfoJsonLocation -Raw
$packageInfo = ConvertFrom-Json $packageInfoJson
$originalVersion = [AzureEngSemanticVersion]::ParseVersionString($packageInfo.Version)
if ($packageInfo.DevVersion) {
# If the package is of a dev version there may be language-specific needs to
# specify the appropriate version. For example, in the case of JS, the dev
Expand All @@ -131,6 +144,11 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation) {
$packageInfo.Version = $packageInfo.DevVersion
}
}
return $packageInfo
}

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' })
if ($packageMetadataArray.Count -eq 0) {
Expand Down Expand Up @@ -176,7 +194,18 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation) {
-Value $packageInfoJson
}

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

# 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")) {
&$ValidateDocsMsPackagesFn -PackageInfo $packageInfo $PackageSourceOverride $DocValidationImageId
if ($LASTEXITCODE -ne 0) {
LogError "The package failed Doc.Ms validation. Please fixed the doc and republish to Doc.Ms."
exit 1
}
}
UpdateDocsMsMetadataForPackage $packageInfoLocation $packageInfo
}
1 change: 1 addition & 0 deletions eng/common/scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ $GetDocsMsDevLanguageSpecificPackageInfoFn = "Get-${Language}-DocsMsDevLanguageS
$GetGithubIoDocIndexFn = "Get-${Language}-GithubIoDocIndex"
$FindArtifactForApiReviewFn = "Find-${Language}-Artifacts-For-Apireview"
$TestProxyTrustCertFn = "Import-Dev-Cert-${Language}"
$ValidateDocsMsPackagesFn = "Validate-${Language}-DocMsPackages"

0 comments on commit 169546c

Please sign in to comment.