diff --git a/eng/pipelines/templates/steps/typespec-ci.yml b/eng/pipelines/templates/steps/typespec-ci.yml deleted file mode 100644 index 992c13fd4030..000000000000 --- a/eng/pipelines/templates/steps/typespec-ci.yml +++ /dev/null @@ -1,22 +0,0 @@ -parameters: -- name: Folder - type: string -- name: DisplayName - type: string - -steps: -- bash: | - exit_code=0 - - # Log commands before running - set -x - - npx --no tsv ${{parameters.Folder}} || exit_code=1 - - # Discard any changes - git restore . - git clean -df - - exit $exit_code - displayName: ${{parameters.DisplayName}} - condition: succeededOrFailed() diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 91574df6ec45..ed52aa37fe94 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -40,72 +40,12 @@ jobs: displayName: npm ls -a condition: succeededOrFailed() - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/contosowidgetmanager/Contoso.WidgetManager - DisplayName: Contoso.WidgetManager - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/AnomalyDetector - DisplayName: AnomalyDetector - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/ContentSafety - DisplayName: ContentSafety - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/HealthInsights/healthinsights.openapi - DisplayName: healthinsights.openapi - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/HealthInsights/healthinsights.oncophenotype - DisplayName: healthinsights.oncophenotype - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/HealthInsights/healthinsights.trialmatcher - DisplayName: healthinsights.trialmatcher - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/cognitiveservices/OpenAI.Inference - DisplayName: OpenAI.Inference - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/confidentialledger/Microsoft.ManagedCcf - DisplayName: ManagedCcf - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/containerservice/Fleet.Management - DisplayName: Fleet.Management - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/containerstorage/ContainerStorage.Management - DisplayName: ContainerStorage.Management - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/eventgrid/Azure.Messaging.EventGrid - DisplayName: Messaging.EventGrid - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/servicenetworking/ServiceNetworking.Management - DisplayName: Microsoft.ServiceNetworking - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/sphere/Sphere.Management - DisplayName: Sphere.Management - - - template: templates/steps/typespec-ci.yml - parameters: - Folder: specification/translation/Azure.AI.TextTranslation - DisplayName: AI.TextTranslation + - pwsh: | + if ('$(Build.Reason)' -eq 'PullRequest') { + $(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" + } + else { + $(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 $(Build.SourcesDirectory) + } + displayName: Validate TypeSpec + condition: succeededOrFailed() diff --git a/eng/scripts/Get-TypeSpec-Folders.ps1 b/eng/scripts/Get-TypeSpec-Folders.ps1 new file mode 100644 index 000000000000..4271184ca72b --- /dev/null +++ b/eng/scripts/Get-TypeSpec-Folders.ps1 @@ -0,0 +1,27 @@ +[CmdletBinding()] +param ( + [Parameter(Position = 0, Mandatory = $true)] + [string] $SpecsRepoRootDirectory, + [Parameter(Position = 1, Mandatory = $false)] + [string]$TargetBranch, + [Parameter(Position = 2, Mandatory = $false)] + [string]$SourceBranch +) + +$tspFiles = @() +if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { + $tspFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" +} +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')} +} + +$typespecFolders = @() +foreach ($file in $tspFiles) { + $file -match 'specification\/[^\/]*\/' | out-null + $typespecFolders += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).Directory.FullName -replace "$($pwd.Path)/" +} +$typespecFolders = $typespecFolders | Select-Object -Unique + +return $typespecFolders diff --git a/eng/scripts/Validate-TypeSpec.ps1 b/eng/scripts/Validate-TypeSpec.ps1 new file mode 100644 index 000000000000..7bd3171d001f --- /dev/null +++ b/eng/scripts/Validate-TypeSpec.ps1 @@ -0,0 +1,25 @@ +[CmdletBinding()] +param ( + [Parameter(Position = 0, Mandatory = $true)] + [string] $SpecsRepoRootDirectory, + [Parameter(Position = 1, Mandatory = $false)] + [string]$TargetBranch, + [Parameter(Position = 2, Mandatory = $false)] + [string]$SourceBranch +) + +$typespecFolders = @() + +$typespecFolders = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" "$SpecsRepoRootDirectory" "$TargetBranch" "$SourceBranch" + +$exitCode = 0 +foreach ($typespecFolder in $typespecFolders) { + npx --no tsv $typespecFolder 2>&1 | Write-Host + if ($LASTEXITCODE) { + $exitCode = 1 + } + git restore . + git clean -df +} + +exit $exitCode