Skip to content

Commit 6a87430

Browse files
Updates for Codeowneers changes (#21084)
Co-authored-by: James Suplizio <[email protected]>
1 parent 37c37a6 commit 6a87430

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

eng/common/scripts/get-codeowners.lib.ps1

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function Get-CodeownersTool([string] $ToolPath, [string] $DevOpsFeed, [string] $ToolVersion)
22
{
33
$codeownersToolCommand = Join-Path $ToolPath "retrieve-codeowners"
4+
Write-Host "Checking for retrieve-codeowners in $ToolPath ..."
45
# Check if the retrieve-codeowners tool exists or not.
56
if (Get-Command $codeownersToolCommand -errorAction SilentlyContinue) {
67
return $codeownersToolCommand
@@ -10,15 +11,16 @@ function Get-CodeownersTool([string] $ToolPath, [string] $DevOpsFeed, [string] $
1011
}
1112
Write-Host "Installing the retrieve-codeowners tool under tool path: $ToolPath ..."
1213

13-
# Run command under tool path to avoid dotnet tool install command checking .csproj files.
14+
# Run command under tool path to avoid dotnet tool install command checking .csproj files.
1415
# This is a bug for dotnet tool command. Issue: https://github.com/dotnet/sdk/issues/9623
1516
Push-Location $ToolPath
17+
Write-Host "Executing: dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion"
1618
dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null
1719
Pop-Location
1820
# Test to see if the tool properly installed.
1921
if (!(Get-Command $codeownersToolCommand -errorAction SilentlyContinue)) {
2022
Write-Error "The retrieve-codeowners tool is not properly installed. Please check your tool path: $ToolPath"
21-
return
23+
return
2224
}
2325
return $codeownersToolCommand
2426
}
@@ -30,7 +32,7 @@ of that path, as determined by CODEOWNERS file passed in $CodeownersFileLocation
3032
param.
3133
3234
.PARAMETER TargetPath
33-
Required*. Path to file or directory whose owners are to be determined from a
35+
Required*. Path to file or directory whose owners are to be determined from a
3436
CODEOWNERS file. e.g. sdk/core/azure-amqp/ or sdk/core/foo.txt.
3537
3638
*for backward compatibility, you might provide $TargetDirectory instead.
@@ -45,7 +47,7 @@ Optional. An absolute path to the CODEOWNERS file against which the $TargetPath
4547
will be checked to determine its owners.
4648
4749
.PARAMETER ToolVersion
48-
Optional. The NuGet package version of the package containing the "retrieve-codeowners"
50+
Optional. The NuGet package version of the package containing the "retrieve-codeowners"
4951
tool, around which this script is a wrapper.
5052
5153
.PARAMETER ToolPath
@@ -60,8 +62,8 @@ https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/A
6062
Pipeline publishing the NuGet package to the feed, "tools - code-owners-parser":
6163
https://dev.azure.com/azure-sdk/internal/_build?definitionId=3188
6264
63-
.PARAMETER VsoVariable
64-
Optional. If provided, the determined owners, based on $TargetPath matched against CODEOWNERS file at $CodeownersFileLocation,
65+
.PARAMETER VsoVariable
66+
Optional. If provided, the determined owners, based on $TargetPath matched against CODEOWNERS file at $CodeownersFileLocation,
6567
will be output to Azure DevOps pipeline log as variable named $VsoVariable.
6668
6769
Reference:
@@ -80,7 +82,7 @@ function Get-Codeowners(
8082
[string] $TargetDirectory,
8183
[string] $ToolPath = (Join-Path ([System.IO.Path]::GetTempPath()) "codeowners-tool"),
8284
[string] $DevOpsFeed = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json",
83-
[string] $ToolVersion = "1.0.0-dev.20230306.3",
85+
[string] $ToolVersion = "1.0.0-dev.20230629.2",
8486
[string] $VsoVariable = "",
8587
[string] $CodeownersFileLocation = "",
8688
[switch] $IncludeNonUserAliases
@@ -100,12 +102,14 @@ function Get-Codeowners(
100102
return ,@()
101103
}
102104

105+
$jsonOutputFile = New-TemporaryFile
103106
$codeownersToolCommand = Get-CodeownersTool -ToolPath $ToolPath -DevOpsFeed $DevOpsFeed -ToolVersion $ToolVersion
104-
Write-Host "Executing: & $codeownersToolCommand --target-path $TargetPath --codeowners-file-path-or-url $CodeownersFileLocation --exclude-non-user-aliases:$(!$IncludeNonUserAliases)"
107+
Write-Host "Executing: & $codeownersToolCommand --target-path $TargetPath --codeowners-file-path-or-url $CodeownersFileLocation --exclude-non-user-aliases:$(!$IncludeNonUserAliases) --owners-data-output-file $jsonOutputFile"
105108
$commandOutput = & $codeownersToolCommand `
106109
--target-path $TargetPath `
107110
--codeowners-file-path-or-url $CodeownersFileLocation `
108111
--exclude-non-user-aliases:$(!$IncludeNonUserAliases) `
112+
--owners-data-output-file $jsonOutputFile `
109113
2>&1
110114

111115
if ($LASTEXITCODE -ne 0) {
@@ -116,14 +120,15 @@ function Get-Codeowners(
116120
Write-Host "Command $codeownersToolCommand executed successfully (exit code = 0). Command output string length: $($commandOutput.length)"
117121
}
118122

119-
# Assert: $commandOutput is a valid JSON representing:
120-
# - a single CodeownersEntry, if the $TargetPath was a single path
121-
# - or a dictionary of CodeownerEntries, keyes by each path resolved from a $TargetPath glob path.
122-
#
123-
# For implementation details, see Azure.Sdk.Tools.RetrieveCodeOwners.Program.Main
123+
# Assert: $commandOutput is a valid JSON representing:
124+
# - a single CodeownersEntry, if the $TargetPath was a single path
125+
# - or a dictionary of CodeownerEntries, keyes by each path resolved from a $TargetPath glob path.
126+
#
127+
# For implementation details, see Azure.Sdk.Tools.RetrieveCodeOwners.Program.Main
128+
129+
$fileContents = Get-Content $jsonOutputFile -Raw
130+
$codeownersJson = ConvertFrom-Json -InputObject $fileContents
124131

125-
$codeownersJson = $commandOutput | ConvertFrom-Json
126-
127132
if ($VsoVariable) {
128133
$codeowners = $codeownersJson.Owners -join ","
129134
Write-Host "##vso[task.setvariable variable=$VsoVariable;]$codeowners"

0 commit comments

Comments
 (0)