diff --git a/eng/pipelines/templates/steps/build.yml b/eng/pipelines/templates/steps/build.yml index ec174fa4b38b..5dbb326f67e2 100644 --- a/eng/pipelines/templates/steps/build.yml +++ b/eng/pipelines/templates/steps/build.yml @@ -68,11 +68,6 @@ steps: node eng/tools/rush-runner.js unlink displayName: "Unlink dependencies" - - template: /eng/common/pipelines/templates/steps/create-apireview.yml - parameters: - Artifacts: ${{ parameters.Artifacts }} - ArtifactPath: $(Build.SourcesDirectory)/sdk/${{ parameters.ServiceDirectory }} - - template: ../steps/generate-doc.yml parameters: ServiceDirectory: ${{parameters.ServiceDirectory}} @@ -94,7 +89,19 @@ steps: } displayName: 'Copy Packages' + - pwsh: | + 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)' ArtifactName: 'packages' + + - template: /eng/common/pipelines/templates/steps/create-apireview.yml + parameters: + Artifacts: ${{ parameters.Artifacts }} + + - template: /eng/common/pipelines/templates/steps/detect-api-changes.yml + parameters: + Artifacts: ${{ parameters.Artifacts }} diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index 8cefb93fe473..9408470e5b89 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -404,26 +404,23 @@ Removed $($package.name) because of docs package validation failure on $(Get-Dat } # function is used to auto generate API View -function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName = "") +function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName) { - # Find api.json file in service temp directory - [regex]$pattern = "azure-" - $pkgName = $pattern.replace($packageName, "", 1) - $packageDir = Join-Path $artifactDir $pkgName "temp" - if (Test-Path $packageDir) + $artifactPath = Join-Path $artifactDir $packageName + if (Test-Path $artifactPath) { - Write-Host "Searching for *.api.json in path $($packageDir)" - $files = Get-ChildItem "${packageDir}" | Where-Object -FilterScript { $_.Name.EndsWith(".api.json") } + Write-Host "Searching for *.api.json in path $($artifactPath)" + $files = Get-ChildItem "${artifactPath}" | Where-Object -FilterScript { $_.Name.EndsWith(".api.json") } if (!$files) { - Write-Host "$($packageDir) 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 "$($packageDir) should contain only one api review for $($packageName)" - Write-Host "No of Packages $($files.Count)" + Write-Host "$($artifactPath) should contain only one api review for $($packageName)" + Write-Host "No of files $($files.Count)" return $null } } @@ -431,8 +428,7 @@ function Find-javascript-Artifacts-For-Apireview($artifactDir, $packageName = "" { Write-Host "$($pkgName) does not have api review json" return $null - } - + } $packages = @{ $files[0].Name = $files[0].FullName } diff --git a/eng/scripts/stage-api-review-file.ps1 b/eng/scripts/stage-api-review-file.ps1 new file mode 100644 index 000000000000..747eea5a1caa --- /dev/null +++ b/eng/scripts/stage-api-review-file.ps1 @@ -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) + { + # 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" + } +}