Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeSpec APIView] Ensure apiview only triggers on packages directly changed by the pr #31871

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
54 changes: 49 additions & 5 deletions eng/scripts/Create-APIView.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ function Get-ResourceProviderFromReadMePath {
return $null
}

function Get-ImpactedTypespecProjects {
ckairen marked this conversation as resolved.
Show resolved Hide resolved
param (
[Parameter(Mandatory = $true)]
[string]$TypeSpecFile
)
$projectRootPaths = [System.Collections.Generic.HashSet[string]]::new()
ckairen marked this conversation as resolved.
Show resolved Hide resolved
$filePathParts = $TypeSpecFile.split([IO.Path]::DirectorySeparatorChar)
$typeSpecProjectBaseDirectory = $filePathParts[0..($($filePathParts.Length)-2)] -join [IO.Path]::DirectorySeparatorChar
ckairen marked this conversation as resolved.
Show resolved Hide resolved
$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"
ckairen marked this conversation as resolved.
Show resolved Hide resolved
if ($entryPointFile) {
$projectRootPaths.Add($configFilesInTypeSpecProject.Directory.FullName) | Out-Null
ckairen marked this conversation as resolved.
Show resolved Hide resolved
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
}

<#
.DESCRIPTION
Invoke the swagger parset to generate APIView tokens.
Expand Down Expand Up @@ -366,12 +390,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

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 {
$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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ model Employee is TrackedResource<EmployeeProperties> {

/** Employee properties */
model EmployeeProperties {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
model EmployeeProperties {
model EmployeeProperties {
/** Age of employee */
age?: int32;
/** City of employee */
city?: string;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp removal for testing

/** Age of employee */
age?: int32;

/** City of employee */
city?: string;

/** Profile of employee */
@encode("base64url")
profile?: bytes;
Expand Down
Loading