From 4d07d2db4ddddbb22e1675dbe1d6b359cefcf4d5 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 4 Nov 2024 17:18:13 -0800 Subject: [PATCH 1/8] upload the changed services as an attachment named AdditionalTags in save-package-properties.yml --- .../templates/steps/save-package-properties.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 3714c02643..9d83de9cb9 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -32,6 +32,21 @@ steps: -ArtifactPath '${{ parameters.DiffDirectory }}' pwsh: true + # When running in PR node, we want the detected changed services to be attached to the build as tags. + # However, the public identity does not have the permissions to attach tags to the build. + # Instead, we will save the changed services to a file, attach it as an attachment named tags.json, and pipeline + - pwsh: | + if ($changedServices) { + Write-Host "Attaching changed service names to the build for additional tag generation." + $changedServices | ConvertTo-Json | Out-File -FilePath $(System.DefaultWorkingDirectory)/tags.json -Encoding utf8 + Write-Host '##vso[task.addattachment type=AdditionalTags;name=AdditionalTags;]$(System.DefaultWorkingDirectory)/tags.json' + } + displayName: Upload tags.json with changed services + + - pwsh: | + Remove-Item -Force $(System.DefaultWorkingDirectory)/tags.json + displayName: Clean up tags.json + - task: Powershell@2 displayName: Save package properties filtered for PR inputs: From f96f8528c0d28970aaaa15a902fc6d204bdaeec0 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 4 Nov 2024 17:21:17 -0800 Subject: [PATCH 2/8] ensure the services get pulled from the generated diff --- .../pipelines/templates/steps/save-package-properties.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 9d83de9cb9..7399056c78 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -36,6 +36,8 @@ steps: # However, the public identity does not have the permissions to attach tags to the build. # Instead, we will save the changed services to a file, attach it as an attachment named tags.json, and pipeline - pwsh: | + $changedServices = (Get-Content -Path '${{ parameters.DiffDirectory }}/diff.json' -Raw | ConvertFrom-Json).ChangedServices + if ($changedServices) { Write-Host "Attaching changed service names to the build for additional tag generation." $changedServices | ConvertTo-Json | Out-File -FilePath $(System.DefaultWorkingDirectory)/tags.json -Encoding utf8 From 09fd429eda10adbad43285f5958c2db6d648783c Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Mon, 4 Nov 2024 17:23:07 -0800 Subject: [PATCH 3/8] update comment for completedness --- .../pipelines/templates/steps/save-package-properties.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 7399056c78..6004ba5efd 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -34,7 +34,7 @@ steps: # When running in PR node, we want the detected changed services to be attached to the build as tags. # However, the public identity does not have the permissions to attach tags to the build. - # Instead, we will save the changed services to a file, attach it as an attachment named tags.json, and pipeline + # Instead, we will save the changed services to a file, attach it as an attachment for PiplineWitness to pick up and utilize. - pwsh: | $changedServices = (Get-Content -Path '${{ parameters.DiffDirectory }}/diff.json' -Raw | ConvertFrom-Json).ChangedServices From 7b5da8f0f285f15682e5736af605b1ed203a2bd2 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 5 Nov 2024 13:16:16 -0800 Subject: [PATCH 4/8] we don't need to clean up the attachment. it is consumed by the addattachment operation --- .../pipelines/templates/steps/save-package-properties.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 6004ba5efd..90b7ac4671 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -45,10 +45,6 @@ steps: } displayName: Upload tags.json with changed services - - pwsh: | - Remove-Item -Force $(System.DefaultWorkingDirectory)/tags.json - displayName: Clean up tags.json - - task: Powershell@2 displayName: Save package properties filtered for PR inputs: From cf3b515f242418e61192991d371ae1ca8363ebf5 Mon Sep 17 00:00:00 2001 From: Scott Beddall <45376673+scbedd@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:34:47 -0800 Subject: [PATCH 5/8] Update eng/common/pipelines/templates/steps/save-package-properties.yml Co-authored-by: Patrick Hallisey --- .../pipelines/templates/steps/save-package-properties.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 90b7ac4671..1246a1a4a3 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -32,7 +32,7 @@ steps: -ArtifactPath '${{ parameters.DiffDirectory }}' pwsh: true - # When running in PR node, we want the detected changed services to be attached to the build as tags. + # When running in PR mode, we want the detected changed services to be attached to the build as tags. # However, the public identity does not have the permissions to attach tags to the build. # Instead, we will save the changed services to a file, attach it as an attachment for PiplineWitness to pick up and utilize. - pwsh: | From 6fa1624420254b8403003a9d44200126fff92921 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 12 Nov 2024 11:09:03 -0800 Subject: [PATCH 6/8] ensure that changedservices properly outputs an array --- eng/common/scripts/Generate-PR-Diff.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Generate-PR-Diff.ps1 b/eng/common/scripts/Generate-PR-Diff.ps1 index 5c3d764009..0ed03bb90d 100644 --- a/eng/common/scripts/Generate-PR-Diff.ps1 +++ b/eng/common/scripts/Generate-PR-Diff.ps1 @@ -28,7 +28,7 @@ function Get-ChangedServices [string[]] $ChangedFiles ) - $changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique + [string[]] $changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique return $changedServices } From e73cef6d4d74839da46de5d573331a2092e2dae2 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 12 Nov 2024 12:18:55 -0800 Subject: [PATCH 7/8] ChangedServices should be an array! enforce it! --- eng/common/scripts/Generate-PR-Diff.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/Generate-PR-Diff.ps1 b/eng/common/scripts/Generate-PR-Diff.ps1 index 0ed03bb90d..355ef61254 100644 --- a/eng/common/scripts/Generate-PR-Diff.ps1 +++ b/eng/common/scripts/Generate-PR-Diff.ps1 @@ -30,7 +30,7 @@ function Get-ChangedServices [string[]] $changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique - return $changedServices + return , $changedServices } if (!(Test-Path $ArtifactPath)) From 5a27e33a653e95befde649b262750f9256a604b8 Mon Sep 17 00:00:00 2001 From: Scott Beddall Date: Tue, 12 Nov 2024 13:41:20 -0800 Subject: [PATCH 8/8] ensure changeservices remains an array --- .../pipelines/templates/steps/save-package-properties.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/pipelines/templates/steps/save-package-properties.yml b/eng/common/pipelines/templates/steps/save-package-properties.yml index 1246a1a4a3..172191c272 100644 --- a/eng/common/pipelines/templates/steps/save-package-properties.yml +++ b/eng/common/pipelines/templates/steps/save-package-properties.yml @@ -40,7 +40,7 @@ steps: if ($changedServices) { Write-Host "Attaching changed service names to the build for additional tag generation." - $changedServices | ConvertTo-Json | Out-File -FilePath $(System.DefaultWorkingDirectory)/tags.json -Encoding utf8 + $changedServices | ConvertTo-Json -AsArray | Out-File -FilePath $(System.DefaultWorkingDirectory)/tags.json -Encoding utf8 Write-Host '##vso[task.addattachment type=AdditionalTags;name=AdditionalTags;]$(System.DefaultWorkingDirectory)/tags.json' } displayName: Upload tags.json with changed services