diff --git a/eng/scripts/Create-APIView.ps1 b/eng/scripts/Create-APIView.ps1 index f219279f1892..df19d32128a9 100644 --- a/eng/scripts/Create-APIView.ps1 +++ b/eng/scripts/Create-APIView.ps1 @@ -86,6 +86,32 @@ function Get-ResourceProviderFromReadMePath { return $null } +function Get-ImpactedTypespecProjects { + param ( + [Parameter(Mandatory = $true)] + [string]$TypeSpecFile + ) + $filePathParts = $TypeSpecFile.split([IO.Path]::DirectorySeparatorChar) + 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) { + 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)" + } + } + } +} + <# .DESCRIPTION Invoke the swagger parset to generate APIView tokens. @@ -363,15 +389,33 @@ 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 + $changedTypeSpecFiles = Get-ChangedTypeSpecFiles -changedFiles $changedFiles - $typeSpecProjects, $null = &"$PSScriptRoot/Get-TypeSpec-Folders.ps1" ` - -IgnoreCoreFiles:$true ` - -BaseCommitish:$SourceCommitId ` - -TargetCommitish:$TargetCommitId + 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 + } - $typeSpecProjects = $typeSpecProjects | Where-Object {Test-Path -Path "$_/main.tsp"} + 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 { + $tspProj = Get-ImpactedTypespecProjects -TypeSpecFile "$_" + if ($tspProj) { + $typeSpecProjects.Add($tspProj) | Out-Null + } + } LogGroupStart " TypeSpec APIView Tokens will be generated for the following configuration files..." $typeSpecProjects | ForEach-Object { @@ -391,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 @@ -402,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)) { 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;