From 72aaadf1228597b5836bb476c1e09a1060d08c37 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:44:47 -0400 Subject: [PATCH] Sync eng/common directory with azure-sdk-tools for PR 8602 (#45019) * add additional argument to Save-Package-Properties to allow for usage in pull request context --------- Co-authored-by: Scott Beddall (from Dev Box) Co-authored-by: Scott Beddall <45376673+scbedd@users.noreply.github.com> Co-authored-by: Wes Haggard --- eng/common/scripts/Generate-PR-Diff.ps1 | 2 +- eng/common/scripts/Package-Properties.ps1 | 24 +++++++++++++++++++ .../scripts/Save-Package-Properties.ps1 | 20 ++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/eng/common/scripts/Generate-PR-Diff.ps1 b/eng/common/scripts/Generate-PR-Diff.ps1 index 8239b219c3735..d84f9e15ca7c9 100644 --- a/eng/common/scripts/Generate-PR-Diff.ps1 +++ b/eng/common/scripts/Generate-PR-Diff.ps1 @@ -45,7 +45,7 @@ $changedServices = Get-ChangedServices -ChangedFiles $changedFiles $result = [PSCustomObject]@{ "ChangedFiles" = $changedFiles "ChangedServices" = $changedServices - "PRNumber" = $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER + "PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" } } $result | ConvertTo-Json | Out-File $ArtifactName diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 606998c8ea3c0..0e703a9d43743 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -105,6 +105,30 @@ function Get-PkgProperties return $null } +function Get-PrPkgProperties([string]$InputDiffJson) { + $packagesWithChanges = @() + + $allPackageProperties = Get-AllPkgProperties + $diff = Get-Content $InputDiffJson | ConvertFrom-Json + $targetedFiles = $diff.ChangedFiles + + foreach($pkg in $allPackageProperties) + { + $pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)" + + foreach($file in $targetedFiles) + { + $filePath = Resolve-Path (Join-Path $RepoRoot $file) + $shouldInclude = $filePath -like "$pkgDirectory*" + if ($shouldInclude) { + $packagesWithChanges += $pkg + } + } + } + + return $packagesWithChanges +} + # Takes ServiceName and Repo Root Directory # Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified # Returns a Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath } diff --git a/eng/common/scripts/Save-Package-Properties.ps1 b/eng/common/scripts/Save-Package-Properties.ps1 index 0e8ce26aa654d..c234d8b28ede4 100644 --- a/eng/common/scripts/Save-Package-Properties.ps1 +++ b/eng/common/scripts/Save-Package-Properties.ps1 @@ -15,7 +15,10 @@ filename as track 1 packages (e.g. same artifact name or package name), the track 2 package properties will be written. .PARAMETER serviceDirectory -Service directory in which to search for packages +Service directory in which to search for packages. + +.PARAMETER prDiff +A file path leading to a file generated from Generate-PR-Diff.json. This parameter takes precedence over serviceDirectory, do not provide both. .PARAMETER outDirectory Output location (generally a package artifact directory in DevOps) for JSON @@ -32,10 +35,10 @@ Verison property in that file. [CmdletBinding()] Param ( - [Parameter(Mandatory=$True)] [string] $serviceDirectory, [Parameter(Mandatory=$True)] [string] $outDirectory, + [string] $prDiff, [switch] $addDevVersion ) @@ -92,7 +95,16 @@ function GetRelativePath($path) { } $exportedPaths = @{} -$allPackageProperties = Get-AllPkgProperties $serviceDirectory + +$allPackageProperties = @() + +if ($prDiff) { + $allPackageProperties = Get-PrPkgProperties $prDiff +} +else { + $allPackageProperties = Get-AllPkgProperties $serviceDirectory +} + if ($allPackageProperties) { if (-not (Test-Path -Path $outDirectory)) @@ -137,6 +149,6 @@ if ($allPackageProperties) } else { - Write-Error "Package properties are not available for service directory $($serviceDirectory)" + Write-Error "Package properties are not available for service directory $serviceDirectory or $prdiff" exit 1 }