Skip to content

Commit 2e19c52

Browse files
authored
Delete redundant docs onboarding language from Language-Settings.ps1, move validation to Docs-Onboarding.ps1 (Azure#37558)
1 parent 309b2e0 commit 2e19c52

File tree

2 files changed

+157
-334
lines changed

2 files changed

+157
-334
lines changed

eng/scripts/Language-Settings.ps1

Lines changed: 2 additions & 330 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ function Get-python-PackageInfoFromPackageFile ($pkg, $workingDirectory)
204204
}
205205

206206
# This is the GetDocsMsDevLanguageSpecificPackageInfoFn implementation
207+
# Defined in common.ps1 as:
208+
# $GetDocsMsDevLanguageSpecificPackageInfoFn = "Get-${Language}-DocsMsDevLanguageSpecificPackageInfo"
207209
function Get-python-DocsMsDevLanguageSpecificPackageInfo($packageInfo, $packageSourceOverride) {
208210
# If the default namespace isn't in the package info then it needs to be added
209211
# Can't check if (!$packageInfo.Namespaces) in strict mode because Namespaces won't exist
@@ -284,336 +286,6 @@ function Get-python-GithubIoDocIndex()
284286
GenerateDocfxTocContent -tocContent $tocContent -lang "Python" -campaignId "UA-62780441-36"
285287
}
286288

287-
function ValidatePackage
288-
{
289-
Param(
290-
[Parameter(Mandatory=$true)]
291-
[string]$packageName,
292-
[Parameter(Mandatory=$true)]
293-
[string]$packageVersion,
294-
[Parameter(Mandatory=$false)]
295-
[string]$PackageSourceOverride,
296-
[Parameter(Mandatory=$false)]
297-
[string]$DocValidationImageId
298-
)
299-
$installValidationFolder = Join-Path ([System.IO.Path]::GetTempPath()) "validation"
300-
if (!(Test-Path $installValidationFolder)) {
301-
New-Item -ItemType Directory -Force -Path $installValidationFolder | Out-Null
302-
}
303-
# Add more validation by replicating as much of the docs CI process as
304-
# possible
305-
# https://github.com/Azure/azure-sdk-for-python/issues/20109
306-
$result = $true
307-
if (!$DocValidationImageId) {
308-
Write-Host "Validating using pip command directly on $packageName."
309-
$result = FallbackValidation -packageName "$packageName" -packageVersion "$packageVersion" -workingDirectory $installValidationFolder -PackageSourceOverride $PackageSourceOverride
310-
} else {
311-
Write-Host "Validating using $DocValidationImageId on $packageName."
312-
$result = DockerValidation -packageName "$packageName" -packageVersion "$packageVersion" `
313-
-PackageSourceOverride $PackageSourceOverride -DocValidationImageId $DocValidationImageId -workingDirectory $installValidationFolder
314-
}
315-
316-
return $result
317-
}
318-
function DockerValidation{
319-
Param(
320-
[Parameter(Mandatory=$true)]
321-
[string]$packageName,
322-
[Parameter(Mandatory=$true)]
323-
[string]$packageVersion,
324-
[Parameter(Mandatory=$false)]
325-
[string]$PackageSourceOverride,
326-
[Parameter(Mandatory=$false)]
327-
[string]$DocValidationImageId,
328-
[Parameter(Mandatory=$false)]
329-
[string]$workingDirectory
330-
)
331-
if ($PackageSourceOverride) {
332-
Write-Host "docker run -v ${workingDirectory}:/workdir/out -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -e EXTRA_INDEX_URL=$PackageSourceOverride -t $DocValidationImageId"
333-
$commandLine = docker run -v "${workingDirectory}:/workdir/out" -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion `
334-
-e EXTRA_INDEX_URL=$PackageSourceOverride -t $DocValidationImageId 2>&1
335-
}
336-
else {
337-
Write-Host "docker run -v ${workingDirectory}:/workdir/out -e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -t $DocValidationImageId"
338-
$commandLine = docker run -v "${workingDirectory}:/workdir/out" `
339-
-e TARGET_PACKAGE=$packageName -e TARGET_VERSION=$packageVersion -t $DocValidationImageId 2>&1
340-
}
341-
# The docker exit codes: https://docs.docker.com/engine/reference/run/#exit-status
342-
# If the docker failed because of docker itself instead of the application,
343-
# we should skip the validation and keep the packages.
344-
345-
if ($LASTEXITCODE -eq 125 -Or $LASTEXITCODE -eq 126 -Or $LASTEXITCODE -eq 127) {
346-
$commandLine | ForEach-Object { Write-Debug $_ }
347-
LogWarning "The `docker` command does not work with exit code $LASTEXITCODE. Fall back to npm install $packageName directly."
348-
FallbackValidation -packageName "$packageName" -packageVersion "$packageVersion" -workingDirectory $workingDirectory -PackageSourceOverride $PackageSourceOverride
349-
}
350-
elseif ($LASTEXITCODE -ne 0) {
351-
$commandLine | ForEach-Object { Write-Debug $_ }
352-
LogWarning "Package $packageName ref docs validation failed."
353-
return $false
354-
}
355-
return $true
356-
}
357-
358-
function FallbackValidation
359-
{
360-
Param(
361-
[Parameter(Mandatory=$true)]
362-
[string]$packageName,
363-
[Parameter(Mandatory=$true)]
364-
[string]$packageVersion,
365-
[Parameter(Mandatory=$true)]
366-
[string]$workingDirectory,
367-
[Parameter(Mandatory=$false)]
368-
[string]$PackageSourceOverride
369-
)
370-
$installTargetFolder = Join-Path $workingDirectory $packageName
371-
New-Item -ItemType Directory -Force -Path $installTargetFolder | Out-Null
372-
$packageExpression = "$packageName$packageVersion"
373-
try {
374-
$pipInstallOutput = ""
375-
if ($PackageSourceOverride) {
376-
Write-Host "python -m pip install $packageExpression --no-cache-dir --target $installTargetFolder --extra-index-url=$PackageSourceOverride"
377-
$pipInstallOutput = python -m pip `
378-
install `
379-
$packageExpression `
380-
--no-cache-dir `
381-
--target $installTargetFolder `
382-
--extra-index-url=$PackageSourceOverride 2>&1
383-
}
384-
else {
385-
Write-Host "python -m pip install $packageExpression --no-cache-dir --target $installTargetFolder"
386-
$pipInstallOutput = python -m pip `
387-
install `
388-
$packageExpression `
389-
--no-cache-dir `
390-
--target $installTargetFolder 2>&1
391-
}
392-
if ($LASTEXITCODE -ne 0) {
393-
LogWarning "python -m pip install failed for $packageExpression"
394-
Write-Host $pipInstallOutput
395-
return $false
396-
}
397-
} catch {
398-
LogWarning "python -m pip install failed for $packageExpression with exception"
399-
LogWarning $_.Exception
400-
LogWarning $_.Exception.StackTrace
401-
return $false
402-
}
403-
404-
return $true
405-
}
406-
407-
$PackageExclusions = @{
408-
'azure-mgmt-videoanalyzer' = 'Unsupported doc directives: https://github.com/Azure/azure-sdk-for-python/issues/21563';
409-
'azure-mgmt-quota' = 'Unsupported doc directives: https://github.com/Azure/azure-sdk-for-python/issues/21366';
410-
'azure-mgmt-apimanagement' = 'Unsupported doc directives https://github.com/Azure/azure-sdk-for-python/issues/18084';
411-
'azure-mgmt-reservations' = 'Unsupported doc directives https://github.com/Azure/azure-sdk-for-python/issues/18077';
412-
'azure-mgmt-signalr' = 'Unsupported doc directives https://github.com/Azure/azure-sdk-for-python/issues/18085';
413-
'azure-mgmt-mixedreality' = 'Missing version info https://github.com/Azure/azure-sdk-for-python/issues/18457';
414-
'azure-mgmt-network' = 'Manual process used to build';
415-
'azureml-fsspec' = 'Build issues related to Python requirements: https://github.com/Azure/azure-sdk-for-python/issues/30565';
416-
'mltable' = 'Build issues related to Python requirements: https://github.com/Azure/azure-sdk-for-python/issues/30565';
417-
418-
'azure-mgmt-compute' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
419-
'azure-mgmt-consumption' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
420-
'azure-mgmt-notificationhubs' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
421-
'azure-servicebus' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
422-
'azure-mgmt-web' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
423-
'azure-mgmt-netapp' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
424-
'azure-synapse-artifacts' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
425-
'azure-mgmt-streamanalytics' = 'Latest package requires Python >= 3.7 and this breaks docs build. https://github.com/Azure/azure-sdk-for-python/issues/22492';
426-
'azure-ai-ml' = 'Docs CI build issues https://github.com/Azure/azure-sdk-for-python/issues/30774';
427-
428-
'azure-keyvault' = 'Metapackages should not be documented';
429-
}
430-
431-
function Update-python-DocsMsPackages($DocsRepoLocation, $DocsMetadata, $PackageSourceOverride, $DocValidationImageId) {
432-
Write-Host "Excluded packages:"
433-
foreach ($excludedPackage in $PackageExclusions.Keys) {
434-
Write-Host " $excludedPackage - $($PackageExclusions[$excludedPackage])"
435-
}
436-
437-
$FilteredMetadata = $DocsMetadata.Where({ !($PackageExclusions.ContainsKey($_.Package)) })
438-
439-
UpdateDocsMsPackages `
440-
(Join-Path $DocsRepoLocation 'ci-configs/packages-preview.json') `
441-
'preview' `
442-
$FilteredMetadata `
443-
$PackageSourceOverride `
444-
$DocValidationImageId
445-
446-
UpdateDocsMsPackages `
447-
(Join-Path $DocsRepoLocation 'ci-configs/packages-latest.json') `
448-
'latest' `
449-
$FilteredMetadata `
450-
$PackageSourceOverride `
451-
$DocValidationImageId
452-
}
453-
454-
function UpdateDocsMsPackages($DocConfigFile, $Mode, $DocsMetadata, $PackageSourceOverride, $DocValidationImageId) {
455-
Write-Host "Updating configuration: $DocConfigFile with mode: $Mode"
456-
$packageConfig = Get-Content $DocConfigFile -Raw | ConvertFrom-Json
457-
458-
$outputPackages = @()
459-
foreach ($package in $packageConfig.packages) {
460-
$packageName = $package.package_info.name
461-
if (!$packageName) {
462-
Write-Host "Keeping package with no name: $($package.package_info)"
463-
$outputPackages += $package
464-
continue
465-
}
466-
467-
if ($package.package_info.install_type -ne 'pypi') {
468-
Write-Host "Keeping package with install_type not 'pypi': $($package.package_info.name)"
469-
$outputPackages += $package
470-
continue
471-
}
472-
473-
if ($package.package_info.name.EndsWith("-nspkg")) {
474-
Write-Host "Skipping $($package.package_info.name) because it's a namespace package."
475-
continue
476-
}
477-
478-
# Do not filter by GA/Preview status because we want differentiate between
479-
# tracked and non-tracked packages
480-
$matchingPublishedPackageArray = $DocsMetadata.Where( { $_.Package -eq $packageName })
481-
482-
# If this package does not match any published packages keep it in the list.
483-
# This handles packages which are not tracked in metadata but still need to
484-
# be built in Docs CI.
485-
if ($matchingPublishedPackageArray.Count -eq 0) {
486-
Write-Host "Keep non-tracked package: $packageName"
487-
$outputPackages += $package
488-
continue
489-
}
490-
491-
if ($matchingPublishedPackageArray.Count -gt 1) {
492-
LogWarning "Found more than one matching published package in metadata for $packageName; only updating first entry"
493-
}
494-
$matchingPublishedPackage = $matchingPublishedPackageArray[0]
495-
496-
if ($Mode -eq 'preview' -and !$matchingPublishedPackage.VersionPreview.Trim()) {
497-
# If we are in preview mode and the package does not have a superseding
498-
# preview version, remove the package from the list.
499-
Write-Host "Remove superseded preview package: $packageName"
500-
continue
501-
}
502-
503-
if ($Mode -eq 'latest' -and !$matchingPublishedPackage.VersionGA.Trim()) {
504-
LogWarning "Metadata is missing GA version for GA package $packageName. Keeping existing package."
505-
$outputPackages += $package
506-
continue
507-
}
508-
509-
$packageVersion = "==$($matchingPublishedPackage.VersionGA)"
510-
if ($Mode -eq 'preview') {
511-
if (!$matchingPublishedPackage.VersionPreview.Trim()) {
512-
LogWarning "Metadata is missing preview version for preview package $packageName. Keeping existing package."
513-
$outputPackages += $package
514-
continue
515-
}
516-
$packageVersion = "==$($matchingPublishedPackage.VersionPreview)"
517-
}
518-
519-
# If upgrading the package, run basic sanity checks against the package
520-
if ($package.package_info.version -ne $packageVersion) {
521-
Write-Host "New version detected for $packageName ($packageVersion)"
522-
if (!(ValidatePackage -packageName $packageName -packageVersion $packageVersion -PackageSourceOverride $PackageSourceOverride -DocValidationImageId $DocValidationImageId)) {
523-
LogWarning "Package is not valid: $packageName. Keeping old version."
524-
$outputPackages += $package
525-
continue
526-
}
527-
528-
$package.package_info = Add-Member `
529-
-InputObject $package.package_info `
530-
-MemberType NoteProperty `
531-
-Name 'version' `
532-
-Value $packageVersion `
533-
-PassThru `
534-
-Force
535-
if ($PackageSourceOverride) {
536-
$package.package_info = Add-Member `
537-
-InputObject $package.package_info `
538-
-MemberType NoteProperty `
539-
-Name 'extra_index_url' `
540-
-Value $PackageSourceOverride `
541-
-PassThru `
542-
-Force
543-
}
544-
}
545-
546-
Write-Host "Keeping tracked package: $packageName."
547-
$outputPackages += $package
548-
}
549-
550-
$outputPackagesHash = @{}
551-
foreach ($package in $outputPackages) {
552-
# In some cases there is no $package.package_info.name, only hash if the
553-
# name is set.
554-
if ($package.package_info.name) {
555-
$outputPackagesHash[$package.package_info.name] = $true
556-
}
557-
}
558-
559-
$remainingPackages = @()
560-
if ($Mode -eq 'preview') {
561-
$remainingPackages = $DocsMetadata.Where({
562-
$_.VersionPreview.Trim() `
563-
-and !$outputPackagesHash.ContainsKey($_.Package) `
564-
-and !$_.Package.EndsWith("-nspkg")
565-
})
566-
} else {
567-
$remainingPackages = $DocsMetadata.Where({
568-
$_.VersionGA.Trim() `
569-
-and !$outputPackagesHash.ContainsKey($_.Package) `
570-
-and !$_.Package.EndsWith("-nspkg")
571-
})
572-
}
573-
574-
# Add packages that exist in the metadata but are not onboarded in docs config
575-
foreach ($package in $remainingPackages) {
576-
$packageName = $package.Package
577-
$packageVersion = "==$($package.VersionGA)"
578-
if ($Mode -eq 'preview') {
579-
$packageVersion = "==$($package.VersionPreview)"
580-
}
581-
if (!(ValidatePackage -packageName $packageName -packageVersion $packageVersion -PackageSourceOverride $PackageSourceOverride -DocValidationImageId $DocValidationImageId)) {
582-
LogWarning "Package is not valid: $packageName. Cannot onboard."
583-
continue
584-
}
585-
586-
Write-Host "Add new package from metadata: $packageName"
587-
if ($PackageSourceOverride) {
588-
$package = [ordered]@{
589-
package_info = [ordered]@{
590-
name = $packageName;
591-
install_type = 'pypi';
592-
prefer_source_distribution = 'true';
593-
version = $packageVersion;
594-
extra_index_url = $PackageSourceOverride
595-
};
596-
exclude_path = @("test*","example*","sample*","doc*");
597-
}
598-
} else {
599-
$package = [ordered]@{
600-
package_info = [ordered]@{
601-
name = $packageName;
602-
install_type = 'pypi';
603-
prefer_source_distribution = 'true';
604-
version = $packageVersion;
605-
};
606-
exclude_path = @("test*","example*","sample*","doc*");
607-
}
608-
}
609-
$outputPackages += $package
610-
}
611-
612-
$packageConfig.packages = $outputPackages
613-
$packageConfig | ConvertTo-Json -Depth 100 | Set-Content $DocConfigFile
614-
Write-Host "Onboarding configuration written to: $DocConfigFile"
615-
}
616-
617289
# function is used to auto generate API View
618290
function Find-python-Artifacts-For-Apireview($artifactDir, $artifactName)
619291
{

0 commit comments

Comments
 (0)