Skip to content

Commit 3b93044

Browse files
committed
Delete redundant docs onboarding language from Language-Settings.ps1, move validation to Docs-Onboarding.ps1
1 parent 0fc263f commit 3b93044

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
@@ -131,6 +131,8 @@ function Get-python-PackageInfoFromPackageFile ($pkg, $workingDirectory)
131131
}
132132

133133
# This is the GetDocsMsDevLanguageSpecificPackageInfoFn implementation
134+
# Defined in common.ps1 as:
135+
# $GetDocsMsDevLanguageSpecificPackageInfoFn = "Get-${Language}-DocsMsDevLanguageSpecificPackageInfo"
134136
function Get-python-DocsMsDevLanguageSpecificPackageInfo($packageInfo, $packageSourceOverride) {
135137
# If the default namespace isn't in the package info then it needs to be added
136138
# Can't check if (!$packageInfo.Namespaces) in strict mode because Namespaces won't exist
@@ -211,336 +213,6 @@ function Get-python-GithubIoDocIndex()
211213
GenerateDocfxTocContent -tocContent $tocContent -lang "Python" -campaignId "UA-62780441-36"
212214
}
213215

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

0 commit comments

Comments
 (0)