From cfc1d82ea3f496bf3a0b063ef6e7791833932326 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 24 Aug 2020 15:28:52 -0700 Subject: [PATCH 01/10] add additional outputs --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 5 +---- .../identity-resolver/Program.cs | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index a80d5b83b2d..58391afd58e 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -18,11 +18,8 @@ steps: --kusto-database-var KUSTO_DB ` --kusto-table-var KUSTO_TABLE ` --identity "$(Build.QueuedBy)" + --vsoVariable "${{ parameters.TargetVariable }}" $resolvedIdentity = $result[-1] | ConvertFrom-Json - - Write-Host $resolvedIdentity - - Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$($resolvedIdentity.GithubUserName)" displayName: 'Resolving Queuing User' workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver env: diff --git a/tools/notification-configuration/identity-resolver/Program.cs b/tools/notification-configuration/identity-resolver/Program.cs index 01583430a3a..6e47cff0b08 100644 --- a/tools/notification-configuration/identity-resolver/Program.cs +++ b/tools/notification-configuration/identity-resolver/Program.cs @@ -19,6 +19,7 @@ class Program /// Kusto DB environment variable name /// Kusto Table environment variable name /// The full name of the employee + /// The name of DevOps output variable. /// public static async Task Main( string aadAppIdVar, @@ -27,7 +28,8 @@ public static async Task Main( string kustoUrlVar, string kustoDatabaseVar, string kustoTableVar, - string identity + string identity, + string vsoVariable ) { @@ -47,6 +49,11 @@ string identity var result = await githubNameResolver.GetMappingInformationFromAADName(identity); + + if (!String.IsNullOrEmpty(vsoVariable)) + { + Console.Write(String.Format("##vso[task.setvariable variable={0};]{1}", vsoVariable, result.GithubUserName)); + } Console.Write(JsonConvert.SerializeObject(result)); } } From eff2adc2d467e5f1ae461fd71675431e7a8d06a2 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 24 Aug 2020 18:58:16 -0700 Subject: [PATCH 02/10] set vso variable if provided --- .../pipelines/templates/steps/get-pr-owners.yml | 16 +++++++++------- eng/common/scripts/get-codeowners.ps1 | 9 ++++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index 70668a7bfc9..4a56e3009d9 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -34,10 +34,12 @@ steps: Remove-Item -Force -Recurse $(Build.SourcesDirectory)/tools_repo displayName: Clean Up Cloned Tools Repo - - pwsh: | - $originalValue = "$(${{ parameters.TargetVariable }})" - $result = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 -TargetDirectory /sdk/${{ parameters.ServiceDirectory }}/ -RootDirectory $(Build.SourcesDirectory) - if ($result) { - Write-Host "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$originalValue,$result" - } - displayName: Add CodeOwners if Present \ No newline at end of file + - 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 }}" \ No newline at end of file diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index 8452f9fd650..e833c580962 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -1,6 +1,7 @@ param ( $TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus - $RootDirectory # ideally $(Build.SourcesDirectory) + $RootDirectory, # ideally $(Build.SourcesDirectory) + $VsoVariable = "" # target devops output variable ) $target = $TargetDirectory.ToLower().Trim("/") $codeOwnersLocation = Join-Path $RootDirectory -ChildPath ".github/CODEOWNERS" @@ -29,6 +30,12 @@ $results = $ownedFolders[$target] if ($results) { Write-Host "Found a folder $results to match $target" + $alreadyPresent = [System.Environment]::GetEnvironmentVariable('$VsoVariable') + + if ($VsoVariable) { + Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results,$alreadyPresent" + } + return $results } else { From 16fbdad78808d7d179befeb5e2461e652db2b654 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 24 Aug 2020 19:42:57 -0700 Subject: [PATCH 03/10] clean up functionality --- eng/common/scripts/get-codeowners.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 index e833c580962..f28cb3df789 100644 --- a/eng/common/scripts/get-codeowners.ps1 +++ b/eng/common/scripts/get-codeowners.ps1 @@ -30,10 +30,14 @@ $results = $ownedFolders[$target] if ($results) { Write-Host "Found a folder $results to match $target" - $alreadyPresent = [System.Environment]::GetEnvironmentVariable('$VsoVariable') - + if ($VsoVariable) { - Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results,$alreadyPresent" + $alreadyPresent = [System.Environment]::GetEnvironmentVariable($VsoVariable) + + if ($alreadyPresent) { + $results += ",$alreadyPresent" + } + Write-Host "##vso[task.setvariable variable=$VsoVariable;]$results" } return $results From 8f7b463e9555b57715ee9e90e09dc98f5fedc6f3 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Sat, 29 Aug 2020 15:52:03 -0700 Subject: [PATCH 04/10] handle issues discovered during testing --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index 4a56e3009d9..b854ae36a4a 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -9,6 +9,10 @@ steps: git checkout 564ad63ae72d18422533fa1da9d396e7703c1cb5 displayName: Setup Identity Resolver + - pwsh: | + Write-Host "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]" + displayName: 'Ensure Target Variable Is Populated' + - pwsh: | $result = dotnet run -v q -- ` --aad-app-id-var APP_ID ` @@ -17,7 +21,7 @@ steps: --kusto-url-var KUSTO_URL ` --kusto-database-var KUSTO_DB ` --kusto-table-var KUSTO_TABLE ` - --identity "$(Build.QueuedBy)" + --identity "$(Build.QueuedBy)" ` --vsoVariable "${{ parameters.TargetVariable }}" displayName: 'Resolving Queuing User' continueOnError: true From d3b216d25518d317bc56be575e43e8162353fcb9 Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 31 Aug 2020 17:59:23 -0700 Subject: [PATCH 05/10] update targeting usage appropriately, remove extraneous error --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index b854ae36a4a..0f5c34a9294 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -8,11 +8,7 @@ steps: cd $(Build.SourcesDirectory)/tools_repo git checkout 564ad63ae72d18422533fa1da9d396e7703c1cb5 displayName: Setup Identity Resolver - - - pwsh: | - Write-Host "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]" - displayName: 'Ensure Target Variable Is Populated' - + - pwsh: | $result = dotnet run -v q -- ` --aad-app-id-var APP_ID ` @@ -22,7 +18,7 @@ steps: --kusto-database-var KUSTO_DB ` --kusto-table-var KUSTO_TABLE ` --identity "$(Build.QueuedBy)" ` - --vsoVariable "${{ parameters.TargetVariable }}" + --vso-variable "${{ parameters.TargetVariable }}" displayName: 'Resolving Queuing User' continueOnError: true workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver From 07470c217876f7af29b79e98ef94ec2ee087ea05 Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 31 Aug 2020 18:17:31 -0700 Subject: [PATCH 06/10] need the output to actually print! --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index 0f5c34a9294..517e544ea9d 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -10,7 +10,7 @@ steps: displayName: Setup Identity Resolver - pwsh: | - $result = dotnet run -v q -- ` + dotnet run -v q -- ` --aad-app-id-var APP_ID ` --aad-app-secret-var APP_SECRET ` --aad-tenant-var AAD_TENANT ` From 9e4022039778530e64e22582505a3ea22cfebf1d Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 31 Aug 2020 18:20:28 -0700 Subject: [PATCH 07/10] newer SHA on clone --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index 517e544ea9d..fbf858dda15 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -6,7 +6,7 @@ steps: - pwsh: | git clone https://github.com/Azure/azure-sdk-tools.git $(Build.SourcesDirectory)/tools_repo cd $(Build.SourcesDirectory)/tools_repo - git checkout 564ad63ae72d18422533fa1da9d396e7703c1cb5 + git checkout a7f38c84325424bd7f8be8c7661213995ebe8adb displayName: Setup Identity Resolver - pwsh: | From 2ffd4fcd30459d3fafc4f6d39deb9b10ce753495 Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Mon, 31 Aug 2020 18:46:15 -0700 Subject: [PATCH 08/10] WriteLine instead of write --- tools/notification-configuration/identity-resolver/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/notification-configuration/identity-resolver/Program.cs b/tools/notification-configuration/identity-resolver/Program.cs index 6e47cff0b08..ef25446df4d 100644 --- a/tools/notification-configuration/identity-resolver/Program.cs +++ b/tools/notification-configuration/identity-resolver/Program.cs @@ -52,9 +52,9 @@ string vsoVariable if (!String.IsNullOrEmpty(vsoVariable)) { - Console.Write(String.Format("##vso[task.setvariable variable={0};]{1}", vsoVariable, result.GithubUserName)); + Console.WriteLine(String.Format("##vso[task.setvariable variable={0};]{1}", vsoVariable, result.GithubUserName)); } - Console.Write(JsonConvert.SerializeObject(result)); + Console.WriteLine(JsonConvert.SerializeObject(result)); } } } From 10de45dba2721d4e763b179e4515e0c68139be9c Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 31 Aug 2020 23:42:01 -0700 Subject: [PATCH 09/10] final tested updates. --- eng/common/pipelines/templates/steps/get-pr-owners.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml index fbf858dda15..545143ce09b 100644 --- a/eng/common/pipelines/templates/steps/get-pr-owners.yml +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -6,9 +6,9 @@ steps: - pwsh: | git clone https://github.com/Azure/azure-sdk-tools.git $(Build.SourcesDirectory)/tools_repo cd $(Build.SourcesDirectory)/tools_repo - git checkout a7f38c84325424bd7f8be8c7661213995ebe8adb + git checkout 35ad98f821913eb0e8872f861ee60589b563c865 displayName: Setup Identity Resolver - + - pwsh: | dotnet run -v q -- ` --aad-app-id-var APP_ID ` @@ -18,7 +18,7 @@ steps: --kusto-database-var KUSTO_DB ` --kusto-table-var KUSTO_TABLE ` --identity "$(Build.QueuedBy)" ` - --vso-variable "${{ parameters.TargetVariable }}" + --targetvar "${{ parameters.TargetVariable }}" displayName: 'Resolving Queuing User' continueOnError: true workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver From b25a45a46a9f25087b09a4664f4c4b2dfe63b78f Mon Sep 17 00:00:00 2001 From: scbedd <45376673+scbedd@users.noreply.github.com> Date: Tue, 1 Sep 2020 12:29:45 -0700 Subject: [PATCH 10/10] mirror updates to the identity-resolver. ready for merge --- .../identity-resolver/Program.cs | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/tools/notification-configuration/identity-resolver/Program.cs b/tools/notification-configuration/identity-resolver/Program.cs index ef25446df4d..a89f808041e 100644 --- a/tools/notification-configuration/identity-resolver/Program.cs +++ b/tools/notification-configuration/identity-resolver/Program.cs @@ -19,7 +19,7 @@ class Program /// Kusto DB environment variable name /// Kusto Table environment variable name /// The full name of the employee - /// The name of DevOps output variable. + /// The name of DevOps output variable /// public static async Task Main( string aadAppIdVar, @@ -29,7 +29,7 @@ public static async Task Main( string kustoDatabaseVar, string kustoTableVar, string identity, - string vsoVariable + string targetvar ) { @@ -37,25 +37,36 @@ string vsoVariable using (var loggerFactory = new LoggerFactory().AddConsole(includeScopes: true)) #pragma warning restore CS0618 // Type or member is obsolete { - var githubNameResolver = new GitHubNameResolver( - Environment.GetEnvironmentVariable(aadAppIdVar), - Environment.GetEnvironmentVariable(aadAppSecretVar), - Environment.GetEnvironmentVariable(aadTenantVar), - Environment.GetEnvironmentVariable(kustoUrlVar), - Environment.GetEnvironmentVariable(kustoDatabaseVar), - Environment.GetEnvironmentVariable(kustoTableVar), - loggerFactory.CreateLogger() - ); - - var result = await githubNameResolver.GetMappingInformationFromAADName(identity); + try + { + var githubNameResolver = new GitHubNameResolver( + Environment.GetEnvironmentVariable(aadAppIdVar), + Environment.GetEnvironmentVariable(aadAppSecretVar), + Environment.GetEnvironmentVariable(aadTenantVar), + Environment.GetEnvironmentVariable(kustoUrlVar), + Environment.GetEnvironmentVariable(kustoDatabaseVar), + Environment.GetEnvironmentVariable(kustoTableVar), + loggerFactory.CreateLogger() + ); + var result = await githubNameResolver.GetMappingInformationFromAADName(identity); - if (!String.IsNullOrEmpty(vsoVariable)) + if (!String.IsNullOrEmpty(targetvar)) + { + Console.WriteLine(String.Format("##vso[task.setvariable variable={0};]{1}", targetvar, result.GithubUserName)); + } + Console.WriteLine(JsonConvert.SerializeObject(result)); + } + catch (Exception e) { - Console.WriteLine(String.Format("##vso[task.setvariable variable={0};]{1}", vsoVariable, result.GithubUserName)); + if (!String.IsNullOrEmpty(targetvar)) + { + Console.WriteLine(String.Format("##vso[task.setvariable variable={0};]{1}", targetvar, "")); + } + + throw e; } - Console.WriteLine(JsonConvert.SerializeObject(result)); } } } -} +} \ No newline at end of file