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

APIView Creation from PR for Go #24000

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 34 additions & 14 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
NonShipping: false
LicenseCheck: true
IsSdkLibrary: true

ArtifactName: packages

steps:
- task: Powershell@2
Expand All @@ -19,6 +19,25 @@ steps:
displayName: Dump Package properties
condition: and(succeeded(), ${{ parameters.IsSdkLibrary }})

- pwsh: |
. $(Build.SourcesDirectory)/eng/scripts/apiview-helpers.ps1
$directoryToPublish = Join-Path -Path $(Build.ArtifactStagingDirectory) ${{ parameters.ArtifactName }}

New-APIViewArtifacts `
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
-OutputDirectory $(Build.ArtifactStagingDirectory) `
-DirectoryToPublish $directoryToPublish

Copy-Item "$(Build.ArtifactStagingDirectory)/PackageInfo" -Destination $directoryToPublish -Recurse
displayName: 'Create Go APIView Artifact'

- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
parameters:
ArtifactName: ${{ parameters.ArtifactName }}
ArtifactPath: "$(Build.ArtifactStagingDirectory)/${{ parameters.ArtifactName }}"
CustomCondition: and(succeeded(), ${{ parameters.IsSdkLibrary }})

# Second publish of PackageInfo to avoid breakng release pipeline, should be cleaned up once release pipeline is updated
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
parameters:
ArtifactName: "PackageInfo"
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,23 +46,24 @@ steps:

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

- task: Powershell@2
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved
inputs:
filePath: $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
arguments: >
-ServiceDirectory '${{parameters.ServiceDirectory}}'
-OutPath '$(Build.ArtifactStagingDirectory)'
-ApiKey '$(azuresdk-apiview-apikey)'
-SourceBranch '$(Build.SourceBranchName)'
-DefaultBranch '$(DefaultBranch)'
-ConfigFileDir '$(Build.ArtifactStagingDirectory)/PackageInfo'
-BuildId $(Build.BuildId)
- pwsh: |
. $(Build.SourcesDirectory)/eng/scripts/apiview-helpers.ps1
New-APIViewFromCI `
-ServiceDirectory '${{parameters.ServiceDirectory}}' `
-ArtifactPath '$(Build.ArtifactStagingDirectory)' `
-ApiKey '$(azuresdk-apiview-apikey)' `
-SourceBranch '$(Build.SourceBranchName)' `
-DefaultBranch '$(DefaultBranch)' `
-ConfigFileDir '$(Build.ArtifactStagingDirectory)/PackageInfo' `
-BuildId $(Build.BuildId) `
-RepoName '$(Build.Repository.Name)'
pwsh: true
workingDirectory: $(Pipeline.Workspace)
displayName: Create API review for Go
workingDirectory: $(Pipeline.Workspace)
condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true') , ne(variables['Build.Reason'],'PullRequest'), eq(variables['System.TeamProject'], 'internal'))

- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml

- ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), eq(variables['System.TeamProject'], 'internal')) }}:
- pwsh: |
. ./eng/common/scripts/common.ps1
Expand Down
39 changes: 0 additions & 39 deletions eng/scripts/Create-ApiReview.ps1

This file was deleted.

100 changes: 100 additions & 0 deletions eng/scripts/apiview-helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Write-Host "$PSScriptRoot"
. (Join-Path $PSScriptRoot .. common scripts common.ps1)

<#
.DESCRIPTION
Create .gosource APIVIew artifact for go
.PARAMETER ServiceDirectory
Thee name of the ServiceDirectory
.PARAMETER OutputDirectory
Base output Directory path for the generated gosource artifacts
.PARAMETER DirectoryToPublish
Directory containing all artifacts to be publisehd to the pipeline
#>
function New-APIViewArtifacts {
Param(
[Parameter(Mandatory=$True)]
[string] $ServiceDirectory,
[Parameter(Mandatory=$True)]
[string] $OutputDirectory,
[Parameter(Mandatory=$True)]
[string] $DirectoryToPublish
)

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

$artifactParentDirectory = $sdk.Name -Split "/" | Select-Object -First 1
Copy-Item "$OutputDirectory/$artifactParentDirectory" -Destination "$DirectoryToPublish/$artifactParentDirectory" -Recurse
}
}

<#
.DESCRIPTION
Create new automatic APIView from a CI run
.PARAMETER ServiceDirectory
Thee name of the ServiceDirectory
.PARAMETER ArtifactPath
Directory containing the gosources artifact
.PARAMETER ApiKey
The APIview ApiKey
.PARAMETER SourceBranch
SourceBranch
.PARAMETER DefaultBranch
DefaultBranch
.PARAMETER ConfigFileDir
Path to the ConfigFileDir as published in the pipeline
.PARAMETER RepoName
The name of the repository
.PARAMETER BuildId
The build Id of the pipeline run
.PARAMETER MarkPackageAsShipped
Indicate weather to mark the package a s shipped
#>
function New-APIViewFromCI {
Param(
[Parameter(Mandatory=$True)]
[string] $ServiceDirectory,
[Parameter(Mandatory=$True)]
[string] $ArtifactPath,
[Parameter(Mandatory=$True)]
[string] $ApiKey,
[Parameter(Mandatory=$True)]
[string] $SourceBranch,
[Parameter(Mandatory=$True)]
[string] $DefaultBranch,
[Parameter(Mandatory=$True)]
[string] $ConfigFileDir,
[string] $RepoName,
[string] $BuildId,
[bool] $MarkPackageAsShipped = $false
)
$artifactList = @()

Get-AllPackageInfoFromRepo $ServiceDirectory | ForEach-Object {
$artifactList += [PSCustomObject]@{
name = $sdk.Name
}
}

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

Write-Host "Create Go APIView using generated artifacts"
&($createReviewScript) `
-ArtifactList $artifactList `
-ArtifactPath $ArtifactPath `
-APIKey $ApiKey `
-SourceBranch $SourceBranch `
-DefaultBranch $DefaultBranch `
-ConfigFileDir $ConfigFileDir `
-RepoName $RepoName `
-BuildId $BuildId `
-MarkPackageAsShipped $MarkPackageAsShipped
}