Skip to content

Commit

Permalink
[typespec-ci] Automatically detect spec folders to validate (Azure#24629
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ckairen authored and harryli0108 committed Jul 28, 2023
1 parent 03b73c8 commit 6c8fce3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 91 deletions.
22 changes: 0 additions & 22 deletions eng/pipelines/templates/steps/typespec-ci.yml

This file was deleted.

78 changes: 9 additions & 69 deletions eng/pipelines/typespec-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 27 additions & 0 deletions eng/scripts/Get-TypeSpec-Folders.ps1
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions eng/scripts/Validate-TypeSpec.ps1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6c8fce3

Please sign in to comment.