diff --git a/eng/pipelines/apiview-review-gen-python.yml b/eng/pipelines/apiview-review-gen-python.yml new file mode 100644 index 00000000000..7020593833b --- /dev/null +++ b/eng/pipelines/apiview-review-gen-python.yml @@ -0,0 +1,47 @@ +pr: none + +trigger: none + +pool: + name: azsdk-pool-mms-ubuntu-2004-general + vmImage: MMSUbuntu20.04 + +parameters: + - name: Reviews + type: string + default: '[{"ReviewID":"","RevisionID":"","FileID":"","FileName":""}]' + - name: APIViewURL + type: string + default: 'https://apiview.dev' + - name: StorageContainerUrl + type: string + default: '' + +variables: + PythonIndexUrl: 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/' + PythonVersion: '3.10.2' + ApiStubVersion: '0.3.1' + +jobs: +- job: CreatePythonReviewCodeFile + displayName: 'Create Python API review token file' + + variables: + - template: /eng/pipelines/templates/variables/globals.yml + + steps: + - template: /eng/pipelines/templates/steps/use-python-version.yml + parameters: + versionSpec: '$(PythonVersion)' + + - script: | + pip install virtualenv aiohttp chardet trio + pip install api-stub-generator==$(ApiStubVersion) --index-url $(PythonIndexUrl) + displayName: 'Install api-stub-generator' + + - template: /eng/pipelines/templates/steps/apiview-review-gen.yml + parameters: + Reviews: ${{ parameters.Reviews }} + APIViewURL: ${{ parameters.APIViewURL }} + StorageContainerUrl: ${{ parameters.StorageContainerUrl }} + ApiviewGenScript: './Create-Apiview-Token-Python.ps1' \ No newline at end of file diff --git a/eng/pipelines/templates/steps/apiview-review-gen.yml b/eng/pipelines/templates/steps/apiview-review-gen.yml new file mode 100644 index 00000000000..4403b9341c8 --- /dev/null +++ b/eng/pipelines/templates/steps/apiview-review-gen.yml @@ -0,0 +1,40 @@ +parameters: + - name: Reviews + type: string + default: '' + - name: APIViewURL + type: string + default: '' + - name: StorageContainerUrl + type: string + default: '' + - name: ApiviewGenScript + type: string + default: '' + +steps: +- task: Powershell@2 + displayName: 'Generate APIView Token files' + condition: succeededOrFailed() + inputs: + pwsh: true + filePath: $(Build.SourcesDirectory)/eng/scripts/Create-Apiview-Token-Files.ps1 + arguments: > + -ReviewDetailsJson "${{ parameters.Reviews }}" + -StagingPath "$(Build.ArtifactStagingDirectory)" + -WorkingDir "$(Pipeline.Workspace)" + -StorageBaseUrl "${{parameters.StorageContainerUrl}}" + -ApiviewGenScript "${{parameters.ApiviewGenScript}}" + -ContainerSas "$(apiview-originals-sas)" + +- task: PublishBuildArtifacts@1 + inputs: + pathtoPublish: '$(Build.ArtifactStagingDirectory)/' + artifactName: 'apiview' + +- pwsh: | + $requestUrl = ${{parameters.APIViewURL}}/reviewgen/update?path=apiview&buildId=$(Build.BuildId) + Write-Host $requestUrl + $resp = Invoke-RestMethod $requestUrl + Write-Host $resp + displayName: 'Send Request to APIView' \ No newline at end of file diff --git a/eng/scripts/Create-Apiview-Token-Files.ps1 b/eng/scripts/Create-Apiview-Token-Files.ps1 new file mode 100644 index 00000000000..f5918b67806 --- /dev/null +++ b/eng/scripts/Create-Apiview-Token-Files.ps1 @@ -0,0 +1,48 @@ +[CmdletBinding()] +param ( + [Parameter(Mandatory = $true)] + [string]$ReviewDetailsJson, + [Parameter(Mandatory = $true)] + [string]$StagingPath, + [Parameter(Mandatory = $true)] + [string]$WorkingDir, + [Parameter(Mandatory = $true)] + [string]$StorageBaseUrl, + [Parameter(Mandatory = $true)] + [string]$ContainerSas, + [Parameter(Mandatory = $true)] + [string]$ApiviewGenScript +) + + +Write-Host "Review Details Json: $($ReviewDetailsJson)" +$reviews = ConvertFrom-Json $ReviewDetailsJson +Write-Host $reviews +if ($reviews -ne $null) +{ + foreach($r in $reviews) + { + Write-Host "Review:$($r.ReviewID)" + Write-Host "Revision: $($r.RevisionID)" + + $pkgWorkingDir = Join-Path -Path $WorkingDir $r.ReviewID | Join-Path -ChildPath $r.RevisionID + $codeDir = New-Item -Path $pkgWorkingDir -ItemType Directory + $sourcePath = $StorageBaseUrl + "/" + $r.FileID + $ContainerSas + Write-Host "Copying $($sourcePath)" + azcopy cp "$sourcePath" $codeDir/$($r.FileName) --recursive=true + + #Create staging path for review and revision ID + $CodeFilePath = Join-Path -Path $StagingPath $r.ReviewID | Join-Path -ChildPath $r.RevisionID + if (-not (Test-Path -Path $CodeFilePath)) { + New-Item -Path $CodeFilePath -ItemType Directory + } + + $reviewGenScriptPath = Join-Path $PSScriptRoot $ApiviewGenScript + &($reviewGenScriptPath) -SourcePath $codeDir/$($r.FileName) -OutPath $CodeFilePath + } +} +else +{ + Write-Host "Invalid Input review details Json $($ReviewDetailsJson)" + exit 1; +} \ No newline at end of file diff --git a/eng/scripts/Create-Apiview-Token-Python.ps1 b/eng/scripts/Create-Apiview-Token-Python.ps1 new file mode 100644 index 00000000000..d46f2757b1a --- /dev/null +++ b/eng/scripts/Create-Apiview-Token-Python.ps1 @@ -0,0 +1,10 @@ +[CmdletBinding()] +param ( + [Parameter(Mandatory = $true)] + [string]$SourcePath, + [Parameter(Mandatory = $true)] + [string]$OutPath +) + +Write-Host "Generating API review token file: $($SourcePath)" +python -m apistub --pkg-path $SourcePath --out-path $OutPath \ No newline at end of file