|
1 | 1 | [CmdletBinding()] |
2 | 2 | param ( |
3 | | - [Parameter(Position = 0, Mandatory = $true)] |
4 | | - [string] $SpecsRepoRootDirectory, |
5 | | - [Parameter(Position = 1, Mandatory = $false)] |
6 | | - [string]$TargetBranch, |
7 | | - [Parameter(Position = 2, Mandatory = $false)] |
8 | | - [string]$SourceBranch |
| 3 | + [switch]$CheckAll = $false |
9 | 4 | ) |
| 5 | +Set-StrictMode -Version 3 |
10 | 6 |
|
11 | | -$changedFiles = @() |
12 | | -$allChangedFiles = (Get-ChildItem -path ./specification tspconfig.* -Recurse).Directory.FullName | ForEach-Object {[IO.Path]::GetRelativePath($($pwd.path), $_)} |
13 | | -$allChangedFiles = $allChangedFiles -replace '\\', '/' |
| 7 | +. $PSScriptRoot/ChangedFiles-Functions.ps1 |
14 | 8 |
|
15 | | -if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { |
16 | | - if ($TargetBranch -or $SourceBranch) { |
17 | | - throw "Please provide both target branch and source branch." |
18 | | - } |
19 | | - $changedFiles = $allChangedFiles |
| 9 | +$repoPath = Resolve-Path "$PSScriptRoot/../.." |
| 10 | +$checkAllPath = "specification" |
| 11 | + |
| 12 | +if ($CheckAll) { |
| 13 | + $changedFiles = $checkAllPath |
20 | 14 | } |
21 | 15 | else { |
22 | | - Write-Host "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" --" |
23 | | - $changedFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" -- |
24 | | - $changedFiles = $changedFiles -replace '\\', '/' | Sort-Object |
25 | | - |
26 | | - Write-Host "changedFiles:" |
27 | | - foreach ($changedFile in $changedFiles) { |
28 | | - Write-Host " $changedFile" |
29 | | - } |
30 | | - Write-Host |
| 16 | + $changedFiles = @(Get-ChangedFiles -diffFilter "") |
| 17 | + $coreChangedFiles = Get-ChangedCoreFiles $changedFiles |
31 | 18 |
|
32 | | - $engFiles = $changedFiles | Where-Object {if ($_) { $_.StartsWith('eng') }} |
33 | | - |
34 | | - $commonTypesFiles = $changedFiles | Where-Object {if ($_) { $_.StartsWith('specification/common-types') }} |
35 | | - |
36 | | - $rootFilesImpactingTypeSpec = @( |
37 | | - ".gitattributes", |
38 | | - ".prettierrc.json", |
39 | | - "package-lock.json", |
40 | | - "package.json", |
41 | | - "tsconfig.json" |
42 | | - ) |
43 | | - $repoRootFiles = $changedFiles | Where-Object {$_ -in $rootFilesImpactingTypeSpec} |
44 | | - |
45 | | - if (($Env:BUILD_REPOSITORY_NAME -eq 'azure/azure-rest-api-specs') -and ($engFiles -or $commonTypesFiles -or $repoRootFiles)) { |
46 | | - $changedFiles = $allChangedFiles |
| 19 | + if ($Env:BUILD_REPOSITORY_NAME -eq 'azure/azure-rest-api-specs' -and $coreChangedFiles) { |
| 20 | + Write-Verbose "Found changes to core eng or root files so checking all specs." |
| 21 | + $changedFiles = $checkAllPath |
47 | 22 | } |
48 | 23 | else { |
49 | | - $changedFiles = $changedFiles | Where-Object {if ($_) { $_.StartsWith('specification') }} |
| 24 | + $changedFiles = Get-ChangedFilesUnderSpecification $changedFiles |
50 | 25 | } |
51 | 26 | } |
52 | 27 |
|
53 | 28 | $typespecFolders = @() |
54 | 29 | $skippedTypespecFolders = @() |
55 | 30 | foreach ($file in $changedFiles) { |
56 | | - if ($file -match 'specification\/[^\/]*\/') { |
57 | | - if (Test-Path $matches[0]) { |
58 | | - $typespecFolder = (Get-ChildItem -path $matches[0] tspconfig.* -Recurse).Directory.FullName | ForEach-Object {if ($_) { [IO.Path]::GetRelativePath($($pwd.path), $_) }} |
59 | | - $typespecFolders += $typespecFolder -replace '\\', '/' |
| 31 | + if ($file -match 'specification(\/[^\/]*\/)*') { |
| 32 | + $path = "$repoPath/$($matches[0])" |
| 33 | + if (Test-Path $path) { |
| 34 | + Write-Verbose "Checking for tspconfig files under $path" |
| 35 | + $typespecFolder = Get-ChildItem -path $path tspconfig.* -Recurse |
| 36 | + if ($typespecFolder) { |
| 37 | + $typespecFolders += $typespecFolder.Directory.FullName |
| 38 | + } |
60 | 39 | } else { |
61 | | - $skippedTypespecFolders += $matches[0] |
62 | | - } |
| 40 | + $skippedTypespecFolders += $path |
| 41 | + } |
63 | 42 | } |
64 | 43 | } |
65 | | - |
66 | 44 | foreach ($skippedTypespecFolder in $skippedTypespecFolders | Select-Object -Unique) { |
67 | 45 | Write-Host "Cannot find directory $skippedTypespecFolder" |
68 | 46 | } |
69 | 47 |
|
70 | | -$typespecFolders = $typespecFolders | Select-Object -Unique | Sort-Object |
| 48 | +$typespecFolders = $typespecFolders | ForEach-Object { [IO.Path]::GetRelativePath($repoPath, $_) -replace '\\', '/' } | Sort-Object -Unique |
71 | 49 |
|
72 | 50 | return $typespecFolders |
0 commit comments