Skip to content

Commit

Permalink
Split into multi-job workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed Nov 8, 2024
1 parent 7273e1f commit 1ee0df5
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 26 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/create-swagger-apiview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Create APIView

on:
workflow_run:
workflows: ["Generate APIView Artifact"]
types:
- completed

jobs:
create-apiview:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.outputs.PullRequestRef }}
fetch-depth: 0

- name: Download Workflow Artifacts
uses: actions/download-artifact@v3
with:
name: workflow-params

- name: Read JSON File
id: read-json
run: |
PARAMS=$(cat output-parameters.json)
echo $PARAMS
echo "APIViewArtifactsDirectoryName=$(echo $PARAMS | jq -r '.APIViewArtifactsDirectoryName')" >> $GITHUB_ENV
echo "APIViewArtifactsName=$(echo $PARAMS | jq -r '.APIViewArtifactsName')" >> $GITHUB_ENV
echo "APIViewAPIUri=$(echo $PARAMS | jq -r '.APIViewAPIUri')" >> $GITHUB_ENV
echo "PullRequestRef=$(echo $PARAMS | jq -r '.PullRequestRef')" >> $GITHUB_ENV
echo "PullRequestNumber=$(echo $PARAMS | jq -r '.PullRequestNumber')" >> $GITHUB_ENV
- name: Download Swagger APIView Artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.APIViewArtifactsName }}
path: ${{ github.workspace }}/artifacts/${{ env.APIViewArtifactsDirectoryName }}

- name: Create Swagger APIView
shell: pwsh
run: |
eng/scripts/Create-Swagger-APIView.ps1 `
-ArtiFactsStagingDirectory ${{ github.workspace }}/artifacts `
-APIViewArtifactsDirectoryName ${{ env.APIViewArtifactsDirectoryName }} `
-APIViewArtifactsName ${{ env.APIViewArtifactsName }} `
-APIViewUri ${{ env.outputs.APIViewAPIUri }} `
-BuildId ${{ github.run_id }} `
-RepoName ${{ github.repository }} `
-PullRequestNumber ${{ env.outputs.PullRequestNumber }} `
-Language 'Swagger' `
-CommitSha ${{ github.sha }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Swagger APIView
name: Generate APIView Artifact

on:
pull_request:
Expand All @@ -21,26 +21,32 @@ on:
default: 'swaggerAPIViewArtifacts'
APIViewAPIUri:
description: 'URI for APIView Creation Endpoint'
default: 'https:/apiview.dev/PullRequest/DetectAPIChanges'
default: 'https://apiviewstagingtest.com/PullRequest/DetectAPIChanges'
PullRequestRef:
description: 'Pull Request ref'
default: 'refs/pull/4/merge'
default: 'refs/pull/5/merge'
PullRequestNumber:
description: 'Pull Request Number'
default: '4'
default: '5'

env:
AzureSdkForNetDevOpsFeed: ${{ github.event.inputs.AzureSdkForNetDevOpsFeed || 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json' }}
SwaggerApiParserVersion: ${{ github.event.inputs.SwaggerApiParserVersion || '1.3.0-dev.20241029.2' }}
APIViewArtifactsDirectoryName: ${{ github.event.inputs.APIViewArtifactsDirectoryName || 'SwaggerAPIViewArtifacts' }}
APIViewArtifactsName: ${{ github.event.inputs.APIViewArtifactsName || 'swaggerAPIViewArtifacts' }}
APIViewAPIUri: ${{ github.event.inputs.APIViewAPIUri || 'https://apiview.dev/PullRequest/DetectAPIChanges' }}
PullRequestRef: ${{ github.event.pull_request.head.ref || github.event.inputs.PullRequestRef }}
PullRequestNumber: ${{ github.event.pull_request.number || github.event.inputs.PullRequestNumber }}

jobs:
build:
generate-apiview-artifact:
runs-on: ubuntu-latest

env:
AzureSdkForNetDevOpsFeed: ${{ github.event.inputs.AzureSdkForNetDevOpsFeed || 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json' }}
SwaggerApiParserVersion: ${{ github.event.inputs.SwaggerApiParserVersion || '1.3.0-dev.20241029.2' }}
APIViewArtifactsDirectoryName: ${{ github.event.inputs.APIViewArtifactsDirectoryName || 'SwaggerAPIViewArtifacts' }}
APIViewArtifactsName: ${{ github.event.inputs.APIViewArtifactsName || 'swaggerAPIViewArtifacts' }}
APIViewAPIUri: ${{ github.event.inputs.APIViewAPIUri || 'https:/apiview.dev/PullRequest/DetectAPIChanges' }}
PullRequestRef: ${{ github.event.pull_request.head.ref || github.event.inputs.PullRequestRef }}
PullRequestNumber: ${{ github.event.pull_request.number || github.event.inputs.PullRequestNumber }}
outputs:
APIViewArtifactsDirectoryName: ${{ steps.set-outputs.outputs.APIViewArtifactsDirectoryName }}
APIViewArtifactsName: ${{ steps.set-outputs.outputs.APIViewArtifactsName }}
APIViewAPIUri: ${{ steps.set-outputs.outputs.APIViewAPIUri }}
PullRequestRef: ${{ steps.set-outputs.outputs.PullRequestRef }}
PullRequestNumber: ${{ steps.set-outputs.outputs.PullRequestNumber }}

steps:
- name: Checkout Repository
Expand Down Expand Up @@ -77,16 +83,20 @@ jobs:
name: ${{ env.APIViewArtifactsName }}
path: ${{ github.workspace }}/artifacts/${{ env.APIViewArtifactsDirectoryName }}

- name: Create Swagger APIView
shell: pwsh
- name: Output Env Variables to JSON
run: |
eng/scripts/Create-Swagger-APIView.ps1 `
-ArtiFactsStagingDirectory ${{ github.workspace }}/artifacts `
-APIViewArtifactsDirectoryName ${{ env.APIViewArtifactsDirectoryName }} `
-APIViewArtifactsName ${{ env.APIViewArtifactsName }} `
-APIViewUri ${{ env.APIViewAPIUri }} `
-BuildId ${{ github.run_id }} `
-RepoName ${{ github.repository }} `
-PullRequestNumber ${{ env.PullRequestNumber }} `
-Language 'Swagger' `
-CommitSha ${{ github.sha }}
echo '{
"APIViewArtifactsDirectoryName": "${{ env.APIViewArtifactsDirectoryName }}",
"APIViewArtifactsName": "${{ env.APIViewArtifactsName }}",
"APIViewAPIUri": "${{ env.APIViewAPIUri }}",
"PullRequestRef": "${{ env.PullRequestRef }}",
"PullRequestNumber": "${{ env.PullRequestNumber }}",
}' > output-parameters.json
- name: Upload JSON as Artifact
uses: actions/upload-artifact@v3
with:
name: workflow-params
path: output-parameters.json

0 comments on commit 1ee0df5

Please sign in to comment.