Sync eng/common directory with azure-sdk-tools for PR 2093 (#2984)
* Consume Codeowners parser library, ceperate users from teams in codeownerse * Update get-pr-owners and related logic Co-authored-by: Chidozie Ononiwu <chononiw@microsoft.com>
This commit is contained in:
parent
dcc6f12c20
commit
24b34875ff
@ -1,16 +1,30 @@
|
||||
parameters:
|
||||
TargetVariable: ''
|
||||
TargetUserVariable: 'notspecified'
|
||||
TargetTeamVariable: 'notspecified'
|
||||
TargetLabelVariable: 'notspecified'
|
||||
ServiceDirectory: ''
|
||||
DevOpsFeed: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"
|
||||
|
||||
steps:
|
||||
- pwsh: |
|
||||
git clone https://github.com/Azure/azure-sdk-tools.git $(Build.SourcesDirectory)/tools_repo
|
||||
cd $(Build.SourcesDirectory)/tools_repo
|
||||
git checkout azure-sdk-tools_20210114.1
|
||||
displayName: Setup Identity Resolver
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: 'Install Identity Resolver'
|
||||
inputs:
|
||||
command: custom
|
||||
custom: 'tool'
|
||||
arguments: 'install --global --add-source "${{ parameters.DevOpsFeed }}" --version "1.0.0-dev.20211018.1" "Azure.Sdk.Tools.IdentityResolver"'
|
||||
workingDirectory: '$(Agent.BuildDirectory)'
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: 'Install CodeOwners Retriever'
|
||||
inputs:
|
||||
command: custom
|
||||
custom: 'tool'
|
||||
arguments: 'install --global --add-source "${{ parameters.DevOpsFeed }}" --version "1.0.0-dev.20211019.1" "Azure.Sdk.Tools.RetrieveCodeOwners"'
|
||||
workingDirectory: '$(Agent.BuildDirectory)'
|
||||
|
||||
- pwsh: |
|
||||
dotnet run -v q -- `
|
||||
identity-resolver `
|
||||
--aad-app-id-var APP_ID `
|
||||
--aad-app-secret-var APP_SECRET `
|
||||
--aad-tenant-var AAD_TENANT `
|
||||
@ -19,10 +33,9 @@ steps:
|
||||
--kusto-table-var KUSTO_TABLE `
|
||||
--identity-name "$(Build.QueuedBy)" `
|
||||
--identity-email "$(Build.RequestedForEmail)" `
|
||||
--targetvar "${{ parameters.TargetVariable }}"
|
||||
--targetvar "${{ coalesce(parameters.TargetVariable, parameters.TargetUserVariable) }}"
|
||||
displayName: 'Resolving Queuing User'
|
||||
continueOnError: true
|
||||
workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver
|
||||
env:
|
||||
APP_ID: $(notification-aad-app-id)
|
||||
APP_SECRET: $(notification-aad-secret)
|
||||
@ -32,15 +45,10 @@ steps:
|
||||
KUSTO_TABLE: $(notification-kusto-table)
|
||||
|
||||
- pwsh: |
|
||||
Remove-Item -Force -Recurse $(Build.SourcesDirectory)/tools_repo
|
||||
displayName: Clean Up Cloned Tools Repo
|
||||
|
||||
- task: PowerShell@2
|
||||
displayName: Add CodeOwners if Present
|
||||
inputs:
|
||||
pwsh: true
|
||||
filePath: $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1
|
||||
arguments: >
|
||||
-TargetDirectory "/sdk/${{ parameters.ServiceDirectory }}/"
|
||||
-RootDirectory "$(Build.SourcesDirectory)"
|
||||
-VsoVariable "${{ parameters.TargetVariable }}"
|
||||
retrieve-codeowners `
|
||||
--target-directory "/sdk/${{ parameters.ServiceDirectory }}/" `
|
||||
--root-directory "$(Build.SourcesDirectory)" `
|
||||
--vso-owning-users "${{ coalesce(parameters.TargetVariable, parameters.TargetUserVariable) }}" `
|
||||
--vso-owning-teams "${{ parameters.TargetTeamVariable }}" `
|
||||
--vso-owning-labels "${{ parameters.TargetLabelVariable }}"
|
||||
displayName: 'Add CodeOwners if Present'
|
||||
@ -1,50 +0,0 @@
|
||||
param (
|
||||
$TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus
|
||||
$RootDirectory, # ideally $(Build.SourcesDirectory)
|
||||
$VsoVariable = "" # target devops output variable
|
||||
)
|
||||
$target = $TargetDirectory.ToLower().Trim("/")
|
||||
$codeOwnersLocation = Join-Path $RootDirectory -ChildPath ".github/CODEOWNERS"
|
||||
$ownedFolders = @{}
|
||||
|
||||
if (!(Test-Path $codeOwnersLocation)) {
|
||||
Write-Host "Unable to find CODEOWNERS file in target directory $RootDirectory"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$codeOwnersContent = Get-Content $codeOwnersLocation
|
||||
|
||||
foreach ($contentLine in $codeOwnersContent) {
|
||||
if (-not $contentLine.StartsWith("#") -and $contentLine){
|
||||
$splitLine = $contentLine -split "\s+"
|
||||
|
||||
# CODEOWNERS file can also have labels present after the owner aliases
|
||||
# gh aliases start with @ in codeowners. don't pass on to API calls
|
||||
$ownedFolders[$splitLine[0].ToLower().Trim("/")] = ($splitLine[1..$($splitLine.Length)] `
|
||||
| ? { $_.StartsWith("@") } `
|
||||
| % { return $_.substring(1) }) -join ","
|
||||
}
|
||||
}
|
||||
|
||||
$results = $ownedFolders[$target]
|
||||
|
||||
if ($results) {
|
||||
Write-Host "Found a folder $results to match $target"
|
||||
|
||||
if ($VsoVariable) {
|
||||
$alreadyPresent = [System.Environment]::GetEnvironmentVariable($VsoVariable)
|
||||
|
||||
if ($alreadyPresent) {
|
||||
$results += ",$alreadyPresent"
|
||||
}
|
||||
Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results"
|
||||
}
|
||||
|
||||
return $results
|
||||
}
|
||||
else {
|
||||
Write-Host "Unable to match path $target in CODEOWNERS file located at $codeOwnersLocation."
|
||||
Write-Host ($ownedFolders | ConvertTo-Json)
|
||||
return ""
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user