Sync eng/common directory with azure-sdk-tools for PR 8602 (#5801)

* 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>
This commit is contained in:
Azure SDK Bot 2024-07-18 14:44:18 -04:00 committed by GitHub
parent 01263ec39b
commit e67bcaa558
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 5 deletions

View File

@ -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

View File

@ -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 }

View File

@ -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
}