Skip to content

Commit 47fbccc

Browse files
APIView Creation from PR for Go
1 parent c12b01f commit 47fbccc

2 files changed

Lines changed: 183 additions & 48 deletions

File tree

eng/pipelines/templates/steps/analyze.yml

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
NonShipping: false
66
LicenseCheck: true
77
IsSdkLibrary: true
8+
APIViewArtifactsName: "APIViewArtifacts"
89

910

1011
steps:
@@ -24,26 +25,42 @@ steps:
2425
ArtifactName: "PackageInfo"
2526
ArtifactPath: "$(Build.ArtifactStagingDirectory)/PackageInfo"
2627
CustomCondition: and(succeeded(), ${{ parameters.IsSdkLibrary }})
27-
2828
- template: /eng/common/pipelines/templates/steps/set-default-branch.yml
2929

30-
- task: Powershell@2
31-
inputs:
32-
filePath: $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
33-
arguments: >
34-
-ServiceDirectory '${{parameters.ServiceDirectory}}'
35-
-OutPath '$(Build.ArtifactStagingDirectory)'
36-
-ApiKey '$(azuresdk-apiview-apikey)'
37-
-SourceBranch '$(Build.SourceBranchName)'
38-
-DefaultBranch '$(DefaultBranch)'
39-
-ConfigFileDir '$(Build.ArtifactStagingDirectory)/PackageInfo'
40-
-BuildId $(Build.BuildId)
30+
- pwsh: |
31+
. $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
32+
New-APIView-From-CI `
33+
-ServiceDirectory '${{parameters.ServiceDirectory}}' `
34+
-ArtifactOutputDirectory '$(Build.ArtifactStagingDirectory)' `
35+
-ApiKey '$(azuresdk-apiview-apikey)' `
36+
-SourceBranch '$(Build.SourceBranchName)' `
37+
-DefaultBranch '$(DefaultBranch)' `
38+
-ConfigFileDir '$(Build.ArtifactStagingDirectory)/PackageInfo' `
39+
-BuildId $(Build.BuildId) `
4140
-RepoName '$(Build.Repository.Name)'
42-
pwsh: true
43-
workingDirectory: $(Pipeline.Workspace)
4441
displayName: Create API review for Go
42+
workingDirectory: $(Pipeline.Workspace)
4543
condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true') , ne(variables['Build.Reason'],'PullRequest'), eq(variables['System.TeamProject'], 'internal'))
4644
45+
- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
46+
- pwsh: |
47+
. $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
48+
$_ = Create-APIViewArtifact `
49+
-ServiceDirectory '${{parameters.ServiceDirectory}}' `
50+
-ArtifactOutputDirectory '$(Build.ArtifactStagingDirectory)' `
51+
-ArtifactName '${{parameters.APIViewArtifactsName}}'
52+
displayName: Create APIView Artifact
53+
workingDirectory: $(Pipeline.Workspace)
54+
55+
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
56+
parameters:
57+
ArtifactName: "${{parameters.APIViewArtifactsName}}"
58+
ArtifactPath: "$(Build.ArtifactStagingDirectory)/${{parameters.APIViewArtifactsName}}"
59+
60+
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
61+
parameters:
62+
ArtifactName: '${{parameters.APIViewArtifactsName}}'
63+
4764
- ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), eq(variables['System.TeamProject'], 'internal')) }}:
4865
- pwsh: |
4966
. ./eng/common/scripts/common.ps1

eng/scripts/Create-ApiReview.ps1

Lines changed: 152 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,157 @@
1-
Param(
2-
[Parameter(Mandatory=$True)]
3-
[string] $ServiceDirectory,
4-
[Parameter(Mandatory=$True)]
5-
[string] $OutPath,
6-
[Parameter(Mandatory=$True)]
7-
[string] $ApiKey,
8-
[Parameter(Mandatory=$True)]
9-
[string] $SourceBranch,
10-
[Parameter(Mandatory=$True)]
11-
[string] $DefaultBranch,
12-
[Parameter(Mandatory=$True)]
13-
[string] $ConfigFileDir,
14-
[string] $RepoName,
15-
[string] $BuildId,
16-
[bool] $MarkPackageAsShipped = $false
17-
)
18-
19-
201
Write-Host "$PSScriptRoot"
212
. (Join-Path $PSScriptRoot .. common scripts common.ps1)
22-
$createReviewScript = (Join-Path $PSScriptRoot .. common scripts Create-APIReview.ps1)
23-
24-
$artifactList = @()
25-
foreach ($sdk in (Get-AllPackageInfoFromRepo $ServiceDirectory))
26-
{
27-
Write-Host "Creating API review artifact for $($sdk.Name)"
28-
New-Item -ItemType Directory -Path $OutPath/$($sdk.Name) -force
29-
$fileName = Split-Path -Path $sdk.Name -Leaf
30-
Compress-Archive -Path $sdk.DirectoryPath -DestinationPath $outPath/$($sdk.Name)/$fileName -force
31-
Rename-Item $outPath/$($sdk.Name)/$fileName.zip -NewName "$fileName.gosource"
32-
33-
$artifactList += [PSCustomObject]@{
34-
name = $sdk.Name
3+
4+
<#
5+
.DESCRIPTION
6+
Create .gosource APIVIew artifact for go
7+
.PARAMETER ServiceDirectory
8+
Thee name of the ServiceDirectory
9+
.PARAMETER ArtifactOutputDirectory
10+
Base output Directory path for the generated gosource artifacts
11+
.PARAMETER ArtifactName
12+
Name of the group of artifacts to be created
13+
#>
14+
function Create-APIViewArtifact {
15+
Param(
16+
[Parameter(Mandatory=$True)]
17+
[string] $ServiceDirectory,
18+
[Parameter(Mandatory=$True)]
19+
[string] $ArtifactOutputDirectory,
20+
[Parameter(Mandatory=$True)]
21+
[string] $ArtifactName
22+
)
23+
24+
$artifactList = @()
25+
26+
$artifactsDirectoryPath = Join-Path -Path $ArtifactOutputDirectory $ArtifactName
27+
New-Item -ItemType Directory -Path $artifactsDirectoryPath -force
28+
29+
foreach ($sdk in (Get-AllPackageInfoFromRepo $ServiceDirectory))
30+
{
31+
Write-Host "Creating API review artifact for $($sdk.Name)"
32+
New-Item -ItemType Directory -Path $artifactsDirectoryPath/$($sdk.Name) -force
33+
$fileName = Split-Path -Path $sdk.Name -Leaf
34+
Compress-Archive -Path $sdk.DirectoryPath -DestinationPath $artifactsDirectoryPath/$($sdk.Name)/$fileName -force
35+
Rename-Item $artifactsDirectoryPath/$($sdk.Name)/$fileName.zip -NewName "$fileName.gosource"
36+
37+
$artifactList += [PSCustomObject]@{
38+
name = $sdk.Name
39+
}
3540
}
41+
return $artifactList
3642
}
3743

38-
Write-Host "Create Go APIView using generated artifacts"
39-
&($createReviewScript) -ArtifactList $artifactList -ArtifactPath $outPath -APIKey $ApiKey -SourceBranch $SourceBranch -DefaultBranch $DefaultBranch -ConfigFileDir $ConfigFileDir -RepoName $RepoName -BuildId $BuildId -MarkPackageAsShipped $MarkPackageAsShipped
44+
<#
45+
.DESCRIPTION
46+
Create new automatic APIView from a CI run
47+
.PARAMETER ServiceDirectory
48+
Thee name of the ServiceDirectory
49+
.PARAMETER ArtifactOutputDirectory
50+
Base output Directory path for the generated gosource artifacts
51+
.PARAMETER ArtifactName
52+
Name of the group of artifacts to be created
53+
.PARAMETER ApiKey
54+
The APIview ApiKey
55+
.PARAMETER SourceBranch
56+
SourceBranch
57+
.PARAMETER DefaultBranch
58+
DefaultBranch
59+
.PARAMETER ConfigFileDir
60+
Path to the ConfigFileDir as published in the pipeline
61+
.PARAMETER RepoName
62+
The name of the repository
63+
.PARAMETER BuildId
64+
The build Id of the pipeline run
65+
.PARAMETER MarkPackageAsShipped
66+
Indicate weather to mark the package a s shipped
67+
#>
68+
function New-APIView-From-CI {
69+
Param(
70+
[Parameter(Mandatory=$True)]
71+
[string] $ServiceDirectory,
72+
[Parameter(Mandatory=$True)]
73+
[string] $ArtifactOutputDirectory,
74+
[string] $ArtifactName="APIViewArtifacts",
75+
[Parameter(Mandatory=$True)]
76+
[string] $ApiKey,
77+
[Parameter(Mandatory=$True)]
78+
[string] $SourceBranch,
79+
[Parameter(Mandatory=$True)]
80+
[string] $DefaultBranch,
81+
[Parameter(Mandatory=$True)]
82+
[string] $ConfigFileDir,
83+
[string] $RepoName,
84+
[string] $BuildId,
85+
[bool] $MarkPackageAsShipped = $false
86+
)
87+
$artifactList = Create-APIViewArtifact -ServiceDirectory $ServiceDirectory -ArtifactOutputDirectory $ArtifactOutputDirectory -ArtifactName $ArtifactName
88+
$createReviewScript = (Join-Path $PSScriptRoot .. common scripts Create-APIReview.ps1)
89+
90+
Write-Host "Create Go APIView using generated artifacts"
91+
Write-Host "ArtifactList: $artifactList"
92+
Write-Host "ApiKey: $ApiKey"
93+
Write-Host "SourceBranch: $SourceBranch"
94+
Write-Host "DefaultBranch: $DefaultBranch"
95+
Write-Host "ConfigFileDir: $ConfigFileDir"
96+
Write-Host "RepoName: $RepoName"
97+
Write-Host "BuildId: $BuildId"
98+
Write-Host "MarkPackageAsShipped: $MarkPackageAsShipped"
99+
Write-Host "createReviewScript: $createReviewScript"
100+
101+
102+
#&($createReviewScript) -ArtifactList $artifactList -ArtifactPath $outPath -APIKey $ApiKey -SourceBranch $SourceBranch -DefaultBranch $DefaultBranch -ConfigFileDir $ConfigFileDir -RepoName $RepoName -BuildId $BuildId -MarkPackageAsShipped $MarkPackageAsShipped
103+
}
104+
105+
<#
106+
.DESCRIPTION
107+
Call APIView endpoint to detect changes in API surface and create APIView if required
108+
.PARAMETER ArtifactPath
109+
Path to the generated artifact
110+
.PARAMETER CommitSha
111+
Commist sha for the build
112+
.PARAMETER ArtifactName
113+
Name of the group of artifacts to be created
114+
.PARAMETER ApiKey
115+
The APIview ApiKey
116+
.PARAMETER SourceBranch
117+
SourceBranch
118+
.PARAMETER DefaultBranch
119+
DefaultBranch
120+
.PARAMETER ConfigFileDir
121+
Path to the ConfigFileDir as published in the pipeline
122+
.PARAMETER RepoName
123+
The name of the repository
124+
.PARAMETER BuildId
125+
The build Id of the pipeline run
126+
.PARAMETER MarkPackageAsShipped
127+
Indicate weather to mark the package a s shipped
128+
#>
129+
function New-APIView-From-PR {
130+
Param(
131+
[Parameter(Mandatory=$True)]
132+
[string] $ArtifactPath,
133+
[Parameter(Mandatory=$True)]
134+
[string] $CommitSha,
135+
[Parameter(Mandatory=$True)]
136+
[string] $BuildId,
137+
[Parameter(Mandatory=$True)]
138+
[string] $PullRequestNumber,
139+
[Parameter(Mandatory=$True)]
140+
[string] $RepoFullName,
141+
[Parameter(Mandatory=$True)]
142+
[string] $APIViewUri,
143+
[Parameter(Mandatory=$True)]
144+
[string] $ArtifactName,
145+
[Parameter(Mandatory=$True)]
146+
[string] $DevopsProject
147+
)
148+
149+
$detectApiChanges = (Join-Path $PSScriptRoot .. common scripts Detect-Api-Changes.ps1)
150+
151+
Write-Host "Detect API changes and create Go APIView using generated artifacts"
152+
&($detectApiChanges) -ArtifactPath $ArtifactPath -CommitSha $CommitSha -BuildId $BuildId `
153+
-PullRequestNumber $PullRequestNumber -RepoFullName $RepoFullName -APIViewUri $APIViewUri `
154+
-ArtifactName $ArtifactName -DevopsProject $DevopsProject
155+
}
156+
157+

0 commit comments

Comments
 (0)