Skip to content

Commit

Permalink
[typespec-ci] Improve change detection (Azure#24825)
Browse files Browse the repository at this point in the history
- Fixes Azure#24813
- Fixes Azure#24818
  • Loading branch information
ckairen authored and harryli0108 committed Jul 28, 2023
1 parent af48f25 commit 746c515
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
22 changes: 16 additions & 6 deletions eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 15 additions & 7 deletions eng/scripts/Validate-TypeSpec.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 746c515

Please sign in to comment.