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

Adjustments enabling change-specific PackageInfo #8602

Merged
merged 9 commits into from
Jul 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ steps:
inputs:
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Save-Package-Properties.ps1
arguments: >
-ServiceDirectory ${{parameters.ServiceDirectory}}
-ServiceInput ${{parameters.ServiceDirectory}}
-OutDirectory $(Build.ArtifactStagingDirectory)/PackageInfo
pwsh: true
workingDirectory: $(Pipeline.Workspace)
Expand Down
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
32 changes: 32 additions & 0 deletions eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,38 @@ function Get-PkgProperties
return $null
}

function Get-PackageFolderFromPath($file) {
$parts = $file -split "/"

if ($parts.Length -lt 3) {
return ""
}
return [System.IO.Path]::Combine($parts[0], $parts[1], $parts[2])
}

# Takes an input diff json file generated from eng/common/scripts/Generate-PR-Diff.ps1
# On PR builds, this function should be utilized instead of Get-AllPkgProperties.
function Get-PrPkgProperties([string]$InputDiffJson) {
$packagesWithChanges = @()

$allPackageProperties = Get-AllPkgProperties
$diff = Get-Content $InputDiffJson | ConvertFrom-Json
$targetedFiles = $diff.ChangedFiles

foreach($pkg in $allPackageProperties)
{
foreach($file in $targetedFiles)
{
$pkgFolder = Get-PackageFolderFromPath($file)
if ($pkgFolder.EndsWith($pkg.ArtifactName)) {
$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
19 changes: 14 additions & 5 deletions eng/common/scripts/Save-Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ In cases of collisions where track 2 packages (IsNewSdk = true) have the same
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
.PARAMETER serviceInput
Service directory in which to search for packages, or file path ending in diff.json.

.PARAMETER outDirectory
Output location (generally a package artifact directory in DevOps) for JSON
Expand All @@ -33,7 +33,7 @@ Verison property in that file.
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[string] $serviceDirectory,
[string] $serviceInput,
[Parameter(Mandatory=$True)]
[string] $outDirectory,
[switch] $addDevVersion
Expand Down Expand Up @@ -92,7 +92,16 @@ function GetRelativePath($path) {
}

$exportedPaths = @{}
$allPackageProperties = Get-AllPkgProperties $serviceDirectory

$allPackageProperties = @()

if ($serviceInput.endswith("diff.json")) {
$allPackageProperties = Get-PrPkgProperties $serviceInput
}
else {
$allPackageProperties = Get-AllPkgProperties $serviceInput
}

if ($allPackageProperties)
{
if (-not (Test-Path -Path $outDirectory))
Expand Down Expand Up @@ -137,6 +146,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 $($serviceInput)"
exit 1
}
2 changes: 1 addition & 1 deletion eng/common/scripts/Verify-RestApiSpecLocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Verify-PackageVersion() {
if (-not (Test-Path -Path $PackageInfoDirectory)) {
# Call Save-Package-Properties.ps1 script to generate package info json files
$savePropertiesScriptPath = Join-Path -Path $PSScriptRoot "Save-Package-Properties.ps1"
& $savePropertiesScriptPath -serviceDirectory $ServiceDirectory -outDirectory $PackageInfoDirectory
& $savePropertiesScriptPath -serviceInput $ServiceDirectory -outDirectory $PackageInfoDirectory
}
}
$pkgPropPath = Join-Path -Path $PackageInfoDirectory "$PackageName.json"
Expand Down