Skip to content

Commit

Permalink
Enable API review gen in CI for Go (#18235)
Browse files Browse the repository at this point in the history
* Enable API review gen in CI for Go
  • Loading branch information
praveenkuttappan committed May 26, 2022
1 parent d17638f commit 931f528
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
31 changes: 31 additions & 0 deletions eng/pipelines/templates/steps/build-test.yml
Expand Up @@ -82,6 +82,37 @@ steps:
inputs:
BuildDropPath: $(Build.ArtifactStagingDirectory)

- task: Powershell@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/common/scripts/Save-Package-Properties.ps1
arguments: >
-ServiceDirectory ${{parameters.ServiceDirectory}}
-OutDirectory $(Build.ArtifactStagingDirectory)/PackageInfo
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Dump Package properties
condition: succeeded()

- template: /eng/common/pipelines/templates/steps/set-default-branch.yml

- task: Powershell@2
inputs:
filePath: $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
arguments: >
-ServiceDirectory ${{parameters.ServiceDirectory}}
-OutPath $(Build.ArtifactStagingDirectory)
-ApiviewUri "$(azuresdk-apiview-uri)"
-ApiKey "$(azuresdk-apiview-apikey)"
-ApiLabel "Auto Review - $(Build.SourceVersion)"
-SourceBranch $(Build.SourceBranchName)
-DefaultBranch $(DefaultBranch)
-ConfigFileDir $(Build.ArtifactStagingDirectory)/PackageInfo
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Create API review for Go
continueOnError: true
condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true') , ne(variables['Build.Reason'],'PullRequest'), eq(variables['System.TeamProject'], 'internal'))

- template: /eng/common/pipelines/templates/steps/publish-artifact.yml
parameters:
ArtifactPath: '$(Build.ArtifactStagingDirectory)/_manifest'
Expand Down
35 changes: 35 additions & 0 deletions eng/scripts/Create-ApiReview.ps1
@@ -0,0 +1,35 @@
Param(
[Parameter(Mandatory=$True)]
[string] $ServiceDirectory,
[Parameter(Mandatory=$True)]
[string] $OutPath,
[Parameter(Mandatory=$True)]
[string] $ApiviewUri,
[Parameter(Mandatory=$True)]
[string] $ApiKey,
[Parameter(Mandatory=$True)]
[string] $ApiLabel,
[Parameter(Mandatory=$True)]
[string] $SourceBranch,
[Parameter(Mandatory=$True)]
[string] $DefaultBranch,
[Parameter(Mandatory=$True)]
[string] $ConfigFileDir
)


Write-Host "$PSScriptRoot"
. (Join-Path $PSScriptRoot .. common scripts common.ps1)
$createReviewScript = (Join-Path $PSScriptRoot .. common scripts Create-APIReview.ps1)

foreach ($sdk in (Get-AllPackageInfoFromRepo $ServiceDirectory))
{
Write-Host "Creating API review artifact for $($sdk.Name)"
New-Item -ItemType Directory -Path $OutPath/$($sdk.Name) -force
$fileName = Split-Path -Path $sdk.Name -Leaf
Compress-Archive -Path $sdk.DirectoryPath -DestinationPath $outPath/$($sdk.Name)/$fileName -force
Rename-Item $outPath/$($sdk.Name)/$fileName.zip -NewName "$fileName.gosource"

Write-Host "Send request to APIView to create review for $($sdk.Name)"
&($createReviewScript) -ArtifactPath $outPath -APIViewUri $ApiviewUri -APIKey $ApiKey -APILabel $ApiLabel -PackageName $sdk.Name -SourceBranch $SourceBranch -DefaultBranch $DefaultBranch -ConfigFileDir $ConfigFileDir
}
14 changes: 14 additions & 0 deletions eng/scripts/Language-Settings.ps1
Expand Up @@ -130,3 +130,17 @@ function SetPackageVersion ($PackageName, $Version, $ReleaseDate, $PackageProper
-ReleaseDate $ReleaseDate `
-ReplaceLatestEntryTitle $ReplaceLatestEntryTitle
}


function Find-Go-Artifacts-For-Apireview($ArtifactPath, $PackageName)
{
$artifact = Get-ChildItem -Path (Join-Path $ArtifactPath $PackageName) -Filter "*.gosource"
if ($artifact)
{
$packages = @{
$artifact.FullName = $artifact.FullName
}
return $packages
}
return $null
}

0 comments on commit 931f528

Please sign in to comment.