Manual-Trigger-To-Extract-From-Dev-APIM-Instance #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Manual-Trigger-To-Extract-From-Dev-APIM-Instance | |
| run-name: Manual-Trigger-To-Extract-From-Dev-APIM-Instance | |
| #martin f kallukalam | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| EXTRACTOR_OPTION: | |
| description: 'Choose whether to extract all APIM artifacts OR extract only APIM artifacts listed in extractor config file' | |
| required: true | |
| type: choice | |
| options: | |
| - 'Extract Selected APIM Artifacts' | |
| - 'Extract All APIM Artifacts' | |
| API_SPECIFICATION_FORMAT: | |
| description: 'API specification format to extract the API spec' | |
| required: true | |
| type: choice | |
| options: | |
| - OpenAPIV3Yaml | |
| - OpenAPIV3Json | |
| - OpenAPIV2Yaml | |
| - OpenAPIV2Json | |
| default: OpenAPIV3Yaml | |
| REFERENCE_NUMBER: | |
| description: 'Reference(ticket) number to include in the title of PR' | |
| required: true | |
| type: string | |
| default: '100' | |
| concurrency: | |
| group: extract-from-dev-apim-instance | |
| cancel-in-progress: false | |
| env: | |
| apiops_release_version: v6.0.1.7 | |
| REFTOCHECKOUTFOR_CONFIGURATIONYAMLPATH: branch-${{ github.event.inputs.REFERENCE_NUMBER }} | |
| PULL_REQUEST_LABEL: ticket-${{ github.event.inputs.REFERENCE_NUMBER }} | |
| BASE_BRANCH: dev-artifacts | |
| HEAD_BRANCH: branch-${{ github.event.inputs.REFERENCE_NUMBER }} | |
| #ENVIRONMENT: dev | |
| #artifacts branch dev-artifacts | |
| #working branch dev-working | |
| Logging__LogLevel__Default: ${{ vars.LOG_LEVEL }} | |
| jobs: | |
| #I have to add a job which will check for existence of the HEAD_BRANCH and if doesn't exist, create the branch | |
| Extract-Artifacts: | |
| name: Extract-Artifacts | |
| runs-on: ubuntu-latest | |
| environment: dev | |
| steps: | |
| - name: Checkout-Configuration-File | |
| id: Checkout-Configuration-File | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: '${{ env.REFTOCHECKOUTFOR_CONFIGURATIONYAMLPATH }}' | |
| - name: Run-Extractor | |
| id: Run-Extractor | |
| env: | |
| AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} | |
| AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }} | |
| AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} | |
| AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} | |
| API_MANAGEMENT_SERVICE_NAME: ${{ secrets.API_MANAGEMENT_SERVICE_NAME }} | |
| API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ runner.temp }}/apimartifacts | |
| API_SPECIFICATION_FORMAT: ${{ github.event.inputs.API_SPECIFICATION_FORMAT }} | |
| #Logging__LogLevel__Default: Trace | |
| run: | | |
| $var1="${{ github.event.inputs.EXTRACTOR_OPTION }}" | |
| $var2="Extract All APIM Artifacts" | |
| $var3="Extract Selected APIM Artifacts" | |
| if ($var1 -eq $var3) | |
| { | |
| Write-Output "User have chosen to extract Selected APIM Artifacts" | |
| echo "Copying extractor configuration file to runner.temp" | |
| #copy configuration-extractor.yaml $env:RUNNER_TEMP | |
| copy configuration-extractor.yaml $env:RUNNER_TEMP/configuration-extractor.yaml | |
| $env:CONFIGURATION_YAML_PATH="$env:RUNNER_TEMP/configuration-extractor.yaml" | |
| Write-Output "Configuration yaml path is $env:CONFIGURATION_YAML_PATH" | |
| Write-Output "Api management service output folder path is $env:API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH" | |
| } | |
| else | |
| { | |
| Write-Output "User have chosen to extract All APIM Artifacts" | |
| Write-Output "Configuration yaml path is $env:CONFIGURATION_YAML_PATH" | |
| Write-Output "Api management service output folder path is $env:API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH" | |
| } | |
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = "Stop" | |
| $VerbosePreference = "Continue" | |
| $InformationPreference = "Continue" | |
| Write-Information "Setting name variables..." | |
| $releaseFileName = "extractor-linux-x64.zip" | |
| $executableFileName = "extractor" | |
| if ("${{ runner.os }}" -like "*win*") { | |
| $releaseFileName = "extractor-win-x64.zip" | |
| $executableFileName = "extractor.exe" | |
| } | |
| elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*arm*") { | |
| $releaseFileName = "extractor-osx-arm64.zip" | |
| } | |
| elseif ("${{ runner.os }}" -like "*mac*" -and "${{ runner.arch }}" -like "*x86_64*") { | |
| $releaseFileName = "extractor-osx-x64.zip" | |
| } | |
| Write-Information "Downloading release..." | |
| $uri = "https://github.com/Azure/apiops/releases/download/${{ env.apiops_release_version }}/$releaseFileName" | |
| $downloadFilePath = Join-Path "${{ runner.temp }}" $releaseFileName | |
| Invoke-WebRequest -Uri "$uri" -OutFile "$downloadFilePath" | |
| Write-Information "Extracting release..." | |
| $executableFolderPath = Join-Path "${{ runner.temp }}" "extractor" | |
| Expand-Archive -Path "$downloadFilePath" -DestinationPath "$executableFolderPath" | |
| $executableFilePath = Join-Path "$executableFolderPath" $executableFileName | |
| Write-Information "Setting file permissions..." | |
| if ("${{ runner.os }}" -like "*linux*") | |
| { | |
| & chmod +x "$executableFilePath" | |
| if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."} | |
| } | |
| echo "---------------------------------" | |
| cat $env:CONFIGURATION_YAML_PATH | |
| echo "---------------------------------" | |
| Write-Information "Running extractor..." | |
| & "$executableFilePath" | |
| if ($LASTEXITCODE -ne 0) { throw "Running extractor failed."} | |
| Write-Information "Execution complete." | |
| ls -R $env:API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH || true | |
| shell: pwsh | |
| - name: Upload-Artifact | |
| id: Upload-Artifact | |
| uses: actions/upload-artifact@v4 | |
| env: | |
| API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ runner.temp }}/apimartifacts | |
| with: | |
| name: artifact-extract-from-dev-apim-instance | |
| path: ${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }} | |
| overwrite: 'false' | |
| Create-Pull-Request: | |
| name: Create-Pull-Request | |
| needs: Extract-Artifacts | |
| runs-on: [ubuntu-latest] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout-Artifacts-Branch | |
| id: Checkout-Artifacts-Branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: '${{ env.BASE_BRANCH }}' | |
| fetch-depth: 1 | |
| fetch-tags: 'false' | |
| - name: Download-Artifacts-From-Job | |
| id: Download-Artifacts-From-Job | |
| uses: actions/download-artifact@v4 | |
| env: | |
| API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: apimartifacts | |
| with: | |
| name: artifact-extract-from-dev-apim-instance | |
| path: "${{ GITHUB.WORKSPACE }}/${{ env.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}" | |
| - name: Create-PR-For-Merging-To-Artifacts-Branch | |
| id: Create-PR-For-Merging-To-Artifacts-Branch | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: '${{ env.HEAD_BRANCH }}' | |
| base: '${{ env.BASE_BRANCH }}' | |
| commit-message: "Commiting Artifacts from GHA Workflow Run ID:${{ github.run_id }}" | |
| title: "PR Opened by: ${{ github.triggering_actor }} for Reference Number: ${{ github.event.inputs.REFERENCE_NUMBER }}" | |
| body: | | |
| This PR is Auto-Generated by GHA Workflow Run ID: ${{ github.run_id }} | |
| URL to GHA Workflow Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| labels: '${{ env.PULL_REQUEST_LABEL }}' |