@@ -37,90 +37,93 @@ param (
3737)
3838
3939. (Join-Path $PSScriptRoot common.ps1)
40+ . " $PSScriptRoot /../../scripts/docs/Docs-Onboarding.ps1"
4041
41- function GetDocsMetadataForMoniker ($moniker ) {
42- $searchPath = Join-Path $DocRepoLocation ' metadata' $moniker
43- if (! (Test-Path $searchPath )) {
44- return @ ()
45- }
46- $paths = Get-ChildItem - Path $searchPath - Filter * .json
42+ Set-StrictMode - Version 3
4743
44+ function GetMetadata ($moniker ) {
45+ $jsonFiles = Get-ChildItem - Path (Join-Path $DocRepoLocation " metadata/$moniker " ) - Filter * .json
4846 $metadata = @ ()
49- foreach ($path in $paths ) {
50- $fileContents = Get-Content $path - Raw
51- $fileObject = ConvertFrom-Json - InputObject $fileContents
52- $versionGa = ' '
53- $versionPreview = ' '
54- if ($moniker -eq ' latest' ) {
55- $versionGa = $fileObject.Version
56- } else {
57- $versionPreview = $fileObject.Version
58- }
59-
60- $entry = @ {
61- Package = $fileObject.Name ;
62- VersionGA = $versionGa ;
63- VersionPreview = $versionPreview ;
64- RepoPath = $fileObject.ServiceDirectory ;
65- Type = $fileObject.SdkType ;
66- New = $fileObject.IsNewSdk ;
67- }
68- if ($fileObject.PSObject.Members.Name -contains " Group" )
69- {
70- $entry.Add (" GroupId" , $fileObject.Group )
71- }
72- $metadata += $entry
47+ foreach ($jsonFile in $jsonFiles ) {
48+ # Converting to a hashtable gives more beneficial semantics for handling
49+ # metadata (easier to check existence of property, easier to add new
50+ # properties)
51+ $metadata += Get-Content $jsonFile - Raw | ConvertFrom-Json - AsHashtable
7352 }
7453
7554 return $metadata
7655}
7756
78- function GetDocsMetadata () {
79- # Read metadata from docs repo
80- $metadataByPackage = @ {}
81- foreach ($package in GetDocsMetadataForMoniker ' latest' ) {
82- if ($metadataByPackage.ContainsKey ($package.Package )) {
83- LogWarning " Duplicate package in latest metadata: $ ( $package.Package ) "
84- }
85- Write-Host " Adding latest package: $ ( $package.Package ) "
86- $metadataByPackage [$package.Package ] = $package
57+ function ValidatePackageForOnboarding2 ($package ) {
58+ if (! (Test-Path " Function:$ValidateDocsMsPackagesFn " )) {
59+ return $true
8760 }
8861
89- foreach ($package in GetDocsMetadataForMoniker ' preview' ) {
90- if ($metadataByPackage.ContainsKey ($package.Package )) {
91- # Merge VersionPreview of each object
92- Write-Host " Merging preview package version for $ ( $package.Package ) )"
93- $metadataByPackage [$package.Package ].VersionPreview = $package.VersionPreview
94- } else {
95- Write-Host " Adding preview package: $ ( $package.Package ) "
96- $metadataByPackage [$package.Package ] = $package
97- }
98- }
99-
100- # TODO - Add a call to GetDocsMetadataForMoniker for 'legacy' when that is implemented
101-
102- return $metadataByPackage.Values
62+ return & $ValidateDocsMsPackagesFn `
63+ - PackageInfo $package `
64+ - DocValidationImageId $ImageId `
65+ - DocRepoLocation $DocRepoLocation
10366}
10467
105- if ( $UpdateDocsMsPackagesFn -and ( Test-Path " Function: $UpdateDocsMsPackagesFn " )) {
106-
68+ $MONIKERS = @ ( ' latest ' , ' preview ' , ' legacy ' )
69+ foreach ( $moniker in $MONIKERS ) {
10770 try {
108- $docsMetadata = GetDocsMetadata
109- & $UpdateDocsMsPackagesFn - DocsRepoLocation $DocRepoLocation - DocsMetadata $docsMetadata - PackageSourceOverride $PackageSourceOverride - DocValidationImageId $ImageId
110- } catch {
111- LogError " Exception while updating docs.ms packages"
112- LogError $_
113- LogError $_.ScriptStackTrace
71+ Write-Host " Onboarding packages for moniker: $moniker "
72+ $metadata = GetMetadata $moniker
73+ $alreadyOnboardedPackages = & $GetDocsPackagesAlreadyOnboarded $DocRepoLocation $moniker
74+
75+ # Sort the metadata entries by package name so that the output is
76+ # deterministic (more simple diffs)
77+ $sortedMetadata = $metadata | Sort-Object - Property ' _DocsOnboardingOrdinal' , ' Name'
78+
79+ $outputPackages = @ ()
80+ foreach ($package in $sortedMetadata ) {
81+ $packageIdentity = $package.Name
82+ if (Test-Path " Function:$GetPackageIdentity " ) {
83+ $packageIdentity = & $GetPackageIdentity $package
84+ }
85+
86+ if (! ($alreadyOnboardedPackages.ContainsKey ($packageIdentity ))) {
87+ Write-Host " Evaluating package for onboarding: $ ( $packageIdentity ) "
88+ if ($package.ContainsKey (' _SkipDocsValidation' ) -and $true -eq $package [' _SkipDocsValidation' ]) {
89+ Write-Host " Skip validation for package: $ ( $packageIdentity ) "
90+ }
91+ elseif (! (ValidatePackageForOnboarding2 $package )) {
92+ LogWarning " Skip adding package that did not pass validation: $ ( $packageIdentity ) "
93+ continue
94+ }
95+
96+ Write-Host " Add new package: $ ( $packageIdentity ) @$ ( $package.Version ) "
97+ $outputPackages += $package
98+ continue
99+ }
100+
101+ $oldPackage = $alreadyOnboardedPackages [$packageIdentity ]
102+
103+ if ($oldPackage.Version -ne $package.Version ) {
104+ if (! (ValidatePackageForOnboarding2 $package )) {
105+ LogWarning " Omitting package that failed validation: $ ( $packageIdentity ) @$ ( $package.Version ) "
106+ continue
107+ }
108+
109+ Write-Host " Update package: $ ( $packageIdentity ) @$ ( $oldPackage.Version ) to $ ( $packageIdentity ) @$ ( $package.Version ) "
110+ $outputPackages += $package
111+ continue
112+ }
113+
114+ Write-Host " Unchanged package: $ ( $packageIdentity ) @$ ( $package.Version ) "
115+ $outputPackages += $package
116+ }
117+
118+ & $SetDocsPackageOnboarding $moniker $outputPackages $DocRepoLocation $PackageSourceOverride
119+ }
120+ catch {
121+ Write-Host " Error onboarding packages for moniker: $moniker "
122+ Write-Host " Error: $_ "
123+ Write-Host " Stacktrace: $ ( $_.ScriptStackTrace ) "
124+ Write-Error $_
114125 exit 1
115126 }
116-
117- } else {
118- LogError " The function for '$UpdateFn ' was not found.`
119- Make sure it is present in eng/scripts/Language-Settings.ps1 and referenced in eng/common/scripts/common.ps1.`
120- See https://github.com/Azure/azure-sdk-tools/blob/main/doc/common/common_engsys.md#code-structure"
121- exit 1
122127}
123128
124- # Exit 0 so DevOps doesn't fail the build when the last command called by the
125- # domain-specific function exited with a non-zero exit code.
126129exit 0
0 commit comments