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

Publish api json file and enable api change detection #17837

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion eng/pipelines/templates/steps/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ steps:
New-Item -Type Directory -Name $artifactName -Path $(Build.ArtifactStagingDirectory) > $null
Copy-Item sdk/${{parameters.ServiceDirectory}}/**/$artifactName-[0-9]*.[0-9]*.[0-9]*.tgz $(Build.ArtifactStagingDirectory)/$artifactName
Copy-Item sdk/${{parameters.ServiceDirectory}}/**/browser/$artifactName-[0-9]*.[0-9]*.[0-9]*.zip $(Build.ArtifactStagingDirectory)/$artifactName
Copy-Item sdk/${{parameters.ServiceDirectory}}/**/temp/*.api.json $(Build.ArtifactStagingDirectory)/$artifactName
if ($${{ parameters.IncludeRelease }} -eq $true)
{
New-Item -Type Directory -Name documentation -Path $(Build.ArtifactStagingDirectory)/$artifactName > $null
Expand All @@ -90,6 +89,10 @@ steps:
}
displayName: 'Copy Packages'

- script: |
eng/scripts/stage-api-review-file.ps1 -PackageInfoPath $(Build.ArtifactStagingDirectory)/PackageInfo -StagingDirectory $(Build.ArtifactStagingDirectory)
displayName: 'Copy API extracted files'

- template: /eng/common/pipelines/templates/steps/publish-artifact.yml
parameters:
ArtifactPath: '$(Build.ArtifactStagingDirectory)'
Expand Down
4 changes: 2 additions & 2 deletions eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName)
$files = Get-ChildItem "${artifactPath}" | Where-Object -FilterScript { $_.Name.EndsWith(".api.json") }
if (!$files)
{
Write-Host "$($artifactPath) does not have api review json for package"
Write-Host "$($packageName) does not have api review json"
Write-Host "API Extractor must be enabled for $($packageName). Please ensure api-extractor.json is present in package directory and api extract script included in build script"
return $null
}
elseif ($files.Count -ne 1)
{
Write-Host "$($artifactPath) should contain only one api review for $($packageName)"
Write-Host "No of Packages $($files.Count)"
Write-Host "No of files $($files.Count)"
return $null
}
}
Expand Down
50 changes: 50 additions & 0 deletions eng/scripts/stage-api-review-file.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
param (
[Parameter(mandatory = $true)]
$PackageInfoPath,
[Parameter(mandatory = $true)]
$StagingDirectory
)

if (!((Test-Path $PackageInfoPath) -and (Test-Path $StagingDirectory)))
{
Write-Error "Invalid parameter values. Pleaes verify values for these parameters."
exit 1
}

foreach($pkg in (Get-ChildItem -Path $PackageInfoPath "*.json"))
{
$info = Get-Content -Path $pkg.FullName | ConvertFrom-Json
$apiFilePath = Join-Path $info.DirectoryPath "temp"
if (Test-Path $apiFilePath)
{
$apiFile = Get-ChildItem -Path $apiFilePath "*.api.json"
if ($apiFile)
{
if ($apiFile.Count -ne 1)
Copy link
Member

Choose a reason for hiding this comment

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

Does this always give back a list? I know PS sometimes gives back a single object if there is only one in the list.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe so. It was working when referring it directly without index also. I thought of adding this check to avoid any issue if we get any such scenario.

{
# Unlikely, but handling to avoid any issue in the future if more than one api file is present here
Write-Error "Detected more than one api extracted file in $apiFilePath"
exit 1
}

$pkgStagingDir = Join-Path $StagingDirectory $info.ArtifactName
if (!(Test-Path $pkgStagingDir))
{
New-Item -Type Directory -Name $info.ArtifactName -Path $StagingDirectory > $null
}
$sourceFilePath = $apiFile[0].FullName
$targetFilePath = "$($pkgStagingDir)/$($info.ArtifactName)_$($info.Version).api.json"
Write-Host "Copying $($sourceFilePath) to $($targetFilePath)"
Copy-Item $sourceFilePath $targetFilePath
}
else
{
# Not an error is api-extractor is not cofigured/ required for a package
Write-Host "API extracted file is not present for package $($info.Name)"
}
}
else
{
Write-Host "Directory $($apiFilePath) is not present in package root to search for api-extracted file"
}
}