|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Script used to generate the diff.json file for a PR. Explicitly intended to work in a PR context. |
| 4 | +
|
| 5 | +.DESCRIPTION |
| 6 | +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. |
| 7 | +
|
| 8 | +.PARAMETER ArtifactPath |
| 9 | +The folder in which the result will be written. |
| 10 | +
|
| 11 | +.PARAMETER TargetPath |
| 12 | +The path under which changes will be detected. |
| 13 | +#> |
| 14 | +[CmdletBinding()] |
| 15 | +Param ( |
| 16 | + [Parameter(Mandatory=$True)] |
| 17 | + [string] $ArtifactPath, |
| 18 | + [Parameter(Mandatory=$True)] |
| 19 | + [string] $TargetPath |
| 20 | +) |
| 21 | + |
| 22 | +. (Join-Path $PSScriptRoot "Helpers" git-helpers.ps1) |
| 23 | + |
| 24 | +function Get-ChangedServices { |
| 25 | + Param ( |
| 26 | + [Parameter(Mandatory=$True)] |
| 27 | + [string[]] $ChangedFiles |
| 28 | + ) |
| 29 | + |
| 30 | + $changedServices = $ChangedFiles | Foreach-Object { if ($_ -match "sdk/([^/]+)") { $matches[1] } } | Sort-Object -Unique |
| 31 | + |
| 32 | + return $changedServices |
| 33 | +} |
| 34 | + |
| 35 | +if (!(Test-Path $ArtifactPath)) { |
| 36 | + New-Item -ItemType Directory -Path $ArtifactPath | Out-Null |
| 37 | +} |
| 38 | + |
| 39 | +$ArtifactPath = Resolve-Path $ArtifactPath |
| 40 | +$ArtifactName = Join-Path $ArtifactPath "diff.json" |
| 41 | + |
| 42 | +$changedFiles = Get-ChangedFiles -DiffPath $TargetPath |
| 43 | +$changedServices = Get-ChangedServices -ChangedFiles $changedFiles |
| 44 | + |
| 45 | +$result = [PSCustomObject]@{ |
| 46 | + "ChangedFiles" = $changedFiles |
| 47 | + "ChangedServices" = $changedServices |
| 48 | + "PRNumber" = $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER |
| 49 | +} |
| 50 | + |
| 51 | +$result | ConvertTo-Json | Out-File $ArtifactName |
0 commit comments