From 2633a10043fd3b47fff1d5f5b295a5bff1862edf Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Tue, 16 Jan 2024 18:10:28 -0800 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 7512 (#22241) * generate an artifact with the updated files * bring in Wes's feedback --------- Co-authored-by: Scott Beddall (from Dev Box) --- eng/common/scripts/Generate-PR-Diff.ps1 | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 eng/common/scripts/Generate-PR-Diff.ps1 diff --git a/eng/common/scripts/Generate-PR-Diff.ps1 b/eng/common/scripts/Generate-PR-Diff.ps1 new file mode 100644 index 000000000000..8239b219c373 --- /dev/null +++ b/eng/common/scripts/Generate-PR-Diff.ps1 @@ -0,0 +1,51 @@ +<# +.SYNOPSIS +Script used to generate the diff.json file for a PR. Explicitly intended to work in a PR context. + +.DESCRIPTION +Combines the result of git diff, some parsed details from the diff, and the PR number into a single JSON file. This JSON file is intended for use further along the pipeline. + +.PARAMETER ArtifactPath +The folder in which the result will be written. + +.PARAMETER TargetPath +The path under which changes will be detected. +#> +[CmdletBinding()] +Param ( + [Parameter(Mandatory=$True)] + [string] $ArtifactPath, + [Parameter(Mandatory=$True)] + [string] $TargetPath +) + +. (Join-Path $PSScriptRoot "Helpers" git-helpers.ps1) + +function Get-ChangedServices { + Param ( + [Parameter(Mandatory=$True)] + [string[]] $ChangedFiles + ) + + $changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique + + return $changedServices +} + +if (!(Test-Path $ArtifactPath)) { + New-Item -ItemType Directory -Path $ArtifactPath | Out-Null +} + +$ArtifactPath = Resolve-Path $ArtifactPath +$ArtifactName = Join-Path $ArtifactPath "diff.json" + +$changedFiles = Get-ChangedFiles -DiffPath $TargetPath +$changedServices = Get-ChangedServices -ChangedFiles $changedFiles + +$result = [PSCustomObject]@{ + "ChangedFiles" = $changedFiles + "ChangedServices" = $changedServices + "PRNumber" = $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER +} + +$result | ConvertTo-Json | Out-File $ArtifactName