Skip to content

Commit 1c83dd4

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 2847 (Azure#27670)
* Add extra group conditions, template consolidation * Module fixes. Enable provisioner identity permissions via opensource api. Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 9eb6bda commit 1c83dd4

File tree

3 files changed

+46
-23
lines changed

3 files changed

+46
-23
lines changed

eng/common/scripts/Helpers/Metadata-Helpers.ps1

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
1+
function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
22
{
33
$LoginAPIBaseURI = "https://login.microsoftonline.com/$TenantId/oauth2/token"
44

55
$headers = @{
66
"content-type" = "application/x-www-form-urlencoded"
77
}
8-
8+
99
$body = @{
1010
"grant_type" = "client_credentials"
1111
"client_id" = $ClientId
@@ -17,8 +17,9 @@ function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
1717
return $resp.access_token
1818
}
1919

20-
function GetMsAliasFromGithub ($TenantId, $ClientId, $ClientSecret, $GithubUser)
20+
function GetMsAliasFromGithub ([string]$TenantId, [string]$ClientId, [string]$ClientSecret, [string]$GithubUser)
2121
{
22+
# API documentation (out of date): https://github.com/microsoft/opensource-management-portal/blob/main/docs/api.md
2223
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links/github/$GithubUser"
2324

2425
$Headers = @{
@@ -31,8 +32,7 @@ function GetMsAliasFromGithub ($TenantId, $ClientId, $ClientSecret, $GithubUser)
3132
$Headers["Authorization"] = "Bearer $opsAuthToken"
3233
Write-Host "Fetching aad identity for github user: $GithubUser"
3334
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers -MaximumRetryCount 3
34-
}
35-
catch {
35+
} catch {
3636
Write-Warning $_
3737
return $null
3838
}
@@ -47,7 +47,30 @@ function GetMsAliasFromGithub ($TenantId, $ClientId, $ClientSecret, $GithubUser)
4747
return $null
4848
}
4949

50-
function GetPrimaryCodeOwner ($TargetDirectory)
50+
function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$ClientSecret)
51+
{
52+
# API documentation (out of date): https://github.com/microsoft/opensource-management-portal/blob/main/docs/api.md
53+
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links"
54+
55+
$Headers = @{
56+
"Content-Type" = "application/json"
57+
"api-version" = "2019-10-01"
58+
}
59+
60+
try {
61+
$opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
62+
$Headers["Authorization"] = "Bearer $opsAuthToken"
63+
Write-Host "Fetching all github alias links"
64+
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers -MaximumRetryCount 3
65+
} catch {
66+
Write-Warning $_
67+
return $null
68+
}
69+
70+
return $resp
71+
}
72+
73+
function GetPrimaryCodeOwner ([string]$TargetDirectory)
5174
{
5275
$codeOwnerArray = &"$PSScriptRoot/../get-codeowners.ps1" -TargetDirectory $TargetDirectory
5376
if ($codeOwnerArray) {

eng/common/scripts/Import-AzModules.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ param (
55

66
. (Join-Path $PSScriptRoot Helpers PSModule-Helpers.ps1)
77

8-
Install-ModuleIfNotInstalled "Az" $AzModuleVersion | Import-Module
8+
Install-ModuleIfNotInstalled "Az" $AzModuleVersion | Import-Module

eng/common/scripts/Update-DocsMsMetadata.ps1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Updates package README.md for publishing to docs.microsoft.com
44
55
.DESCRIPTION
66
Given a PackageInfo .json file, format the package README.md file with metadata
7-
and other information needed to release reference docs:
7+
and other information needed to release reference docs:
88
99
* Adjust README.md content to include metadata
10-
* Insert the package verison number in the README.md title
10+
* Insert the package verison number in the README.md title
1111
* Copy file to the appropriate location in the documentation repository
1212
* Copy PackageInfo .json file to the metadata location in the reference docs
1313
repository. This enables the Docs CI build to onboard packages which have not
@@ -18,7 +18,7 @@ List of locations of the artifact information .json file. This is usually stored
1818
in build artifacts under packages/PackageInfo/<package-name>.json. Can also be
1919
a single item.
2020
21-
.PARAMETER DocRepoLocation
21+
.PARAMETER DocRepoLocation
2222
Location of the root of the docs.microsoft.com reference doc location. Further
2323
path information is provided by $GetDocsMsMetadataForPackageFn
2424
@@ -47,7 +47,7 @@ param(
4747
[array]$PackageInfoJsonLocations,
4848

4949
[Parameter(Mandatory = $true)]
50-
[string]$DocRepoLocation,
50+
[string]$DocRepoLocation,
5151

5252
[Parameter(Mandatory = $true)]
5353
[string]$Language,
@@ -104,12 +104,12 @@ function GetAdjustedReadmeContent($ReadmeContent, $PackageInfo, $PackageMetadata
104104
$replacementPattern = "`${1}$tag"
105105
$ReadmeContent = $ReadmeContent -replace $releaseReplaceRegex, $replacementPattern
106106
}
107-
107+
108108
# Get the first code owners of the package.
109109
Write-Host "Retrieve the code owner from $($PackageInfo.DirectoryPath)."
110-
$author = GetPrimaryCodeOwner -TargetDirectory $PackageInfo.DirectoryPath
110+
$author = GetPrimaryCodeOwner -TargetDirectory $PackageInfo.DirectoryPath
111111
if (!$author) {
112-
$author = "ramya-rao-a"
112+
$author = "ramya-rao-a"
113113
$msauthor = "ramyar"
114114
}
115115
else {
@@ -148,10 +148,10 @@ function GetPackageInfoJson ($packageInfoJsonLocation) {
148148
$packageInfoJson = Get-Content $packageInfoJsonLocation -Raw
149149
$packageInfo = ConvertFrom-Json $packageInfoJson
150150
if ($packageInfo.DevVersion) {
151-
# If the package is of a dev version there may be language-specific needs to
152-
# specify the appropriate version. For example, in the case of JS, the dev
151+
# If the package is of a dev version there may be language-specific needs to
152+
# specify the appropriate version. For example, in the case of JS, the dev
153153
# version is always 'dev' when interacting with NPM.
154-
if ($GetDocsMsDevLanguageSpecificPackageInfoFn -and (Test-Path "Function:$GetDocsMsDevLanguageSpecificPackageInfoFn")) {
154+
if ($GetDocsMsDevLanguageSpecificPackageInfoFn -and (Test-Path "Function:$GetDocsMsDevLanguageSpecificPackageInfoFn")) {
155155
$packageInfo = &$GetDocsMsDevLanguageSpecificPackageInfoFn $packageInfo
156156
} else {
157157
# Default: use the dev version from package info as the version for
@@ -162,16 +162,16 @@ function GetPackageInfoJson ($packageInfoJsonLocation) {
162162
return $packageInfo
163163
}
164164

165-
function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo) {
165+
function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo) {
166166
$originalVersion = [AzureEngSemanticVersion]::ParseVersionString($packageInfo.Version)
167167
$packageMetadataArray = (Get-CSVMetadata).Where({ $_.Package -eq $packageInfo.Name -and $_.Hide -ne 'true' -and $_.New -eq 'true' })
168168
if ($packageInfo.Group) {
169169
$packageMetadataArray = ($packageMetadataArray).Where({$_.GroupId -eq $packageInfo.Group})
170170
}
171-
if ($packageMetadataArray.Count -eq 0) {
171+
if ($packageMetadataArray.Count -eq 0) {
172172
LogWarning "Could not retrieve metadata for $($packageInfo.Name) from metadata CSV. Using best effort defaults."
173173
$packageMetadata = $null
174-
} elseif ($packageMetadataArray.Count -gt 1) {
174+
} elseif ($packageMetadataArray.Count -gt 1) {
175175
LogWarning "Multiple metadata entries for $($packageInfo.Name) in metadata CSV. Using first entry."
176176
$packageMetadata = $packageMetadataArray[0]
177177
} else {
@@ -199,10 +199,10 @@ function UpdateDocsMsMetadataForPackage($packageInfoJsonLocation, $packageInfo)
199199
Write-Warning "$($packageInfo.Name) does not have Readme file. Skipping update readme."
200200
return
201201
}
202-
202+
203203
$readmeContent = Get-Content $packageInfo.ReadMePath -Raw
204-
$outputReadmeContent = ""
205-
if ($readmeContent) {
204+
$outputReadmeContent = ""
205+
if ($readmeContent) {
206206
$outputReadmeContent = GetAdjustedReadmeContent $readmeContent $packageInfo $packageMetadata
207207
}
208208

0 commit comments

Comments
 (0)