Skip to content

Commit cc9fd4e

Browse files
azure-sdkscbeddweshaggard
authored
Sync eng/common directory with azure-sdk-tools for PR 8602 (#36486)
* add additional argument to Save-Package-Properties to allow for usage in pull request context --------- Co-authored-by: Scott Beddall (from Dev Box) <[email protected]> Co-authored-by: Scott Beddall <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent 73d6116 commit cc9fd4e

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

eng/common/scripts/Generate-PR-Diff.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $changedServices = Get-ChangedServices -ChangedFiles $changedFiles
4545
$result = [PSCustomObject]@{
4646
"ChangedFiles" = $changedFiles
4747
"ChangedServices" = $changedServices
48-
"PRNumber" = $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER
48+
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
4949
}
5050

5151
$result | ConvertTo-Json | Out-File $ArtifactName

eng/common/scripts/Package-Properties.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ function Get-PkgProperties
105105
return $null
106106
}
107107

108+
function Get-PrPkgProperties([string]$InputDiffJson) {
109+
$packagesWithChanges = @()
110+
111+
$allPackageProperties = Get-AllPkgProperties
112+
$diff = Get-Content $InputDiffJson | ConvertFrom-Json
113+
$targetedFiles = $diff.ChangedFiles
114+
115+
foreach($pkg in $allPackageProperties)
116+
{
117+
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
118+
119+
foreach($file in $targetedFiles)
120+
{
121+
$filePath = Resolve-Path (Join-Path $RepoRoot $file)
122+
$shouldInclude = $filePath -like "$pkgDirectory*"
123+
if ($shouldInclude) {
124+
$packagesWithChanges += $pkg
125+
}
126+
}
127+
}
128+
129+
return $packagesWithChanges
130+
}
131+
108132
# Takes ServiceName and Repo Root Directory
109133
# Returns important properties for each package in the specified service, or entire repo if the serviceName is not specified
110134
# Returns a Table of service key to array values of PS Object with properties @ { pkgName, pkgVersion, pkgDirectoryPath, pkgReadMePath, pkgChangeLogPath }

eng/common/scripts/Save-Package-Properties.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ filename as track 1 packages (e.g. same artifact name or package name), the
1515
track 2 package properties will be written.
1616
1717
.PARAMETER serviceDirectory
18-
Service directory in which to search for packages
18+
Service directory in which to search for packages.
19+
20+
.PARAMETER prDiff
21+
A file path leading to a file generated from Generate-PR-Diff.json. This parameter takes precedence over serviceDirectory, do not provide both.
1922
2023
.PARAMETER outDirectory
2124
Output location (generally a package artifact directory in DevOps) for JSON
@@ -32,10 +35,10 @@ Verison property in that file.
3235

3336
[CmdletBinding()]
3437
Param (
35-
[Parameter(Mandatory=$True)]
3638
[string] $serviceDirectory,
3739
[Parameter(Mandatory=$True)]
3840
[string] $outDirectory,
41+
[string] $prDiff,
3942
[switch] $addDevVersion
4043
)
4144

@@ -92,7 +95,16 @@ function GetRelativePath($path) {
9295
}
9396

9497
$exportedPaths = @{}
95-
$allPackageProperties = Get-AllPkgProperties $serviceDirectory
98+
99+
$allPackageProperties = @()
100+
101+
if ($prDiff) {
102+
$allPackageProperties = Get-PrPkgProperties $prDiff
103+
}
104+
else {
105+
$allPackageProperties = Get-AllPkgProperties $serviceDirectory
106+
}
107+
96108
if ($allPackageProperties)
97109
{
98110
if (-not (Test-Path -Path $outDirectory))
@@ -137,6 +149,6 @@ if ($allPackageProperties)
137149
}
138150
else
139151
{
140-
Write-Error "Package properties are not available for service directory $($serviceDirectory)"
152+
Write-Error "Package properties are not available for service directory $serviceDirectory or $prdiff"
141153
exit 1
142154
}

0 commit comments

Comments
 (0)