1
1
function Get-CodeownersTool ([string ] $ToolPath , [string ] $DevOpsFeed , [string ] $ToolVersion )
2
2
{
3
3
$codeownersToolCommand = Join-Path $ToolPath " retrieve-codeowners"
4
+ Write-Host " Checking for retrieve-codeowners in $ToolPath ..."
4
5
# Check if the retrieve-codeowners tool exists or not.
5
6
if (Get-Command $codeownersToolCommand - errorAction SilentlyContinue) {
6
7
return $codeownersToolCommand
@@ -10,15 +11,16 @@ function Get-CodeownersTool([string] $ToolPath, [string] $DevOpsFeed, [string] $
10
11
}
11
12
Write-Host " Installing the retrieve-codeowners tool under tool path: $ToolPath ..."
12
13
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.
14
15
# This is a bug for dotnet tool command. Issue: https://github.com/dotnet/sdk/issues/9623
15
16
Push-Location $ToolPath
17
+ Write-Host " Executing: dotnet tool install --tool-path $ToolPath --add-source $DevOpsFeed --version $ToolVersion "
16
18
dotnet tool install -- tool- path $ToolPath -- add-source $DevOpsFeed -- version $ToolVersion " Azure.Sdk.Tools.RetrieveCodeOwners" | Out-Null
17
19
Pop-Location
18
20
# Test to see if the tool properly installed.
19
21
if (! (Get-Command $codeownersToolCommand - errorAction SilentlyContinue)) {
20
22
Write-Error " The retrieve-codeowners tool is not properly installed. Please check your tool path: $ToolPath "
21
- return
23
+ return
22
24
}
23
25
return $codeownersToolCommand
24
26
}
@@ -30,7 +32,7 @@ of that path, as determined by CODEOWNERS file passed in $CodeownersFileLocation
30
32
param.
31
33
32
34
. 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
34
36
CODEOWNERS file. e.g. sdk/core/azure-amqp/ or sdk/core/foo.txt.
35
37
36
38
*for backward compatibility, you might provide $TargetDirectory instead.
@@ -45,7 +47,7 @@ Optional. An absolute path to the CODEOWNERS file against which the $TargetPath
45
47
will be checked to determine its owners.
46
48
47
49
. 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"
49
51
tool, around which this script is a wrapper.
50
52
51
53
. PARAMETER ToolPath
@@ -60,8 +62,8 @@ https://dev.azure.com/azure-sdk/public/_artifacts/feed/azure-sdk-for-net/NuGet/A
60
62
Pipeline publishing the NuGet package to the feed, "tools - code-owners-parser":
61
63
https://dev.azure.com/azure-sdk/internal/_build?definitionId=3188
62
64
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,
65
67
will be output to Azure DevOps pipeline log as variable named $VsoVariable.
66
68
67
69
Reference:
@@ -80,7 +82,7 @@ function Get-Codeowners(
80
82
[string ] $TargetDirectory ,
81
83
[string ] $ToolPath = (Join-Path ([System.IO.Path ]::GetTempPath()) " codeowners-tool" ),
82
84
[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 " ,
84
86
[string ] $VsoVariable = " " ,
85
87
[string ] $CodeownersFileLocation = " " ,
86
88
[switch ] $IncludeNonUserAliases
@@ -100,12 +102,14 @@ function Get-Codeowners(
100
102
return , @ ()
101
103
}
102
104
105
+ $jsonOutputFile = New-TemporaryFile
103
106
$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 "
105
108
$commandOutput = & $codeownersToolCommand `
106
109
-- target- path $TargetPath `
107
110
-- codeowners- file- path- or- url $CodeownersFileLocation `
108
111
-- exclude- non- user- aliases:$ (! $IncludeNonUserAliases ) `
112
+ -- owners- data- output- file $jsonOutputFile `
109
113
2>&1
110
114
111
115
if ($LASTEXITCODE -ne 0 ) {
@@ -116,14 +120,15 @@ function Get-Codeowners(
116
120
Write-Host " Command $codeownersToolCommand executed successfully (exit code = 0). Command output string length: $ ( $commandOutput.length ) "
117
121
}
118
122
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
124
131
125
- $codeownersJson = $commandOutput | ConvertFrom-Json
126
-
127
132
if ($VsoVariable ) {
128
133
$codeowners = $codeownersJson.Owners -join " ,"
129
134
Write-Host " ##vso[task.setvariable variable=$VsoVariable ;]$codeowners "
0 commit comments