Skip to content

Commit

Permalink
Update Go Analyze Step
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Jan 31, 2025
1 parent b1ead21 commit a77e679
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 75 deletions.
32 changes: 11 additions & 21 deletions eng/common/scripts/Detect-Api-Changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,51 +104,41 @@ if (!($FindArtifactForApiReviewFn -and (Test-Path "Function:$FindArtifactForApiR
$responses = @{}

$packageProperties = Get-ChildItem -Recurse -Force "$configFileDir" `
| ForEach-Object {
$relativePath = $_.FullName.Substring($configFileDir.Length).TrimStart('\', '/')
Write-Host "Processing: $relativePath"
if ($_.Extension -eq '.json' -and $relativePath -notmatch '^_.*?/') {
Write-Host "Included: $relativePath"
$_
| Where-Object {
$_.Extension -eq '.json' -and ($_.FullName.Substring($configFileDir.Length + 1) -notmatch '^_.*?\\')
}
}

Write-Host "Package Properties: $($packageProperties.Count)"
Write-Host "$packageProperties"

foreach ($packagePropFile in $packageProperties)
{
$packageMetadata = Get-Content $packagePropFile | ConvertFrom-Json
Write-Host "Package Metadata"
Write-Host $packageMetadata
$pkgArtifactName = $packageMetadata.ArtifactName ?? $packageMetadata.Name

$artifactOrModuleName = $packageMetadata.ArtifactName ?? $packageMetadata.Name
Write-Host "Processing $($artifactOrModuleName)"
Write-Host "Processing $($pkgArtifactName)"

$packages = &$FindArtifactForApiReviewFn $ArtifactPath $artifactOrModuleName
$packages = &$FindArtifactForApiReviewFn $ArtifactPath $pkgArtifactName

if ($packages)
{
$pkgPath = $packages.Values[0]
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $($artifactOrModuleName)
Write-Host "Is API change detect required for $($packages.ArtifactName):$($isRequired)"
$isRequired = Should-Process-Package -pkgPath $pkgPath -packageName $pkgArtifactName
Write-Host "Is API change detect required for $($pkgArtifactName):$($isRequired)"
if ($isRequired -eq $True)
{
$filePath = $pkgPath.Replace($ArtifactPath , "").Replace("\", "/")
$respCode = Submit-Request -filePath $filePath -packageName $($artifactOrModuleName)
$respCode = Submit-Request -filePath $filePath -packageName $pkgArtifactName
if ($respCode -ne '200')
{
$responses[$($artifactOrModuleName)] = $respCode
$responses[$pkgArtifactName] = $respCode
}
}
else
{
Write-Host "Pull request does not have any change for $($artifactOrModuleName)). Skipping API change detect."
Write-Host "Pull request does not have any change for $($pkgArtifactName)). Skipping API change detect."
}
}
else
{
Write-Host "No package is found in artifact path to find API changes for $($artifactOrModuleName)"
Write-Host "No package is found in artifact path to find API changes for $($pkgArtifactName)"
}
}

Expand Down
1 change: 0 additions & 1 deletion eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class PackageProps {
[string]$SdkType
[boolean]$IsNewSdk
[string]$ArtifactName
[string]$ModuleName
[string]$ReleaseStatus
# was this package purely included because other packages included it as an AdditionalValidationPackage?
[boolean]$IncludedForValidation
Expand Down
1 change: 0 additions & 1 deletion eng/common/scripts/Save-Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ foreach ($pkg in $allPackageProperties)
Write-Host "Package Version: $($pkg.Version)"
Write-Host "Package SDK Type: $($pkg.SdkType)"
Write-Host "Artifact Name: $($pkg.ArtifactName)"
Write-Host "Module Name: $($pkg.ModuleName)"
Write-Host "Release date: $($pkg.ReleaseStatus)"
$configFilePrefix = $pkg.Name

Expand Down
42 changes: 19 additions & 23 deletions eng/pipelines/templates/steps/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ parameters:
NonShipping: false
LicenseCheck: true
IsSdkLibrary: true
APIViewArtifactsName: "APIViewArtifacts"

ArtifactName: packages

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

- pwsh: |
. $(Build.SourcesDirectory)/eng/scripts/analyze-step-helpers.ps1
$directoryToPublish = Join-Path -Path $(Build.ArtifactStagingDirectory) ${{ parameters.ArtifactName }}
New-GoArtifacts `
-ServiceDirectory '${{ parameters.ServiceDirectory }}' `
-OutputDirectory $(Build.ArtifactStagingDirectory) `
-DirectoryToPublish $directoryToPublish
Copy-Item "$(Build.ArtifactStagingDirectory)/PackageInfo" -Destination $directoryToPublish -Recurse
displayName: 'Create Go Package Artifact'
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
parameters:
ArtifactName: "PackageInfo"
ArtifactPath: "$(Build.ArtifactStagingDirectory)/PackageInfo"
ArtifactName: ${{ parameters.ArtifactName }}
ArtifactPath: "$(Build.ArtifactStagingDirectory)/${{ parameters.ArtifactName }}"
CustomCondition: and(succeeded(), ${{ parameters.IsSdkLibrary }})

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

- pwsh: |
. $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
New-APIView-From-CI `
. $(Build.SourcesDirectory)/eng/scripts/analyze-step-helpers.ps1
New-APIViewFromCI `
-ServiceDirectory '${{parameters.ServiceDirectory}}' `
-ArtifactOutputDirectory '$(Build.ArtifactStagingDirectory)' `
-ArtifactPath '$(Build.ArtifactStagingDirectory)' `
-ApiKey '$(azuresdk-apiview-apikey)' `
-SourceBranch '$(Build.SourceBranchName)' `
-DefaultBranch '$(DefaultBranch)' `
Expand All @@ -43,23 +55,7 @@ steps:
condition: and(succeeded(), ne(variables['Skip.CreateApiReview'], 'true') , ne(variables['Build.Reason'],'PullRequest'), eq(variables['System.TeamProject'], 'internal'))
- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
- pwsh: |
. $(Build.SourcesDirectory)/eng/scripts/Create-ApiReview.ps1
$_ = Create-APIViewArtifact `
-ServiceDirectory '${{parameters.ServiceDirectory}}' `
-ArtifactOutputDirectory '$(Build.ArtifactStagingDirectory)' `
-ArtifactName '${{parameters.APIViewArtifactsName}}'
displayName: Create APIView Artifact
workingDirectory: $(Pipeline.Workspace)
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
parameters:
ArtifactName: "${{parameters.APIViewArtifactsName}}"
ArtifactPath: "$(Build.ArtifactStagingDirectory)/${{parameters.APIViewArtifactsName}}"

- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
parameters:
ArtifactName: '${{parameters.APIViewArtifactsName}}'

- ${{ if and(ne(variables['Skip.PackageValidation'], 'true'), eq(variables['System.TeamProject'], 'internal')) }}:
- pwsh: |
Expand Down
2 changes: 1 addition & 1 deletion eng/scripts/Language-Settings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function Get-GoModuleProperties($goModPath)
$pkgProp.SdkType = $sdkType

$pkgProp | Add-Member -NotePropertyName "VersionFile" -NotePropertyValue $versionFile
$pkgProp.ModuleName = $modName
$pkgProp | Add-Member -NotePropertyName "ModuleName" -NotePropertyValue $modName

return $pkgProp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,43 @@ Write-Host "$PSScriptRoot"
Create .gosource APIVIew artifact for go
.PARAMETER ServiceDirectory
Thee name of the ServiceDirectory
.PARAMETER ArtifactOutputDirectory
.PARAMETER OutputDirectory
Base output Directory path for the generated gosource artifacts
.PARAMETER ArtifactName
Name of the group of artifacts to be created
.PARAMETER DirectoryToPublish
Directory containing all artifacts to be publisehd to the pipeline
#>
function Create-APIViewArtifact {
function New-GoArtifacts {
Param(
[Parameter(Mandatory=$True)]
[string] $ServiceDirectory,
[Parameter(Mandatory=$True)]
[string] $ArtifactOutputDirectory,
[string] $OutputDirectory,
[Parameter(Mandatory=$True)]
[string] $ArtifactName
[string] $DirectoryToPublish
)

$artifactList = @()

$artifactsDirectoryPath = Join-Path -Path $ArtifactOutputDirectory $ArtifactName
New-Item -ItemType Directory -Path $artifactsDirectoryPath -force

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

$artifactList += [PSCustomObject]@{
name = $sdk.Name
}
$artifactParentDirectory = Split-Path -Path $sdk.Name -Parent
Copy-Item "$OutputDirectory/$artifactParentDirectory" -Destination $DirectoryToPublish -Recurse
}
return $artifactList
}

<#
.DESCRIPTION
Create new automatic APIView from a CI run
.PARAMETER ServiceDirectory
Thee name of the ServiceDirectory
.PARAMETER ArtifactOutputDirectory
Base output Directory path for the generated gosource artifacts
.PARAMETER ArtifactName
Name of the group of artifacts to be created
.PARAMETER ArtifactPath
Directory containing the gosources artifact
.PARAMETER ApiKey
The APIview ApiKey
.PARAMETER SourceBranch
Expand All @@ -65,13 +58,12 @@ function Create-APIViewArtifact {
.PARAMETER MarkPackageAsShipped
Indicate weather to mark the package a s shipped
#>
function New-APIView-From-CI {
function New-APIViewFromCI {
Param(
[Parameter(Mandatory=$True)]
[string] $ServiceDirectory,
[Parameter(Mandatory=$True)]
[string] $ArtifactOutputDirectory,
[string] $ArtifactName="APIViewArtifacts",
[string] $ArtifactPath,
[Parameter(Mandatory=$True)]
[string] $ApiKey,
[Parameter(Mandatory=$True)]
Expand All @@ -84,10 +76,25 @@ function New-APIView-From-CI {
[string] $BuildId,
[bool] $MarkPackageAsShipped = $false
)
$artifactList = Create-APIViewArtifact -ServiceDirectory $ServiceDirectory -ArtifactOutputDirectory $ArtifactOutputDirectory -ArtifactName $ArtifactName
$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 $outPath -APIKey $ApiKey -SourceBranch $SourceBranch -DefaultBranch $DefaultBranch -ConfigFileDir $ConfigFileDir -RepoName $RepoName -BuildId $BuildId -MarkPackageAsShipped $MarkPackageAsShipped
&($createReviewScript) `
-ArtifactList $artifactList `
-ArtifactPath $ArtifactPath `
-APIKey $ApiKey `
-SourceBranch $SourceBranch `
-DefaultBranch $DefaultBranch `
-ConfigFileDir $ConfigFileDir `
-RepoName $RepoName `
-BuildId $BuildId `
-MarkPackageAsShipped $MarkPackageAsShipped
}

0 comments on commit a77e679

Please sign in to comment.