Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 8602 (#45019)
Browse files Browse the repository at this point in the history
* add additional argument to Save-Package-Properties to allow for usage in pull request context

---------

Co-authored-by: Scott Beddall (from Dev Box) <scbedd@microsoft.com>
Co-authored-by: Scott Beddall <45376673+scbedd@users.noreply.github.com>
Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 18, 2024
1 parent 5caea73 commit 60e65bd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion eng/common/scripts/Generate-PR-Diff.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
20 changes: 16 additions & 4 deletions eng/common/scripts/Save-Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}

0 comments on commit 60e65bd

Please sign in to comment.