Skip to content

Commit

Permalink
Make JS validation work for docindex and release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Dec 7, 2021
1 parent 8728495 commit 4fd2d60
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
2 changes: 2 additions & 0 deletions eng/pipelines/templates/stages/archetype-js-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ stages:
SkipDefaultCheckout: true
Paths:
- sdk/**/*.md
- .github/CODEOWNERS
- download: current
- template: /eng/common/pipelines/templates/steps/update-docsms-metadata.yml
parameters:
Expand Down Expand Up @@ -286,6 +287,7 @@ stages:
SkipDefaultCheckout: true
Paths:
- sdk/**/*.md
- .github/CODEOWNERS
- download: current
- pwsh: |
Get-ChildItem -Recurse $(Pipeline.Workspace)/${{parameters.ArtifactName}}/
Expand Down
56 changes: 43 additions & 13 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ $packagePattern = "*.tgz"
$MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/main/_data/releases/latest/js-packages.csv"
$BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=javascript%2F&delimiter=%2F"

function Confirm-NodeInstallation
{
if (!(Get-Command npm -ErrorAction SilentlyContinue))
{
function Confirm-NodeInstallation {
if (!(Get-Command npm -ErrorAction SilentlyContinue)) {
LogError "Could not locate npm. Install NodeJS (includes npm and npx) https://nodejs.org/en/download"
exit 1
}
Expand Down Expand Up @@ -233,7 +231,7 @@ function Get-DocsMsPackageName($packageName, $packageVersion) {
# registry = "<url>";
# ...
# }
function ValidatePackagesForDocs($packages) {
function ValidatePackagesForDocs($packages, $DocValidationImageId) {
# Using GetTempPath because it works on linux and windows
$tempDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Force -Path $tempDirectory | Out-Null
Expand All @@ -244,7 +242,7 @@ function ValidatePackagesForDocs($packages) {
# Get value for variables outside of the Foreach-Object scope
$scriptRoot = "$using:scriptRoot"
$workingDirectory = "$using:tempDirectory"
return ."$scriptRoot\validate-docs-package.ps1" -Package $_ -DocValidationImageId "$using:ImageId" -WorkingDirectory $workingDirectory
return ."$scriptRoot\validate-docs-package.ps1" -Package $_ -DocValidationImageId "$using:DocValidationImageId" -WorkingDirectory $workingDirectory
}

# Clean up temp folder
Expand All @@ -260,8 +258,7 @@ $PackageExclusions = @{
'@azure/core-asynciterator-polyfill' = 'Docs CI fails https://github.com/Azure/azure-sdk-for-js/issues/16675';
}

function Update-javascript-DocsMsPackages($DocsRepoLocation, $DocsMetadata) {

function Update-javascript-DocsMsPackages($DocsRepoLocation, $DocsMetadata, $PackageSourceOverride, $DocValidationImageId) {
Write-Host "Excluded packages:"
foreach ($excludedPackage in $PackageExclusions.Keys) {
Write-Host " $excludedPackage - $($PackageExclusions[$excludedPackage])"
Expand All @@ -273,16 +270,17 @@ function Update-javascript-DocsMsPackages($DocsRepoLocation, $DocsMetadata) {
(Join-Path $DocsRepoLocation 'ci-configs/packages-preview.json') `
'preview' `
$FilteredMetadata `
(Join-Path $DocsRepoLocation 'ci-configs/packages-preview.json.log') # Log file for package validation

(Join-Path $DocsRepoLocation 'ci-configs/packages-preview.json.log') `# Log file for package validation
$DocValidationImageId
UpdateDocsMsPackages `
(Join-Path $DocsRepoLocation 'ci-configs/packages-latest.json') `
'latest' `
$FilteredMetadata `
(Join-Path $DocsRepoLocation 'ci-configs/packages-latest.json.log') # Log file for package validation
(Join-Path $DocsRepoLocation 'ci-configs/packages-latest.json.log') `# Log file for package validation
$DocValidationImageId
}

function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageHistoryLogFile) {
function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageHistoryLogFile, $DocValidationImageId) {
Write-Host "Updating configuration: $DocConfigFile with mode: $Mode"
$packageConfig = Get-Content $DocConfigFile -Raw | ConvertFrom-Json

Expand Down Expand Up @@ -373,7 +371,7 @@ function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageHist
$outputPackages += @{ name = $packageName }
}

$packageValidation = ValidatePackagesForDocs $outputPackages
$packageValidation = ValidatePackagesForDocs $outputPackages $DocValidationImageId
$validationHash = @{}
foreach ($result in $packageValidation) {
$validationHash[$result.Package.name] = $result
Expand Down Expand Up @@ -465,3 +463,35 @@ function GetExistingPackageVersions ($PackageName, $GroupId = $null)
return $null
}
}

function Validate-javascript-DocMsPackages {
Param(
[Parameter(Mandatory = $true)]
[PSCustomObject]$PackageInfo,
[Parameter(Mandatory = $false)]
[string]$PackageSourceOverride,
[Parameter(Mandatory = $false)]
[string]$DocValidationImageId
)
$fileLocation = ""
if ($PackageInfo.DevVersion -or $PackageInfo.Version -contains "beta") {
$fileLocation = (Join-Path $DocsRepoLocation 'ci-configs/packages-preview.json')
if ($PackageInfo.DevVersion) {
$PackageInfo.Version = $PackageInfo.DevVersion
}
}
else {
$fileLocation = (Join-Path $DocsRepoLocation 'ci-configs/packages-latest.json')
}

$packageConfig = Get-Content $fileLocation -Raw | ConvertFrom-Json
$outputPackage = $PackageInfo
foreach ($package in $packageConfig.npm_package_sources) {
if ($package.name -eq $PackageInfo.Name) {
$outputPackage = $package
$outputPackage.name = Get-DocsMsPackageName $package.name $PackageInfo.Version
break
}
}
ValidatePackagesForDocs -packages $outputPackage -DocValidationImageId $DocValidationImageId
}

0 comments on commit 4fd2d60

Please sign in to comment.