From 41124f2b32e5d82820d1491c96455f38ca7f63fe Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 12 Dec 2024 16:40:48 -0800 Subject: [PATCH 1/7] get typespec project --- eng/scripts/Create-APIView.ps1 | 51 ++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index f219279f1892..831dac2419d6 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -86,6 +86,27 @@ function Get-ResourceProviderFromReadMePath { return $null } +function Get-ImpactedTypespecProjects { + param ( + [Parameter(Mandatory = $true)] + [string]$TypeSpecFile + ) + $projectRootPaths = [System.Collections.Generic.HashSet[string]]::new() + $filePathParts = $TypeSpecFile.split([IO.Path]::DirectorySeparatorChar) + $typeSpecProjectBaseDirectory = $filePathParts[0..$($filePathParts.IndexOf("specification")+2)] -join [IO.Path]::DirectorySeparatorChar + $configFilesInTypeSpecProjects = Get-ChildItem -Path $typeSpecProjectBaseDirectory -File "tspconfig.yaml" -Recurse + if ($configFilesInTypeSpecProjects) { + foreach($configFilesInTypeSpecProject in $configFilesInTypeSpecProjects) { + $entryPointFile = Get-ChildItem -Path $($configFilesInTypeSpecProject.Directory.FullName) -File "main.tsp" + if ($entryPointFile) { + $projectRootPaths.Add($configFilesInTypeSpecProject.Directory.FullName) | Out-Null + Write-Host "Found $($configFilesInTypeSpecProject.Name) and $($entryPointFile.Name) in directory $($configFilesInTypeSpecProject.Directory.FullName)" + } + } + } + return $projectRootPaths +} + <# .DESCRIPTION Invoke the swagger parset to generate APIView tokens. @@ -366,12 +387,32 @@ function New-TypeSpecAPIViewTokens { $SourceCommitId = $(git rev-parse HEAD^) $TargetCommitId = $(git rev-parse HEAD) - $typeSpecProjects, $null = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" ` - -IgnoreCoreFiles:$true ` - -BaseCommitish:$SourceCommitId ` - -TargetCommitish:$TargetCommitId + LogInfo " Getting changed TypeSpec files in PR, between $SourceCommitId and $TargetCommitId" + $changedFiles = Get-ChangedFiles -baseCommitish $SourceCommitId -targetCommitish $TargetCommitId + $changedTypeSpecFiles = Get-ChangedTypeSpecFiles -changedFiles $changedFiles - $typeSpecProjects = $typeSpecProjects | Where-Object {Test-Path -Path "$_/main.tsp"} + if ($changedTypeSpecFiles.Count -eq 0) { + LogWarning " There are no changes to TypeSpec files in the current PR..." + Write-Host "##vso[task.complete result=SucceededWithIssues;]DONE" + exit 0 + } + + LogGroupStart " Pullrequest has changes in these TypeSpec files..." + $changedTypeSpecFiles | ForEach-Object { + LogInfo " - $_" + } + LogGroupEnd + + # Get impacted TypeSpec projects + $typeSpecProjects = [System.Collections.Generic.HashSet[string]]::new() + $changedTypeSpecFiles | ForEach-Object { + $tspProjs = Get-ImpactedTypespecProjects -TypeSpecFile "$_" + if ($tspProjs) { + foreach ($tspProj in $tspProjs) { + $typeSpecProjects.Add($tspProj) | Out-Null + } + } + } LogGroupStart " TypeSpec APIView Tokens will be generated for the following configuration files..." $typeSpecProjects | ForEach-Object { From 30beb3497c589bd4c9bd7aca4e6532a7b9ee37a4 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 13 Dec 2024 11:19:54 -0800 Subject: [PATCH 2/7] fix dir path --- eng/scripts/Create-APIView.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index 831dac2419d6..530f21f1f6a6 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -93,7 +93,7 @@ function Get-ImpactedTypespecProjects { ) $projectRootPaths = [System.Collections.Generic.HashSet[string]]::new() $filePathParts = $TypeSpecFile.split([IO.Path]::DirectorySeparatorChar) - $typeSpecProjectBaseDirectory = $filePathParts[0..$($filePathParts.IndexOf("specification")+2)] -join [IO.Path]::DirectorySeparatorChar + $typeSpecProjectBaseDirectory = $filePathParts[0..($($filePathParts.Length)-2)] -join [IO.Path]::DirectorySeparatorChar $configFilesInTypeSpecProjects = Get-ChildItem -Path $typeSpecProjectBaseDirectory -File "tspconfig.yaml" -Recurse if ($configFilesInTypeSpecProjects) { foreach($configFilesInTypeSpecProject in $configFilesInTypeSpecProjects) { @@ -102,6 +102,9 @@ function Get-ImpactedTypespecProjects { $projectRootPaths.Add($configFilesInTypeSpecProject.Directory.FullName) | Out-Null Write-Host "Found $($configFilesInTypeSpecProject.Name) and $($entryPointFile.Name) in directory $($configFilesInTypeSpecProject.Directory.FullName)" } + else { + Write-Host "Did not find main.tsp in directory $($configFilesInTypeSpecProject.Directory.FullName)" + } } } return $projectRootPaths From 866cea873daf647ebffa05e02cde72422a6eaa71 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Fri, 13 Dec 2024 11:20:55 -0800 Subject: [PATCH 3/7] test --- .../contosowidgetmanager/Contoso.Management/employee.tsp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/specification/contosowidgetmanager/Contoso.Management/employee.tsp b/specification/contosowidgetmanager/Contoso.Management/employee.tsp index b796033881f6..ca8ad2ec43f7 100644 --- a/specification/contosowidgetmanager/Contoso.Management/employee.tsp +++ b/specification/contosowidgetmanager/Contoso.Management/employee.tsp @@ -17,12 +17,6 @@ model Employee is TrackedResource { /** Employee properties */ model EmployeeProperties { - /** Age of employee */ - age?: int32; - - /** City of employee */ - city?: string; - /** Profile of employee */ @encode("base64url") profile?: bytes; From 0d6a150c6d3bfc02563c4afe564383a19d374a18 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 19 Dec 2024 20:24:56 -0800 Subject: [PATCH 4/7] fix source and target branch --- eng/scripts/Create-APIView.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index 530f21f1f6a6..6309dec49297 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -387,8 +387,8 @@ function New-TypeSpecAPIViewTokens { [string]$APIViewArtifactsDirectoryName ) - $SourceCommitId = $(git rev-parse HEAD^) - $TargetCommitId = $(git rev-parse HEAD) + $SourceCommitId = $(git rev-parse HEAD^2) + $TargetCommitId = $(git rev-parse HEAD^1) LogInfo " Getting changed TypeSpec files in PR, between $SourceCommitId and $TargetCommitId" $changedFiles = Get-ChangedFiles -baseCommitish $SourceCommitId -targetCommitish $TargetCommitId From eece601080c1b10d517c75901d570a20dfd37e8a Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 19 Dec 2024 21:01:58 -0800 Subject: [PATCH 5/7] adjust to pr comment --- eng/scripts/Create-APIView.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index 6309dec49297..6a05488bcdf9 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -91,23 +91,25 @@ function Get-ImpactedTypespecProjects { [Parameter(Mandatory = $true)] [string]$TypeSpecFile ) - $projectRootPaths = [System.Collections.Generic.HashSet[string]]::new() $filePathParts = $TypeSpecFile.split([IO.Path]::DirectorySeparatorChar) - $typeSpecProjectBaseDirectory = $filePathParts[0..($($filePathParts.Length)-2)] -join [IO.Path]::DirectorySeparatorChar - $configFilesInTypeSpecProjects = Get-ChildItem -Path $typeSpecProjectBaseDirectory -File "tspconfig.yaml" -Recurse + while ($filePathParts.Length -and !$configFilesInTypeSpecProjects) { + $filePathParts = $filePathParts | Select-Object -SkipLast 1 + $typeSpecProjectBaseDirectory = $filePathParts -join [IO.Path]::DirectorySeparatorChar + $configFilesInTypeSpecProjects = Get-ChildItem -Path $typeSpecProjectBaseDirectory -File "tspconfig.yaml" + } + if ($configFilesInTypeSpecProjects) { foreach($configFilesInTypeSpecProject in $configFilesInTypeSpecProjects) { $entryPointFile = Get-ChildItem -Path $($configFilesInTypeSpecProject.Directory.FullName) -File "main.tsp" if ($entryPointFile) { - $projectRootPaths.Add($configFilesInTypeSpecProject.Directory.FullName) | Out-Null Write-Host "Found $($configFilesInTypeSpecProject.Name) and $($entryPointFile.Name) in directory $($configFilesInTypeSpecProject.Directory.FullName)" + return $configFilesInTypeSpecProject.Directory.FullName } else { Write-Host "Did not find main.tsp in directory $($configFilesInTypeSpecProject.Directory.FullName)" } } } - return $projectRootPaths } <# @@ -409,11 +411,9 @@ function New-TypeSpecAPIViewTokens { # Get impacted TypeSpec projects $typeSpecProjects = [System.Collections.Generic.HashSet[string]]::new() $changedTypeSpecFiles | ForEach-Object { - $tspProjs = Get-ImpactedTypespecProjects -TypeSpecFile "$_" - if ($tspProjs) { - foreach ($tspProj in $tspProjs) { - $typeSpecProjects.Add($tspProj) | Out-Null - } + $tspProj = Get-ImpactedTypespecProjects -TypeSpecFile "$_" + if ($tspProj) { + $typeSpecProjects.Add($tspProj) | Out-Null } } From 9461772198c5bf92b9be7ffad600fd81623a6edd Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 19 Dec 2024 21:05:28 -0800 Subject: [PATCH 6/7] decrease log size --- eng/scripts/Create-APIView.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index 6a05488bcdf9..467cc2cd6a49 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -435,7 +435,9 @@ function New-TypeSpecAPIViewTokens { git checkout $SourceCommitId Write-Host "Installing required dependencies to generate New API review" npm ci + LogGroupStart "npm ls -a" npm ls -a + LogGroupEnd foreach ($typeSpecProject in $typeSpecProjects) { $tokenDirectory = [System.IO.Path]::Combine($typeSpecAPIViewArtifactsDirectory, $typeSpecProject.split([IO.Path]::DirectorySeparatorChar)[-1]) New-Item -ItemType Directory -Path $tokenDirectory -Force | Out-Null @@ -446,7 +448,9 @@ function New-TypeSpecAPIViewTokens { git checkout $TargetCommitId Write-Host "Installing required dependencies to generate Baseline API review" npm ci + LogGroupStart "npm ls -a" npm ls -a + LogGroupEnd foreach ($typeSpecProject in $typeSpecProjects) { # Skip Baseline APIView Token for new projects if (!(Test-Path -Path $typeSpecProject)) { From e374fad5ed22490dc710e28ca4219b55176e6862 Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Thu, 19 Dec 2024 21:15:07 -0800 Subject: [PATCH 7/7] get changed files --- eng/scripts/Create-APIView.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index 467cc2cd6a49..df19d32128a9 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -393,7 +393,7 @@ function New-TypeSpecAPIViewTokens { $TargetCommitId = $(git rev-parse HEAD^1) LogInfo " Getting changed TypeSpec files in PR, between $SourceCommitId and $TargetCommitId" - $changedFiles = Get-ChangedFiles -baseCommitish $SourceCommitId -targetCommitish $TargetCommitId + $changedFiles = Get-ChangedFiles $changedTypeSpecFiles = Get-ChangedTypeSpecFiles -changedFiles $changedFiles if ($changedTypeSpecFiles.Count -eq 0) {