From b66e2edf48d4ca1ce23ed165c61a3b0839822906 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 28 Jun 2023 14:15:41 -0700 Subject: [PATCH 01/24] tsv auto folder detection for pr pipeline run --- eng/pipelines/templates/steps/typespec-ci.yml | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/templates/steps/typespec-ci.yml b/eng/pipelines/templates/steps/typespec-ci.yml index de04728f74b0..cbb991a429b4 100644 --- a/eng/pipelines/templates/steps/typespec-ci.yml +++ b/eng/pipelines/templates/steps/typespec-ci.yml @@ -5,6 +5,24 @@ parameters: type: string steps: -- script: npx --no tsv ${{parameters.Folder}} +- pwsh: | + $tspFiles = @() + if ('$(Build.Reason)' -eq 'PullRequest') { + $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$(System.PullRequest.TargetBranch)"..."$(System.PullRequest.SourceBranch)" --name-only | Where-Object {$_.StartsWith('specification')} + } + else { + $tspFiles = (Get-ChildItem -path ./specification *.tsp -Recurse).FullName -replace "$($pwd.Path)/" + } + + $typeSpecFolders = @() + foreach ($file in $tspFiles) { + $file -match 'specification\/[^\/]*\/' | out-null + $typeSpecFolders += $matches[0] + } + $typeSpecFolders = $typeSpecFolders | Select-Object -Unique + + foreach ($typeSpecFolder in $typeSpecFolders) { + npx --no tsv $typeSpecFolder + } displayName: ${{parameters.DisplayName}} condition: succeededOrFailed() From 7818abca64c49fe8ea2ddb5c5a939814a0f7bd9a Mon Sep 17 00:00:00 2001 From: Albert Date: Mon, 10 Jul 2023 17:16:50 -0700 Subject: [PATCH 02/24] get typespec folder script --- eng/pipelines/templates/steps/typespec-ci.yml | 28 ------ eng/pipelines/typespec-ci.yml | 88 +++++-------------- eng/scripts/Get-Typespec-Folders.ps1.ps1 | 26 ++++++ 3 files changed, 50 insertions(+), 92 deletions(-) delete mode 100644 eng/pipelines/templates/steps/typespec-ci.yml create mode 100644 eng/scripts/Get-Typespec-Folders.ps1.ps1 diff --git a/eng/pipelines/templates/steps/typespec-ci.yml b/eng/pipelines/templates/steps/typespec-ci.yml deleted file mode 100644 index cbb991a429b4..000000000000 --- a/eng/pipelines/templates/steps/typespec-ci.yml +++ /dev/null @@ -1,28 +0,0 @@ -parameters: -- name: Folder - type: string -- name: DisplayName - type: string - -steps: -- pwsh: | - $tspFiles = @() - if ('$(Build.Reason)' -eq 'PullRequest') { - $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$(System.PullRequest.TargetBranch)"..."$(System.PullRequest.SourceBranch)" --name-only | Where-Object {$_.StartsWith('specification')} - } - else { - $tspFiles = (Get-ChildItem -path ./specification *.tsp -Recurse).FullName -replace "$($pwd.Path)/" - } - - $typeSpecFolders = @() - foreach ($file in $tspFiles) { - $file -match 'specification\/[^\/]*\/' | out-null - $typeSpecFolders += $matches[0] - } - $typeSpecFolders = $typeSpecFolders | Select-Object -Unique - - foreach ($typeSpecFolder in $typeSpecFolders) { - npx --no tsv $typeSpecFolder - } - displayName: ${{parameters.DisplayName}} - condition: succeededOrFailed() diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 0469c9289791..7c9b2276bb69 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -38,67 +38,27 @@ 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/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: | + $typespecFolders = @() + if ('$(Build.Reason)' -eq 'PullRequest') { + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) "$(System.PullRequest.TargetBranch)" "$(System.PullRequest.SourceBranch)" + } + else { + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) + } + + $exitCode = 0 + foreach ($typeSpecFolder in $typeSpecFolders) { + try { + npx --no tsv $typeSpecFolder + } + catch { + $exitCode = 1 + } + git restore . + git clean -df + } + + exit $exitCode + displayName: TypeSpecValidation + condition: succeededOrFailed() \ No newline at end of file diff --git a/eng/scripts/Get-Typespec-Folders.ps1.ps1 b/eng/scripts/Get-Typespec-Folders.ps1.ps1 new file mode 100644 index 000000000000..0f28186421fe --- /dev/null +++ b/eng/scripts/Get-Typespec-Folders.ps1.ps1 @@ -0,0 +1,26 @@ +[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 *.tsp -Recurse).FullName -replace "$($pwd.Path)/" +} +else { + $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetBranch"..."$SourceBranch" --name-only | Where-Object {$_.StartsWith('specification')} +} + +$typeSpecFolders = @() +foreach ($file in $tspFiles) { + $file -match 'specification\/[^\/]*\/' | out-null + $typeSpecFolders += $matches[0] +} +$typeSpecFolders = $typeSpecFolders | Select-Object -Unique + +return $typeSpecFolders From 472e6d001d3a552b45d6972a32f370c06dae1670 Mon Sep 17 00:00:00 2001 From: Albert Date: Mon, 10 Jul 2023 17:30:45 -0700 Subject: [PATCH 03/24] fix ambiguous main --- eng/pipelines/typespec-ci.yml | 28 ++++++++++++++++++++++++ eng/scripts/Get-Typespec-Folders.ps1.ps1 | 4 +++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 2c69da774a3c..6c1126a07982 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -39,3 +39,31 @@ jobs: - script: npm ls -a displayName: npm ls -a condition: succeededOrFailed() + + - script: npm run build + displayName: npm run build + condition: succeededOrFailed() + - pwsh: | + $typespecFolders = @() + if ('$(Build.Reason)' -eq 'PullRequest') { + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) "$(System.PullRequest.TargetBranch)" "$(System.PullRequest.SourceBranch)" + } + else { + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) + } + + $exitCode = 0 + foreach ($typeSpecFolder in $typeSpecFolders) { + try { + npx --no tsv $typeSpecFolder + } + catch { + $exitCode = 1 + } + git restore . + git clean -df + } + + exit $exitCode + displayName: TypeSpecValidation + condition: succeededOrFailed() diff --git a/eng/scripts/Get-Typespec-Folders.ps1.ps1 b/eng/scripts/Get-Typespec-Folders.ps1.ps1 index 0f28186421fe..90df2ab22829 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1.ps1 @@ -8,12 +8,14 @@ param ( [string]$SourceBranch ) +Write-Host $TargetBranch +Write-Host $SourceBranch $tspFiles = @() if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { $tspFiles = (Get-ChildItem -path ./specification *.tsp -Recurse).FullName -replace "$($pwd.Path)/" } else { - $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetBranch"..."$SourceBranch" --name-only | Where-Object {$_.StartsWith('specification')} + $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetBranch"..."$SourceBranch" -- --name-only | Where-Object {$_.StartsWith('specification')} } $typeSpecFolders = @() From 85801bdf316a533bb5f133c0163d98e34c262bbf Mon Sep 17 00:00:00 2001 From: Albert Date: Mon, 10 Jul 2023 18:04:49 -0700 Subject: [PATCH 04/24] trigger on tspconfig --- eng/scripts/Get-Typespec-Folders.ps1.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Get-Typespec-Folders.ps1.ps1 b/eng/scripts/Get-Typespec-Folders.ps1.ps1 index 90df2ab22829..06462d8305da 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1.ps1 @@ -12,7 +12,7 @@ Write-Host $TargetBranch Write-Host $SourceBranch $tspFiles = @() if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { - $tspFiles = (Get-ChildItem -path ./specification *.tsp -Recurse).FullName -replace "$($pwd.Path)/" + $tspFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" } else { $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetBranch"..."$SourceBranch" -- --name-only | Where-Object {$_.StartsWith('specification')} From 38eead2482bf6e5151cb7814bdcab7961df20808 Mon Sep 17 00:00:00 2001 From: Albert Date: Tue, 11 Jul 2023 12:25:47 -0700 Subject: [PATCH 05/24] cleanup --- eng/pipelines/typespec-ci.yml | 3 ++- ...Get-Typespec-Folders.ps1.ps1 => Get-Typespec-Folders.ps1} | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename eng/scripts/{Get-Typespec-Folders.ps1.ps1 => Get-Typespec-Folders.ps1} (77%) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index c20810839109..8c3d76183a2d 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -43,13 +43,14 @@ jobs: - pwsh: | $typespecFolders = @() if ('$(Build.Reason)' -eq 'PullRequest') { - $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) "$(System.PullRequest.TargetBranch)" "$(System.PullRequest.SourceBranch)" + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" } else { $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) } $exitCode = 0 + Write-Host "Running TSV on: $typespecFolders" foreach ($typeSpecFolder in $typeSpecFolders) { try { npx --no tsv $typeSpecFolder diff --git a/eng/scripts/Get-Typespec-Folders.ps1.ps1 b/eng/scripts/Get-Typespec-Folders.ps1 similarity index 77% rename from eng/scripts/Get-Typespec-Folders.ps1.ps1 rename to eng/scripts/Get-Typespec-Folders.ps1 index 06462d8305da..f8132cc13a4d 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1 @@ -8,14 +8,13 @@ param ( [string]$SourceBranch ) -Write-Host $TargetBranch -Write-Host $SourceBranch $tspFiles = @() if ([string]::IsNullOrEmpty($TargetBranch) -or [string]::IsNullOrEmpty($SourceBranch)) { $tspFiles = (Get-ChildItem -path ./specification tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" } else { - $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff "$TargetBranch"..."$SourceBranch" -- --name-only | Where-Object {$_.StartsWith('specification')} + 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 = @() From 20818912b654507fdc1b588db7d1482af3704abe Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 11:21:45 -0700 Subject: [PATCH 06/24] fixing try catch --- eng/pipelines/typespec-ci.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 8c3d76183a2d..f9aafa4269d8 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -52,10 +52,8 @@ jobs: $exitCode = 0 Write-Host "Running TSV on: $typespecFolders" foreach ($typeSpecFolder in $typeSpecFolders) { - try { - npx --no tsv $typeSpecFolder - } - catch { + npx --no tsv $typeSpecFolder + if ($LASTEXITCODE) { $exitCode = 1 } git restore . From c84cdc4df539fcb28748888a8ced89e52013323f Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 11:54:00 -0700 Subject: [PATCH 07/24] fix specs dir --- eng/pipelines/typespec-ci.yml | 1 - eng/scripts/Get-Typespec-Folders.ps1 | 2 +- eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index f9aafa4269d8..7e7f65995921 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -50,7 +50,6 @@ jobs: } $exitCode = 0 - Write-Host "Running TSV on: $typespecFolders" foreach ($typeSpecFolder in $typeSpecFolders) { npx --no tsv $typeSpecFolder if ($LASTEXITCODE) { diff --git a/eng/scripts/Get-Typespec-Folders.ps1 b/eng/scripts/Get-Typespec-Folders.ps1 index f8132cc13a4d..73688a4bbb16 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1 @@ -20,7 +20,7 @@ else { $typeSpecFolders = @() foreach ($file in $tspFiles) { $file -match 'specification\/[^\/]*\/' | out-null - $typeSpecFolders += $matches[0] + $typeSpecFolders += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" } $typeSpecFolders = $typeSpecFolders | Select-Object -Unique diff --git a/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts b/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts index 447f73d6ecae..4078f6233382 100755 --- a/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts +++ b/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts @@ -62,6 +62,7 @@ export async function main() { // Spec compilation check if (await checkFileExists(path.join(folder, "main.tsp"))) { + console.log(path.join(folder, "main.tsp")); await runCmd(`npx --no tsp compile . --warn-as-error`, folder); } if (await checkFileExists(path.join(folder, "client.tsp"))) { From 5b99a70338403d09a2ea61a90835aceb55fee92e Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 12:28:01 -0700 Subject: [PATCH 08/24] fix specs dir --- eng/scripts/Get-Typespec-Folders.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Get-Typespec-Folders.ps1 b/eng/scripts/Get-Typespec-Folders.ps1 index 73688a4bbb16..273a270ea32f 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1 @@ -20,7 +20,7 @@ else { $typeSpecFolders = @() foreach ($file in $tspFiles) { $file -match 'specification\/[^\/]*\/' | out-null - $typeSpecFolders += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).FullName -replace "$($pwd.Path)/" + $typeSpecFolders += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).Directory.FullName -replace "$($pwd.Path)/" } $typeSpecFolders = $typeSpecFolders | Select-Object -Unique From 61f1873e3959ebb3d95c0d8ca5c4c27d50a7d2f6 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 12:37:07 -0700 Subject: [PATCH 09/24] cleanup --- eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts b/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts index 4078f6233382..447f73d6ecae 100755 --- a/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts +++ b/eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts @@ -62,7 +62,6 @@ export async function main() { // Spec compilation check if (await checkFileExists(path.join(folder, "main.tsp"))) { - console.log(path.join(folder, "main.tsp")); await runCmd(`npx --no tsp compile . --warn-as-error`, folder); } if (await checkFileExists(path.join(folder, "client.tsp"))) { From 38e220590f7a40e06c8a50fb202808d4f3e399f1 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 12:42:53 -0700 Subject: [PATCH 10/24] cleanup --- eng/pipelines/typespec-ci.yml | 6 +++--- eng/scripts/Get-Typespec-Folders.ps1 | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 7e7f65995921..3beba0f08b63 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -50,8 +50,8 @@ jobs: } $exitCode = 0 - foreach ($typeSpecFolder in $typeSpecFolders) { - npx --no tsv $typeSpecFolder + foreach ($typespecFolder in $typespecFolders) { + npx --no tsv $typespecFolder if ($LASTEXITCODE) { $exitCode = 1 } @@ -60,5 +60,5 @@ jobs: } exit $exitCode - displayName: TypeSpecValidation + displayName: TypespecValidation condition: succeededOrFailed() diff --git a/eng/scripts/Get-Typespec-Folders.ps1 b/eng/scripts/Get-Typespec-Folders.ps1 index 273a270ea32f..4271184ca72b 100644 --- a/eng/scripts/Get-Typespec-Folders.ps1 +++ b/eng/scripts/Get-Typespec-Folders.ps1 @@ -17,11 +17,11 @@ else { $tspFiles = git -c core.quotepath=off -c i18n.logoutputencoding=utf-8 diff --name-only `"$TargetBranch...$SourceBranch`" -- | Where-Object {$_.StartsWith('specification')} } -$typeSpecFolders = @() +$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 += (Get-ChildItem -path $matches[0] tspconfig.yaml -Recurse).Directory.FullName -replace "$($pwd.Path)/" } -$typeSpecFolders = $typeSpecFolders | Select-Object -Unique +$typespecFolders = $typespecFolders | Select-Object -Unique -return $typeSpecFolders +return $typespecFolders From 75efc3def54ada4c3dfd155781373650e3553895 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 13:06:38 -0700 Subject: [PATCH 11/24] tsv local script --- eng/pipelines/typespec-ci.yml | 4 ++-- eng/scripts/Validate-Typespec.ps1 | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 eng/scripts/Validate-Typespec.ps1 diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 3beba0f08b63..c473dad2d010 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -43,10 +43,10 @@ jobs: - pwsh: | $typespecFolders = @() if ('$(Build.Reason)' -eq 'PullRequest') { - $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" } else { - $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Get-Typespec-Folders.ps1 $(Build.SourcesDirectory) + $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) } $exitCode = 0 diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-Typespec.ps1 new file mode 100644 index 000000000000..c12f52dbce87 --- /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 + if ($LASTEXITCODE) { + $exitCode = 1 + } + git restore . + git clean -df +} + +exit $exitCode \ No newline at end of file From e1d9e9a97dc19329fdd711e90d0842c73af25c89 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 13:12:31 -0700 Subject: [PATCH 12/24] cleanup --- eng/pipelines/typespec-ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index c473dad2d010..c8bdae92056d 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -48,17 +48,5 @@ jobs: else { $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) } - - $exitCode = 0 - foreach ($typespecFolder in $typespecFolders) { - npx --no tsv $typespecFolder - if ($LASTEXITCODE) { - $exitCode = 1 - } - git restore . - git clean -df - } - - exit $exitCode displayName: TypespecValidation condition: succeededOrFailed() From 239b42c61d58b5f4ab0ba69daca875a7d77cbf45 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 13:20:45 -0700 Subject: [PATCH 13/24] write to std out --- eng/scripts/Validate-Typespec.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-Typespec.ps1 index c12f52dbce87..b61ddd31f489 100644 --- a/eng/scripts/Validate-Typespec.ps1 +++ b/eng/scripts/Validate-Typespec.ps1 @@ -14,7 +14,7 @@ $typespecFolders = &"$PSScriptRoot/Get-Typespec-Folders.ps1" "$SpecsRepoRootDire $exitCode = 0 foreach ($typespecFolder in $typespecFolders) { - npx --no tsv $typespecFolder + npx --no tsv $typespecFolder 2>&1 if ($LASTEXITCODE) { $exitCode = 1 } From 909325f966a7a2f3b90c26bf01fe5aa40f1ea9c0 Mon Sep 17 00:00:00 2001 From: Albert Date: Wed, 12 Jul 2023 13:28:24 -0700 Subject: [PATCH 14/24] write to std out --- eng/scripts/Validate-Typespec.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-Typespec.ps1 index b61ddd31f489..b6522a8d6215 100644 --- a/eng/scripts/Validate-Typespec.ps1 +++ b/eng/scripts/Validate-Typespec.ps1 @@ -14,7 +14,7 @@ $typespecFolders = &"$PSScriptRoot/Get-Typespec-Folders.ps1" "$SpecsRepoRootDire $exitCode = 0 foreach ($typespecFolder in $typespecFolders) { - npx --no tsv $typespecFolder 2>&1 + npx --no tsv $typespecFolder 2>&1 | Write-Host if ($LASTEXITCODE) { $exitCode = 1 } From 37adb144cf91c5b7817bffac03a695c8b6430d48 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 17:32:06 -0700 Subject: [PATCH 15/24] Add trailing newline --- eng/scripts/Validate-Typespec.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-Typespec.ps1 index b6522a8d6215..be5ae129671a 100644 --- a/eng/scripts/Validate-Typespec.ps1 +++ b/eng/scripts/Validate-Typespec.ps1 @@ -22,4 +22,4 @@ foreach ($typespecFolder in $typespecFolders) { git clean -df } -exit $exitCode \ No newline at end of file +exit $exitCode From 8f8915a7a31030e4e993ccb2f638298dc84834f0 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:15:34 -0700 Subject: [PATCH 16/24] Remove unused $typespecFolders variable --- eng/pipelines/typespec-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index c8bdae92056d..fdea3fa75ca2 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -43,7 +43,7 @@ jobs: - pwsh: | $typespecFolders = @() if ('$(Build.Reason)' -eq 'PullRequest') { - $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" + $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" } else { $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) From 6b83e5aa26f35da5e2e3c5ad3b3ab5e98c5ee7f7 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:15:44 -0700 Subject: [PATCH 17/24] Remove unused $typespecFolders variable --- eng/pipelines/typespec-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index fdea3fa75ca2..5843e3dae6ab 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -46,7 +46,7 @@ jobs: $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" } else { - $typespecFolders = $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) + $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) } displayName: TypespecValidation condition: succeededOrFailed() From 54c0b2f38fddb88689894c0bd189681438e6349d Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:17:50 -0700 Subject: [PATCH 18/24] Remove unused $typespecFolders variable --- eng/pipelines/typespec-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 5843e3dae6ab..cc34467962fb 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -41,7 +41,6 @@ jobs: condition: succeededOrFailed() - pwsh: | - $typespecFolders = @() if ('$(Build.Reason)' -eq 'PullRequest') { $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" } From af2a6695c4452c7847abe87749020e71447c33ba Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:20:25 -0700 Subject: [PATCH 19/24] Improve displayName --- eng/pipelines/typespec-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index cc34467962fb..cf7bfc647212 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -47,5 +47,5 @@ jobs: else { $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) } - displayName: TypespecValidation + displayName: Validate TypeSpec condition: succeededOrFailed() From 9095230ae5bede1bbd36defa454f631aaca7b98f Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:23:05 -0700 Subject: [PATCH 20/24] Rename Get-Typespec-Folders.ps1 to Get-TypeSpec-Folders.ps1 --- .../{Get-Typespec-Folders.ps1 => Get-TypeSpec-Folders.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eng/scripts/{Get-Typespec-Folders.ps1 => Get-TypeSpec-Folders.ps1} (100%) diff --git a/eng/scripts/Get-Typespec-Folders.ps1 b/eng/scripts/Get-TypeSpec-Folders.ps1 similarity index 100% rename from eng/scripts/Get-Typespec-Folders.ps1 rename to eng/scripts/Get-TypeSpec-Folders.ps1 From 97e46186dccc6ad175c629804e75433311b4fe77 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:23:29 -0700 Subject: [PATCH 21/24] Typespec -> TypeSpec --- eng/pipelines/typespec-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index cf7bfc647212..0ddfad59320c 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -42,7 +42,7 @@ jobs: - pwsh: | if ('$(Build.Reason)' -eq 'PullRequest') { - $(Build.SourcesDirectory)/eng/scripts/Validate-Typespec.ps1 $(Build.SourcesDirectory) "origin/${env:SYSTEM_PULLREQUEST_TARGETBRANCH}" "${env:SYSTEM_PULLREQUEST_SOURCECOMMITID}" + $(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) From 751408145521dbac480f67150e3db1f0875f465f Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:23:55 -0700 Subject: [PATCH 22/24] Typespec -> TypeSpec --- eng/scripts/Validate-Typespec.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-Typespec.ps1 index be5ae129671a..7bd3171d001f 100644 --- a/eng/scripts/Validate-Typespec.ps1 +++ b/eng/scripts/Validate-Typespec.ps1 @@ -10,7 +10,7 @@ param ( $typespecFolders = @() -$typespecFolders = &"$PSScriptRoot/Get-Typespec-Folders.ps1" "$SpecsRepoRootDirectory" "$TargetBranch" "$SourceBranch" +$typespecFolders = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" "$SpecsRepoRootDirectory" "$TargetBranch" "$SourceBranch" $exitCode = 0 foreach ($typespecFolder in $typespecFolders) { From 77110cf3a07a1c4b6b87cef6dc34bca063123789 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:24:08 -0700 Subject: [PATCH 23/24] Rename Validate-Typespec.ps1 to Validate-TypeSpec.ps1 --- eng/scripts/{Validate-Typespec.ps1 => Validate-TypeSpec.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename eng/scripts/{Validate-Typespec.ps1 => Validate-TypeSpec.ps1} (100%) diff --git a/eng/scripts/Validate-Typespec.ps1 b/eng/scripts/Validate-TypeSpec.ps1 similarity index 100% rename from eng/scripts/Validate-Typespec.ps1 rename to eng/scripts/Validate-TypeSpec.ps1 From dd1bf284281ef607a4cecb318c54badb07763a23 Mon Sep 17 00:00:00 2001 From: Mike Harder Date: Wed, 12 Jul 2023 18:24:36 -0700 Subject: [PATCH 24/24] Typespec -> TypeSpec --- eng/pipelines/typespec-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/typespec-ci.yml b/eng/pipelines/typespec-ci.yml index 0ddfad59320c..ed52aa37fe94 100644 --- a/eng/pipelines/typespec-ci.yml +++ b/eng/pipelines/typespec-ci.yml @@ -45,7 +45,7 @@ jobs: $(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) + $(Build.SourcesDirectory)/eng/scripts/Validate-TypeSpec.ps1 $(Build.SourcesDirectory) } displayName: Validate TypeSpec condition: succeededOrFailed()