azure-sdk-for-cpp/eng/common/scripts/Generate-PR-Diff.ps1
Azure SDK Bot b4020493c4
Sync eng/common directory with azure-sdk-tools for PR 8754 (#5884)
* more compatibility with expanding/contracting packages. add ability for packages to have DependentPackages that must be included in the set of packages that should be built given a changeset


---------

Co-authored-by: Scott Beddall <scbedd@microsoft.com>
Co-authored-by: Scott Beddall <45376673+scbedd@users.noreply.github.com>
Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
2024-08-07 16:18:42 -07:00

52 lines
1.5 KiB
PowerShell

<#
.SYNOPSIS
Script used to generate the diff.json file for a PR. Explicitly intended to work in a PR context.
.DESCRIPTION
Combines the result of git diff, some parsed details from the diff, and the PR number into a single JSON file. This JSON file is intended for use further along the pipeline.
.PARAMETER ArtifactPath
The folder in which the result will be written.
.PARAMETER TargetPath
The path under which changes will be detected.
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True)]
[string] $ArtifactPath,
[Parameter(Mandatory=$True)]
[string] $TargetPath
)
. (Join-Path $PSScriptRoot "Helpers" "git-helpers.ps1")
function Get-ChangedServices {
Param (
[Parameter(Mandatory=$True)]
[string[]] $ChangedFiles
)
$changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique
return $changedServices
}
if (!(Test-Path $ArtifactPath)) {
New-Item -ItemType Directory -Path $ArtifactPath | Out-Null
}
$ArtifactPath = Resolve-Path $ArtifactPath
$ArtifactName = Join-Path $ArtifactPath "diff.json"
$changedFiles = Get-ChangedFiles -DiffPath $TargetPath
$changedServices = Get-ChangedServices -ChangedFiles $changedFiles
$result = [PSCustomObject]@{
"ChangedFiles" = $changedFiles
"ChangedServices" = $changedServices
"PRNumber" = if ($env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) { $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER } else { "-1" }
}
$result | ConvertTo-Json | Out-File $ArtifactName