diff --git a/eng/scripts/Get-TypeSpec-Folders.ps1 b/eng/scripts/Get-TypeSpec-Folders.ps1 index 4271184ca72b..5b5dc2227d87 100644 --- a/eng/scripts/Get-TypeSpec-Folders.ps1 +++ b/eng/scripts/Get-TypeSpec-Folders.ps1 @@ -8,19 +8,29 @@ param ( [string]$SourceBranch ) -$tspFiles = @() +$changedFiles = @() if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { - $tspFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" + $changedFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).Directory.FullName | ForEach-Object {[IO.Path]::GetRelativePath($($pwd.path), $_)} + $changedFiles = $changedFiles -replace '\\', '/' } else { Write-Host "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" -- | Where-Object {`$_.StartsWith('specification')}" - $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" -- | Where-Object {$_.StartsWith('specification')} + $changedFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" -- | Where-Object {$_.StartsWith('specification')} + $changedFiles = $changedFiles -replace '\\', '/' + + Write-Host "changedFiles:" + foreach ($changedFile in $changedFiles) { + Write-Host " $changedFile" + } + Write-Host } $typespecFolders = @() -foreach ($file in $tspFiles) { - $file -match 'specification\/[^\/]*\/' | out-null - $typespecFolders += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).Directory.FullName -replace "$($pwd.Path)/" +foreach ($file in $changedFiles) { + if ($file -match 'specification\/[^\/]*\/') { + $typespecFolder = (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).Directory.FullName | ForEach-Object {if ($_) { [IO.Path]::GetRelativePath($($pwd.path), $_) }} + $typespecFolders += $typespecFolder -replace '\\', '/' + } } $typespecFolders = $typespecFolders | Select-Object -Unique diff --git a/eng/scripts/Validate-TypeSpec.ps1 b/eng/scripts/Validate-TypeSpec.ps1 index 7bd3171d001f..f84a272cacb9 100644 --- a/eng/scripts/Validate-TypeSpec.ps1 +++ b/eng/scripts/Validate-TypeSpec.ps1 @@ -8,18 +8,26 @@ param ( [string]$SourceBranch ) -$typespecFolders = @() +$exitCode = 0 $typespecFolders = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" "$SpecsRepoRootDirectory" "$TargetBranch" "$SourceBranch" -$exitCode = 0 +Write-Host "typespecFolders:" foreach ($typespecFolder in $typespecFolders) { - npx --no tsv $typespecFolder 2>&1 | Write-Host - if ($LASTEXITCODE) { - $exitCode = 1 + Write-Host " $typespecFolder" +} +Write-Host + +if ($typespecFolders) { + $typespecFolders = $typespecFolders.Split('',[System.StringSplitOptions]::RemoveEmptyEntries) + foreach ($typespecFolder in $typespecFolders) { + npx --no tsv $typespecFolder 2>&1 | Write-Host + if ($LASTEXITCODE) { + $exitCode = 1 + } + git restore . + git clean -df } - git restore . - git clean -df } exit $exitCode