Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 8602 #45019

Merged
merged 9 commits into from
Jul 18, 2024
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
}