diff --git a/eng/common/scripts/Detect-Api-Changes.ps1 b/eng/common/scripts/Detect-Api-Changes.ps1 index 7a0fc7cf5801..cdfc3cfae581 100644 --- a/eng/common/scripts/Detect-Api-Changes.ps1 +++ b/eng/common/scripts/Detect-Api-Changes.ps1 @@ -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)" } } diff --git a/eng/common/scripts/Package-Properties.ps1 b/eng/common/scripts/Package-Properties.ps1 index 57ae77f2ae2f..a23ee76bbda6 100644 --- a/eng/common/scripts/Package-Properties.ps1 +++ b/eng/common/scripts/Package-Properties.ps1 @@ -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 diff --git a/eng/common/scripts/Save-Package-Properties.ps1 b/eng/common/scripts/Save-Package-Properties.ps1 index b93ff0d4f9d2..0257e73a1545 100644 --- a/eng/common/scripts/Save-Package-Properties.ps1 +++ b/eng/common/scripts/Save-Package-Properties.ps1 @@ -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 diff --git a/eng/pipelines/templates/steps/analyze.yml b/eng/pipelines/templates/steps/analyze.yml index 7b6c83074068..d888eaae6586 100644 --- a/eng/pipelines/templates/steps/analyze.yml +++ b/eng/pipelines/templates/steps/analyze.yml @@ -5,8 +5,7 @@ parameters: NonShipping: false LicenseCheck: true IsSdkLibrary: true - APIViewArtifactsName: "APIViewArtifacts" - + ArtifactName: packages steps: - task: Powershell@2 @@ -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)' ` @@ -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: | diff --git a/eng/scripts/Language-Settings.ps1 b/eng/scripts/Language-Settings.ps1 index d7c6d0c1b9a3..86d52164a6ed 100644 --- a/eng/scripts/Language-Settings.ps1 +++ b/eng/scripts/Language-Settings.ps1 @@ -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 } diff --git a/eng/scripts/Create-ApiReview.ps1 b/eng/scripts/analyze-step-helpers.ps1 similarity index 59% rename from eng/scripts/Create-ApiReview.ps1 rename to eng/scripts/analyze-step-helpers.ps1 index 246f07406682..a9de3ce93402 100644 --- a/eng/scripts/Create-ApiReview.ps1 +++ b/eng/scripts/analyze-step-helpers.ps1 @@ -6,39 +6,34 @@ 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 } <# @@ -46,10 +41,8 @@ function Create-APIViewArtifact { 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 @@ -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)] @@ -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 } \ No newline at end of file