Skip to content
14 changes: 0 additions & 14 deletions eng/pipelines/typespec-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ trigger:
- main
- typespec-next

pr:
branches:
include:
- main
- typespec-next
paths:
include:
- .gitattributes
- .prettierrc.json
- package-lock.json
- package.json
- tsconfig.json
- eng

jobs:
- job: Validate_All_Specs
pool:
Expand Down
7 changes: 2 additions & 5 deletions eng/pipelines/typespec-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ pr:
include:
- main
- typespec-next
paths:
include:
- specification

jobs:
- job: Validate_Changed_Specs
- job: Validate_Impacted_Specs
pool:
name: azsdk-pool-mms-ubuntu-2204-general
vmImage: ubuntu-22.04
Expand All @@ -28,5 +25,5 @@ jobs:
$(Build.SourcesDirectory) `
"origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" `
"${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}"
displayName: Validate Changed Specs
displayName: Validate Impacted Specs
condition: succeededOrFailed()
19 changes: 15 additions & 4 deletions eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,31 @@ param (
)

$changedFiles = @()
$allChangedFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).Directory.FullName | ForEach-Object {[IO.Path]::GetRelativePath($($pwd.path), $_)}
$allChangedFiles = $allChangedFiles -replace '\\', '/'

if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) {
$changedFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).Directory.FullName | ForEach-Object {[IO.Path]::GetRelativePath($($pwd.path), $_)}
$changedFiles = $changedFiles -replace '\\', '/'
$changedFiles = $allChangedFiles
}
else {
Write-Host "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')}
Write-Host "git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" --"
$changedFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" --
$changedFiles = $changedFiles -replace '\\', '/'

Write-Host "changedFiles:"
foreach ($changedFile in $changedFiles) {
Write-Host " $changedFile"
}
Write-Host

$engFiles = $changedFiles | Where-Object {if ($_) { $_.StartsWith('eng') }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there cases where $_ is empty/null?

@mikeharder mikeharder Jul 21, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all of the null checks in this PR were added to fix bugs we found in testing. It might be possible to refactor/rewrite the powershell code to be cleaner, but we wanted to get this merged in and working quickly. I don't understand exactly how PowerShell handles null/empty string, and it seems to be different depending which API you are using.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe $_ was empty/null specifically in the case where there was no git diff (e.g. a PR with no changes).

$repoRootFiles = $changedFiles | Where-Object {$_ -notmatch [Regex]::Escape([IO.Path]::DirectorySeparatorChar)}
if ($engFiles -or $repoRootFiles) {
$changedFiles = $allChangedFiles
}
else {
$changedFiles = $changedFiles | Where-Object {if ($_) { $_.StartsWith('specification') }}
}
}

$typespecFolders = @()
Expand Down