From 729c1062e0345419c94a19bc56a1b4e54c6375d1 Mon Sep 17 00:00:00 2001 From: Azure PowerShell <65331932+azure-powershell-bot@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:41:29 +0800 Subject: [PATCH] Sync tools folder from main branch to generation branch (#24240) Co-authored-by: azurepowershell --- .azure-pipelines/code-sign.yml | 6 +- build.proj | 3 - .../{NewHelpIndex.ps1 => Docs/HelpIndex.ps1} | 27 +++--- tools/Docs/OutputTypeIndex.ps1 | 88 +++++++++++++++++++ tools/NewOutputTypeIndex.ps1 | 62 ------------- 5 files changed, 109 insertions(+), 77 deletions(-) rename tools/{NewHelpIndex.ps1 => Docs/HelpIndex.ps1} (80%) create mode 100644 tools/Docs/OutputTypeIndex.ps1 delete mode 100644 tools/NewOutputTypeIndex.ps1 diff --git a/.azure-pipelines/code-sign.yml b/.azure-pipelines/code-sign.yml index b27fc1cf0b33..d5665ea4889c 100644 --- a/.azure-pipelines/code-sign.yml +++ b/.azure-pipelines/code-sign.yml @@ -52,7 +52,6 @@ jobs: custom: msbuild arguments: 'build.proj /t:"Build;CopyAboutTopics;GenerateHelp" /p:"Configuration=Release;GenerateDocumentationFile=true;ModifiedModuleBuild=true"' - - task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0 displayName: 'Manifest Generator ' inputs: @@ -363,6 +362,11 @@ jobs: displayName: 'Repackage modules' condition: and(succeeded(), ne(variables['SignPsd1'], 'false')) + - pwsh: | + ./tools/Docs/OutputTypeIndex.ps1 -OutputFile ./artifacts/outputtypes.json -BuildConfig Release + ./tools/Docs/HelpIndex.ps1 -OutputFile ./artifacts/index.json -BuildConfig Release + displayName: 'Post process for Docs' + - task: PublishBuildArtifacts@1 displayName: 'Save artifacts' inputs: diff --git a/build.proj b/build.proj index aee57b037547..1b614ca84948 100644 --- a/build.proj +++ b/build.proj @@ -260,9 +260,6 @@ - - - diff --git a/tools/NewHelpIndex.ps1 b/tools/Docs/HelpIndex.ps1 similarity index 80% rename from tools/NewHelpIndex.ps1 rename to tools/Docs/HelpIndex.ps1 index 1c0c05a2b665..d251bf0dead3 100644 --- a/tools/NewHelpIndex.ps1 +++ b/tools/Docs/HelpIndex.ps1 @@ -28,10 +28,12 @@ param( [Parameter(Mandatory = $false)] [string] $BuildConfig = "Debug", [Parameter(Mandatory = $false)] - [string] $OutputFile = "$PSScriptRoot/index.json" + [string] $OutputFile = "$PSScriptRoot/../index.json" ) -Import-LocalizedData -BindingVariable "Azpsd1" -BaseDirectory $PSScriptRoot/Az -FileName "Az.psd1" +$ToolsRootPath = "$PSScriptRoot/.." + +Import-LocalizedData -BindingVariable "Azpsd1" -BaseDirectory $ToolsRootPath/Az -FileName "Az.psd1" if ([string]::isNullOrEmpty($Version)) { @@ -60,21 +62,24 @@ $output.Add("version", "$Version") $outputModules = @{} #Create mappings file -& "$PSScriptRoot/CreateMappings.ps1" -OutputFile $OutputFile/../groupMapping.json -WarningFile $OutputFile/../groupMappingWarnings.json +& "ToolsRootPath/CreateMappings.ps1" -OutputFile $OutputFile/../groupMapping.json -WarningFile $OutputFile/../groupMappingWarnings.json $labelMapping = Get-Content -Raw $OutputFile/../groupMapping.json | ConvertFrom-Json -$RMpsd1s = @() $HelpFolders = @() -$resourceManagerPath = "$PSScriptRoot/../artifacts/$BuildConfig/" - -$RMpsd1s += Get-ChildItem -Path $resourceManagerPath -Depth 1 | Where-Object { - $_.Name -like "*.psd1" -and $_.FullName -notlike "*dll-Help*" +$ProjectPaths = @( "ToolsRootPath/../src") +$RMpsd1s = $ProjectPaths | ForEach-Object { + Get-ChildItem -Path $_ -Filter "*.psd1" -Recurse | Where-Object { + $_.FullName -inotlike "*autorest*" -and ` + $_.FullName -inotlike "*extension*" -and ` + $_.FullName -notlike "*Debug*" -and ` + $_.FullName -notlike "*Netcore*" -and ` + $_.FullName -notlike "*dll-Help.psd1*" -and (-not [Tools.Common.Utilities.ModuleFilter]::IsAzureStackModule($_.FullName)) + } } -.($PSScriptRoot + "\PreloadToolDll.ps1") -$HelpFolders += Get-ChildItem -Path "$PSScriptRoot/../src" -Recurse -Directory | where { $_.Name -eq "help" -and (-not [Tools.Common.Utilities.ModuleFilter]::IsAzureStackModule($_.FullName)) -and $_.FullName -notlike "*\bin\*" -and (-not $_.Parent.BaseName.EndsWith(".Autorest", "CurrentCultureIgnoreCase"))} - +.($ToolsRootPath + "\PreloadToolDll.ps1") +$HelpFolders += Get-ChildItem -Path "$ToolsRootPath/../src" -Recurse -Directory | where { $_.Name -eq "help" -and (-not [Tools.Common.Utilities.ModuleFilter]::IsAzureStackModule($_.FullName)) -and $_.FullName -notlike "*\bin\*" -and (-not $_.Parent.BaseName.EndsWith(".Autorest", "CurrentCultureIgnoreCase"))} # Map the name of the cmdlet to the location of the help file $HelpFileMapping = @{} diff --git a/tools/Docs/OutputTypeIndex.ps1 b/tools/Docs/OutputTypeIndex.ps1 new file mode 100644 index 000000000000..1f56f984d316 --- /dev/null +++ b/tools/Docs/OutputTypeIndex.ps1 @@ -0,0 +1,88 @@ +# ---------------------------------------------------------------------------------- +# +# Copyright Microsoft Corporation +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------------- + +param( + [Parameter(Mandatory = $false)] + [string] $BuildConfig = "Release", + [Parameter(Mandatory = $false)] + [string] $OutputFile = "outputtypes.json" +) + +$ToolsRootPath = "$PSScriptRoot/.." +$AzPreviewPath = Get-Item $ToolsRootPath\AzPreview\AzPreview.psd1 +Import-LocalizedData -BindingVariable ModuleMetadata -BaseDirectory $AzPreviewPath.DirectoryName -FileName $AzPreviewPath.Name +$ModulePath = ($env:PSModulePath -split ';')[0] +$outputTypes = New-Object System.Collections.Generic.HashSet[string] +$jsonData = @() +$ProjectPaths = @( "$ToolsRootPath/../src" ) + +$ModuleManifestFile = $ProjectPaths | ForEach-Object { + Get-ChildItem -Path $_ -Filter "*.psd1" -Recurse | Where-Object { + $_.FullName -notlike "*autorest*" + } +} + +foreach ($item in $jsonData) { + $outputTypes.Add($item) | Out-Null +} + +$ReleaseRepository = "ReleaseRP" +Register-PSRepository -Name $ReleaseRepository -SourceLocation "$ToolsRootPath/../artifacts" -PackageManagementProvider Nuget -InstallationPolicy Trusted +Install-Module -Scope CurrentUser -Name AzPreview -Repository $ReleaseRepository -Force -AllowClobber + +$ModuleMetadata.RequiredModules | ForEach-Object { + $ModuleName = $_.ModuleName + $Version = $_.RequiredVersion + if ($Version -eq $null) + { + $Version = $_.ModuleVersion + } + $srcFile = $ModuleManifestFile | Where-Object {$_.Name -eq "$ModuleName.psd1"} + Import-LocalizedData -BindingVariable srcMetadata -BaseDirectory $srcFile.DirectoryName -FileName $srcFile.Name + $containsPsd1 = $srcMetadata.NestedModules | Where-Object { $_ -like "*.dll" } + $DestinationModulePath = [System.IO.Path]::Combine($ModulePath, $ModuleName, $Version) + $psd1Path = Join-Path -Path $DestinationModulePath -ChildPath "$ModuleName.psd1" + if (($containsPsd1.count -gt 0) -and (Test-Path $psd1Path)){ + Import-Module $Psd1Path -Force + $Module = Get-Module $ModuleName + foreach ($ModuleInfo in $Module.NestedModules){ + if ($srcMetadata.NestedModules -contains $ModuleInfo.Name+".dll") { + foreach ($Cmdlet in $ModuleInfo.ExportedCmdlets.Values) { + $OutputAttributeList = $Cmdlet.ImplementingType.GetTypeInfo().GetCustomAttributes([System.Management.Automation.OutputTypeAttribute], $true) + foreach ($OutputAttribute in $OutputAttributeList) + { + foreach ($OutputType in $OutputAttribute.Type) + { + $outputTypes.Add($OutputType.Name) | Out-Null + } + } + foreach ($Parameter in $Cmdlet.Parameters.Values){ + if ($Parameter.Attributes.TypeId.FullName -contains "System.Management.Automation.ParameterAttribute") { + if ($Parameter.ParameterType.FullName -like "*System.Nullable*``[``[*") + { + $outputTypes.Add(($Parameter.ParameterType.BaseType.FullName -replace "[][]", "")) | Out-Null + } + elseif ($Parameter.ParameterType.FullName -notlike "*``[``[*") + { + $outputTypes.Add(($Parameter.ParameterType.FullName -replace "[][]", "")) | Out-Null + } + } + } + } + } + } + } +} +$json = ConvertTo-Json $outputTypes +$json | Out-File "$OutputFile" \ No newline at end of file diff --git a/tools/NewOutputTypeIndex.ps1 b/tools/NewOutputTypeIndex.ps1 deleted file mode 100644 index 9f3223248ea8..000000000000 --- a/tools/NewOutputTypeIndex.ps1 +++ /dev/null @@ -1,62 +0,0 @@ -param( - [Parameter(Mandatory = $false)] - [string] $BuildConfig = "Debug", - [Parameter(Mandatory = $false)] - [string] $OutputFile = "$PSScriptRoot/outputtypes.json" -) - -# Get all psd1 files -$psd1Files = Get-Item $PSScriptRoot\..\artifacts\$BuildConfig\Az.*\Az.*.psd1 - -$profilePsd1 = $psd1Files | Where-Object {$_.Name -like "*Az.Accounts.psd1"} -Import-LocalizedData -BindingVariable "psd1File" -BaseDirectory $profilePsd1.DirectoryName -FileName $profilePsd1.Name -foreach ($nestedModule in $psd1File.RequiredAssemblies) -{ - $dllPath = Join-Path -Path $profilePsd1.DirectoryName -ChildPath $nestedModule - $Assembly = [Reflection.Assembly]::LoadFrom($dllPath) -} - -$outputTypes = New-Object System.Collections.Generic.HashSet[string] - -$psd1Files | ForEach { - Import-LocalizedData -BindingVariable "psd1File" -BaseDirectory $_.DirectoryName -FileName $_.Name - foreach ($nestedModule in $psd1File.NestedModules) - { - if('.dll' -ne [System.IO.Path]::GetExtension($nestedModule)) - { - continue; - } - $dllPath = Join-Path -Path $_.DirectoryName -ChildPath $nestedModule - $Assembly = [Reflection.Assembly]::LoadFrom($dllPath) - $exportedTypes = $Assembly.GetTypes() - foreach ($exportedType in $exportedTypes) - { - foreach ($attribute in $exportedType.CustomAttributes) - { - if ($attribute.AttributeType.Name -eq "OutputTypeAttribute") - { - $cmdletOutputTypes = $attribute.ConstructorArguments.Value.Value - foreach ($cmdletOutputType in $cmdletOutputTypes) - { - $outputTypes.Add($cmdletOutputType.FullName) | Out-Null - } - } - } - - foreach ($property in $exportedType.GetProperties() | Where-Object {$_.CustomAttributes.AttributeType.Name -contains "ParameterAttribute"}) - { - if ($property.PropertyType.FullName -like "*System.Nullable*``[``[*") - { - $outputTypes.Add(($property.PropertyType.BaseType.FullName -replace "[][]", "")) | Out-Null - } - elseif ($property.PropertyType.FullName -notlike "*``[``[*") - { - $outputTypes.Add(($property.PropertyType.FullName -replace "[][]", "")) | Out-Null - } - } - } - } -} - -$json = ConvertTo-Json $outputTypes -$json | Out-File "$OutputFile" \ No newline at end of file