Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 7040 (#1620)
Browse files Browse the repository at this point in the history
* Remove codeowners resolution logic from docs scripts

* Remove parameters that aren't needed

* Remove auth information from update-docsms-metadata.yml

---------

Co-authored-by: Daniel Jurek <[email protected]>
azure-sdk and danieljurek authored Oct 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent aeba6a7 commit 14ed453
Showing 7 changed files with 75 additions and 295 deletions.
Original file line number Diff line number Diff line change
@@ -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
54 changes: 8 additions & 46 deletions eng/common/scripts/Helpers/Metadata-Helpers.ps1
Original file line number Diff line number Diff line change
@@ -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,18 +68,21 @@ 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"

$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
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@

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 = ""
$content = ""
if (Test-Path (Join-Path $readmeFolder -ChildPath $indexTableLink)) {
$content = "## Packages - $moniker`r`n"
$content += "[!INCLUDE [packages]($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,14 +45,20 @@ 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
}

function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $moniker) {
$tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n"
$tableHeader = "| Reference | Package | Source |`r`n|---|---|---|`r`n"
$tableContent = ""
$packageInfos = $packageInfos | Sort-Object -Property Type,Package
# Here is the table, the versioned value will
@@ -54,7 +71,7 @@ function generate-markdown-table($readmeFolder, $readmeName, $packageInfos, $mon
if (Test-Path "Function:$GetPackageLevelReadmeFn") {
$packageLevelReadme = &$GetPackageLevelReadmeFn -packageMetadata $pkg
}

$referenceLink = "[$($pkg.DisplayName)]($packageLevelReadme-readme.md)"
if (!(Test-Path (Join-Path $readmeFolder -ChildPath "$packageLevelReadme-readme.md"))) {
$referenceLink = $pkg.DisplayName
@@ -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
}
}
45 changes: 9 additions & 36 deletions eng/common/scripts/Service-Level-Readme-Automation.ps1
Original file line number Diff line number Diff line change
@@ -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
}
}
37 changes: 1 addition & 36 deletions eng/common/scripts/Update-DocsMsMetadata.ps1
Original file line number Diff line number Diff line change
@@ -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
138 changes: 0 additions & 138 deletions eng/common/scripts/get-codeowners.lib.ps1

This file was deleted.

18 changes: 0 additions & 18 deletions eng/common/scripts/get-codeowners.ps1

This file was deleted.

0 comments on commit 14ed453

Please sign in to comment.