From 26a0eeae5605233053aef765396462d75f650dbd 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 3714c0264388..9d83de9cb970 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 f36083db0c4a256a51c2f5dfe071c18c5dfaa748 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 9d83de9cb970..7399056c7840 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 e43f46b54afc5e6ddc81f1f30bfb7ffee183cdbe 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 7399056c7840..6004ba5efd40 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 bff33f9944e0837942101f3bd23778fad5d5305c 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 6004ba5efd40..90b7ac4671a8 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 4236ef14b9077bcc6b71ab9925dd38a3f65aabb0 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 90b7ac4671a8..1246a1a4a3c3 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 5b9b66f2ce797b87cf309a6f6a0151104dc5edd3 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 5c3d764009fe..0ed03bb90da9 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 558d1e5650e4d6535981dea29604fb5fb4edb006 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 0ed03bb90da9..355ef612540f 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 2aa5e77c6ebe549dbbb4840f1e1932edbf12705a 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 1246a1a4a3c3..172191c272dc 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