Sync eng/common directory with azure-sdk-tools for PR 7040 (#27300)

Sync eng/common directory with azure-sdk-tools for PR
https://github.com/Azure/azure-sdk-tools/pull/7040 See [eng/common
workflow](https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/README.md#workflow)

---------

Co-authored-by: Daniel Jurek <djurek@microsoft.com>
This commit is contained in:
Azure SDK Bot 2023-10-02 14:58:30 -07:00 коммит произвёл GitHub
Родитель f8ecc50858
Коммит 28cbcd053d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 75 добавлений и 295 удалений

Просмотреть файл

@ -100,10 +100,7 @@ steps:
-Language '${{parameters.Language}}' `
-RepoId '${{ parameters.RepoId }}' `
-DocValidationImageId '${{ parameters.DocValidationImageId }}' `
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}' `
-TenantId '$(opensource-aad-tenant-id)' `
-ClientId '$(opensource-aad-app-id)' `
-ClientSecret '$(opensource-aad-secret)'
-PackageSourceOverride '${{ parameters.PackageSourceOverride }}'
displayName: Apply Documentation Updates
- template: /eng/common/pipelines/templates/steps/git-push-changes.yml

Просмотреть файл

@ -17,36 +17,6 @@ function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
return $resp.access_token
}
function GetMsAliasFromGithub ([string]$TenantId, [string]$ClientId, [string]$ClientSecret, [string]$GithubUser)
{
# API documentation (out of date): https://github.com/microsoft/opensource-management-portal/blob/main/docs/api.md
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubUser"
$Headers = @{
"Content-Type" = "application/json"
"api-version" = "2019-10-01"
}
try {
$opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
$Headers["Authorization"] = "Bearer $opsAuthToken"
Write-Host "Fetching aad identity for github user: $GithubUser"
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers -MaximumRetryCount 3
} catch {
Write-Warning $_
return $null
}
$resp | Write-Verbose
if ($resp.aad) {
Write-Host "Fetched aad identity $($resp.aad.alias) for github user $GithubUser. "
return $resp.aad.alias
}
Write-Warning "Failed to retrieve the aad identity from given github user: $GithubName"
return $null
}
function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$ClientSecret)
{
# API documentation (out of date): https://github.com/microsoft/opensource-management-portal/blob/main/docs/api.md
@ -70,17 +40,6 @@ function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$Clien
return $resp
}
function GetPrimaryCodeOwner ([string]$TargetDirectory)
{
$codeOwnerArray = &"$PSScriptRoot/../get-codeowners.ps1" -TargetDirectory $TargetDirectory
if ($codeOwnerArray) {
Write-Host "Code Owners are $codeOwnerArray."
return $codeOwnerArray[0]
}
Write-Warning "No code owner found in $TargetDirectory."
return $null
}
function GetDocsMsService($packageInfo, $serviceName)
{
$service = $serviceName.ToLower().Replace(' ', '').Replace('/', '-')
@ -109,8 +68,13 @@ function compare-and-merge-metadata ($original, $updated) {
return $updateMetdata
}
function GenerateDocsMsMetadata($originalMetadata, $language, $languageDisplayName, $serviceName, $author, $msAuthor, $msService)
{
function GenerateDocsMsMetadata(
$originalMetadata,
$language,
$languageDisplayName,
$serviceName,
$msService
) {
$langTitle = "Azure $serviceName SDK for $languageDisplayName"
$langDescription = "Reference for Azure $serviceName SDK for $languageDisplayName"
$date = Get-Date -Format "MM/dd/yyyy"
@ -118,9 +82,7 @@ function GenerateDocsMsMetadata($originalMetadata, $language, $languageDisplayNa
$metadataTable = [ordered]@{
"title"= $langTitle
"description"= $langDescription
"author"= $author
"ms.author"= $msauthor
"ms.data"= $date
"ms.date"= $date
"ms.topic"= "reference"
"ms.devlang"= $language
"ms.service"= $msService

Просмотреть файл

@ -1,6 +1,13 @@
function create-service-readme($readmeFolder, $readmeName, $moniker, $msService, $indexTableLink, $serviceName, $author, $msAuthor)
{
function create-service-readme(
$readmeFolder,
$readmeName,
$moniker,
$msService,
$indexTableLink,
$serviceName
) {
$readmePath = Join-Path $readmeFolder -ChildPath $readmeName
$content = ""
if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) {
@ -13,8 +20,12 @@ function create-service-readme($readmeFolder, $readmeName, $moniker, $msService,
}
# Generate the front-matter for docs needs
# $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1
$metadataString = GenerateDocsMsMetadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName `
-author $author -msAuthor $msAuthor -msService $msService
$metadataString = GenerateDocsMsMetadata `
-language $Language `
-languageDisplayName $LanguageDisplayName `
-serviceName $serviceName `
-msService $msService
Add-Content -Path $readmePath -Value $metadataString -NoNewline
# Add tables, conbined client and mgmt together.
@ -34,9 +45,15 @@ function update-metadata-table($readmeFolder, $readmeName, $serviceName, $msServ
$restContent = $Matches["content"].trim()
$metadata = $Matches["metadata"].trim()
}
# $Language, $LanguageDisplayName are the variables globally defined in Language-Settings.ps1
$metadataString = GenerateDocsMsMetadata -originalMetadata $metadata -language $Language -languageDisplayName $LanguageDisplayName -serviceName $serviceName `
-author $author -msAuthor $msAuthor -msService $msService
$metadataString = GenerateDocsMsMetadata `
-originalMetadata $metadata `
-language $Language `
-languageDisplayName $LanguageDisplayName `
-serviceName $serviceName `
-msService $msService
Set-Content -Path $readmePath -Value "$metadataString$restContent" -NoNewline
}
@ -72,19 +89,41 @@ function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $mon
}
}
function generate-service-level-readme($docRepoLocation, $readmeBaseName, $pathPrefix, $packageInfos, $serviceName, $moniker, $author, $msAuthor, $msService) {
function generate-service-level-readme(
$docRepoLocation,
$readmeBaseName,
$pathPrefix,
$packageInfos,
$serviceName,
$moniker,
$msService
) {
$readmeFolder = "$docRepoLocation/$pathPrefix/$moniker/"
$serviceReadme = "$readmeBaseName.md"
$indexReadme = "$readmeBaseName-index.md"
if ($packageInfos) {
generate-markdown-table -readmeFolder $readmeFolder -readmeName $indexReadme -packageInfos $packageInfos -moniker $moniker
generate-markdown-table `
-readmeFolder $readmeFolder `
-readmeName $indexReadme `
-packageInfos $packageInfos `
-moniker $moniker
}
if (!(Test-Path "$readmeFolder$serviceReadme") -and $packageInfos) {
create-service-readme -readmeFolder $readmeFolder -readmeName $serviceReadme -moniker $moniker -msService $msService `
-indexTableLink $indexReadme -serviceName $serviceName -author $author -msAuthor $msAuthor
}
elseif (Test-Path "$readmeFolder$serviceReadme") {
update-metadata-table -readmeFolder $readmeFolder -readmeName $serviceReadme -serviceName $serviceName `
-msService $msService -author $author -msAuthor $msAuthor
create-service-readme `
-readmeFolder $readmeFolder `
-readmeName $serviceReadme `
-moniker $moniker `
-msService $msService `
-indexTableLink $indexReadme `
-serviceName $serviceName
} elseif (Test-Path "$readmeFolder$serviceReadme") {
update-metadata-table `
-readmeFolder $readmeFolder `
-readmeName $serviceReadme `
-serviceName $serviceName `
-msService $msService
}
}

Просмотреть файл

@ -13,15 +13,6 @@ Generate missing service level readme and updating metadata of the existing ones
Location of the documentation repo. This repo may be sparsely checked out
depending on the requirements for the domain
.PARAMETER TenantId
The aad tenant id/object id for ms.author.
.PARAMETER ClientId
The add client id/application id for ms.author.
.PARAMETER ClientSecret
The client secret of add app for ms.author.
.PARAMETER ReadmeFolderRoot
The readme folder root path, use default value here for backward compability. E.g. docs-ref-services in Java, JS, Python, api/overview/azure
#>
@ -30,15 +21,6 @@ param(
[Parameter(Mandatory = $true)]
[string] $DocRepoLocation,
[Parameter(Mandatory = $false)]
[string]$TenantId,
[Parameter(Mandatory = $false)]
[string]$ClientId,
[Parameter(Mandatory = $false)]
[string]$ClientSecret,
[Parameter(Mandatory = $false)]
[string]$ReadmeFolderRoot = "docs-ref-services",
@ -132,26 +114,17 @@ foreach($moniker in $Monikers) {
Write-Host "Building service: $service"
$servicePackages = $packagesForService.Values.Where({ $_.ServiceName -eq $service })
$serviceReadmeBaseName = ServiceLevelReadmeNameStyle -serviceName $service
# Github url for source code: e.g. https://github.com/Azure/azure-sdk-for-js
$serviceBaseName = ServiceLevelReadmeNameStyle $service
$author = GetPrimaryCodeOwner -TargetDirectory "/sdk/$serviceBaseName/"
$msauthor = ""
if (!$author) {
LogError "Cannot fetch the author from CODEOWNER file."
$author = ""
}
elseif ($TenantId -and $ClientId -and $ClientSecret) {
$msauthor = GetMsAliasFromGithub -TenantId $tenantId -ClientId $clientId -ClientSecret $clientSecret -GithubUser $author
}
# Default value
if (!$msauthor) {
LogError "No ms.author found for $author. "
$msauthor = $author
}
# Add ability to override
# Fetch the service readme name
$msService = GetDocsMsService -packageInfo $servicePackages[0] -serviceName $service
generate-service-level-readme -docRepoLocation $DocRepoLocation -readmeBaseName $serviceReadmeBaseName -pathPrefix $ReadmeFolderRoot `
-packageInfos $servicePackages -serviceName $service -moniker $moniker -author $author -msAuthor $msauthor -msService $msService
generate-service-level-readme `
-docRepoLocation $DocRepoLocation `
-readmeBaseName $serviceReadmeBaseName `
-pathPrefix $ReadmeFolderRoot `
-packageInfos $servicePackages `
-serviceName $service `
-moniker $moniker `
-msService $msService
}
}

Просмотреть файл

@ -32,14 +32,6 @@ GitHub repository ID of the SDK. Typically of the form: 'Azure/azure-sdk-for-js'
The docker image id in format of '$containerRegistry/$imageName:$tag'
e.g. azuresdkimages.azurecr.io/jsrefautocr:latest
.PARAMETER TenantId
The aad tenant id/object id.
.PARAMETER ClientId
The add client id/application id.
.PARAMETER ClientSecret
The client secret of add app.
#>
param(
@ -59,16 +51,7 @@ param(
[string]$DocValidationImageId,
[Parameter(Mandatory = $false)]
[string]$PackageSourceOverride,
[Parameter(Mandatory = $false)]
[string]$TenantId,
[Parameter(Mandatory = $false)]
[string]$ClientId,
[Parameter(Mandatory = $false)]
[string]$ClientSecret
[string]$PackageSourceOverride
)
Set-StrictMode -Version 3
. (Join-Path $PSScriptRoot common.ps1)
@ -105,28 +88,10 @@ function GetAdjustedReadmeContent($ReadmeContent, $PackageInfo, $PackageMetadata
$ReadmeContent = $ReadmeContent -replace $releaseReplaceRegex, $replacementPattern
}
# Get the first code owners of the package.
Write-Host "Retrieve the code owner from $($PackageInfo.DirectoryPath)."
$author = GetPrimaryCodeOwner -TargetDirectory $PackageInfo.DirectoryPath
if (!$author) {
$author = "ramya-rao-a"
$msauthor = "ramyar"
}
else {
$msauthor = GetMsAliasFromGithub -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret -GithubUser $author
}
# Default value
if (!$msauthor) {
$msauthor = $author
}
Write-Host "The author of package: $author"
Write-Host "The ms author of package: $msauthor"
$header = @"
---
title: $foundTitle
keywords: Azure, $Language, SDK, API, $($PackageInfo.Name), $service
author: $author
ms.author: $msauthor
ms.date: $date
ms.topic: reference
ms.devlang: $Language

Просмотреть файл

@ -1,138 +0,0 @@
function Get-CodeownersTool([string] $ToolPath, [string] $DevOpsFeed, [string] $ToolVersion)
{
$codeownersToolCommand = Join-Path $ToolPath "retrieve-codeowners"
Write-Host "Checking for retrieve-codeowners in $ToolPath ..."
# Check if the retrieve-codeowners tool exists or not.
if (Get-Command $codeownersToolCommand -errorAction SilentlyContinue) {
return $codeownersToolCommand
}
if (!(Test-Path $ToolPath)) {
New-Item -ItemType Directory -Path $ToolPath | Out-Null
}
Write-Host "Installing the retrieve-codeowners tool under tool path: $ToolPath ..."
# Run command under tool path to avoid dotnet tool install command checking .csproj files.
# This is a bug for dotnet tool command. Issue: https://github.com/dotnet/sdk/issues/9623
Push-Location $ToolPath
Write-Host "Executing: dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion"
dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null
Pop-Location
# Test to see if the tool properly installed.
if (!(Get-Command $codeownersToolCommand -errorAction SilentlyContinue)) {
Write-Error "The retrieve-codeowners tool is not properly installed. Please check your tool path: $ToolPath"
return
}
return $codeownersToolCommand
}
<#
.SYNOPSIS
A function that given as input $TargetPath param, returns the owners
of that path, as determined by CODEOWNERS file passed in $CodeownersFileLocation
param.
.PARAMETER TargetPath
Required*. Path to file or directory whose owners are to be determined from a
CODEOWNERS file. e.g. sdk/core/azure-amqp/ or sdk/core/foo.txt.
*for backward compatibility, you might provide $TargetDirectory instead.
.PARAMETER TargetDirectory
Obsolete. Replaced by $TargetPath. Kept for backward-compatibility.
If both $TargetPath and $TargetDirectory are provided, $TargetDirectory is
ignored.
.PARAMETER CodeownersFileLocation
Optional. An absolute path to the CODEOWNERS file against which the $TargetPath param
will be checked to determine its owners.
.PARAMETER ToolVersion
Optional. The NuGet package version of the package containing the "retrieve-codeowners"
tool, around which this script is a wrapper.
.PARAMETER ToolPath
Optional. The place to check the "retrieve-codeowners" tool existence.
.PARAMETER DevOpsFeed
Optional. The NuGet package feed from which the "retrieve-codeowners" tool is to be installed.
NuGet feed:
https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/Azure.Sdk.Tools.RetrieveCodeOwners
Pipeline publishing the NuGet package to the feed, "tools - code-owners-parser":
https://dev.azure.com/azure-sdk/internal/_build?definitionId=3188
.PARAMETER VsoVariable
Optional. If provided, the determined owners, based on $TargetPath matched against CODEOWNERS file at $CodeownersFileLocation,
will be output to Azure DevOps pipeline log as variable named $VsoVariable.
Reference:
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch
https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#logging-command-format
.PARAMETER IncludeNonUserAliases
Optional. Whether to include in the returned owners list aliases that are team aliases, e.g. Azure/azure-sdk-team
.PARAMETER Test
Optional. Whether to run the script against hard-coded tests.
#>
function Get-Codeowners(
[string] $TargetPath,
[string] $TargetDirectory,
[string] $ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool"),
[string] $DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json",
[string] $ToolVersion = "1.0.0-dev.20230629.2",
[string] $VsoVariable = "",
[string] $CodeownersFileLocation = "",
[switch] $IncludeNonUserAliases
)
{
if ([string]::IsNullOrWhiteSpace($CodeownersFileLocation)) {
# The $PSScriptRoot is assumed to be azure-sdk-tools/eng/common/scripts/get-codeowners.ps1
$CodeownersFileLocation = (Resolve-Path $PSScriptRoot/../../../.github/CODEOWNERS)
}
# Backward compatibility: if $TargetPath is not provided, fall-back to the legacy $TargetDirectory
if ([string]::IsNullOrWhiteSpace($TargetPath)) {
$TargetPath = $TargetDirectory
}
if ([string]::IsNullOrWhiteSpace($TargetPath)) {
Write-Error "TargetPath (or TargetDirectory) parameter must be neither null nor whitespace."
return ,@()
}
$jsonOutputFile = New-TemporaryFile
$codeownersToolCommand = Get-CodeownersTool -ToolPath $ToolPath -DevOpsFeed $DevOpsFeed -ToolVersion $ToolVersion
Write-Host "Executing: & $codeownersToolCommand --target-path $TargetPath --codeowners-file-path-or-url $CodeownersFileLocation --exclude-non-user-aliases:$(!$IncludeNonUserAliases) --owners-data-output-file $jsonOutputFile"
$commandOutput = & $codeownersToolCommand `
--target-path $TargetPath `
--codeowners-file-path-or-url $CodeownersFileLocation `
--exclude-non-user-aliases:$(!$IncludeNonUserAliases) `
--owners-data-output-file $jsonOutputFile `
2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Command $codeownersToolCommand execution failed (exit code = $LASTEXITCODE). Output string: $commandOutput"
return ,@()
} else
{
Write-Host "Command $codeownersToolCommand executed successfully (exit code = 0). Command output string length: $($commandOutput.length)"
}
# Assert: $commandOutput is a valid JSON representing:
# - a single CodeownersEntry, if the $TargetPath was a single path
# - or a dictionary of CodeownerEntries, keyes by each path resolved from a $TargetPath glob path.
#
# For implementation details, see Azure.Sdk.Tools.RetrieveCodeOwners.Program.Main
$fileContents = Get-Content $jsonOutputFile -Raw
$codeownersJson = ConvertFrom-Json -InputObject $fileContents
if ($VsoVariable) {
$codeowners = $codeownersJson.Owners -join ","
Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeowners"
}
return ,@($codeownersJson.Owners)
}

Просмотреть файл

@ -1,18 +0,0 @@
<#
.SYNOPSIS
Please see the comment on Get-Codeowners defined in ./get-codeowners.lib.ps1
#>
param (
[string] $TargetPath = "",
[string] $TargetDirectory = "",
[string] $CodeownersFileLocation = "",
[switch] $IncludeNonUserAliases
)
. $PSScriptRoot/get-codeowners.lib.ps1
return Get-Codeowners `
-TargetPath $TargetPath `
-TargetDirectory $TargetDirectory `
-CodeownersFileLocation $CodeownersFileLocation `
-IncludeNonUserAliases:$IncludeNonUserAliases