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 9eb678d
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 92 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/create-swagger-apiview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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@v4
with:
name: workflow-params
path: ${{ github.workspace }}/artifacts/workflow-params
github-token: ${{ github.token }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}

- name: Read JSON File
id: read-json
run: |
PARAMS=$(cat ${{ github.workspace }}/artifacts/workflow-params/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@v4
with:
name: ${{ env.APIViewArtifactsName }}
path: ${{ github.workspace }}/artifacts/${{ env.APIViewArtifactsDirectoryName }}
github-token: ${{ github.token }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}

- 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 }}
102 changes: 102 additions & 0 deletions .github/workflows/generate-swagger-apiview-tokens.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Generate APIView Artifact

on:
pull_request:
branches:
- main

workflow_dispatch:
inputs:
AzureSdkForNetDevOpsFeed:
description: 'Azure SDK for .NET DevOps Feed'
default: 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json'
SwaggerApiParserVersion:
description: 'Swagger API Parser Version'
default: '1.3.0-dev.20241029.2'
APIViewArtifactsDirectoryName:
description: 'APIView Artifacts Directory Name'
default: 'SwaggerAPIViewArtifacts'
APIViewArtifactsName:
description: 'APIView Artifacts Name'
default: 'swaggerAPIViewArtifacts'
APIViewAPIUri:
description: 'URI for APIView Creation Endpoint'
default: 'https://apiviewstagingtest.com/PullRequest/DetectAPIChanges'
PullRequestRef:
description: 'Pull Request ref'
default: 'refs/pull/5/merge'
PullRequestNumber:
description: 'Pull Request Number'
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:
generate-apiview-artifact:
runs-on: ubuntu-latest
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
uses: actions/checkout@v4
with:
ref: ${{ env.PullRequestRef }}
fetch-depth: 0

- name: Install .NET SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: '8.x'

- name: Install APIView Swagger Parser
run: |
dotnet tool install Azure.Sdk.Tools.SwaggerApiParser \
--version ${{ env.SwaggerApiParserVersion }} \
--add-source ${{ env.AzureSdkForNetDevOpsFeed }} \
--global
- name: Generate Swagger APIView Tokens
shell: pwsh
run: |
eng/scripts/Create-Swagger-APIView-Artifacts.ps1 `
-TempDirectory ${{ github.workspace }}/temp `
-ArtiFactsStagingDirectory ${{ github.workspace }}/artifacts `
-APIViewArtifactsDirectoryName ${{ env.APIViewArtifactsDirectoryName }}
env:
DOTNET_ROOT: /home/runner/.dotnet

- name: Publish Swagger APIView Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.APIViewArtifactsName }}
path: ${{ github.workspace }}/artifacts/${{ env.APIViewArtifactsDirectoryName }}

- name: Output Env Variables to JSON
run: |
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@v4
with:
name: workflow-params
path: output-parameters.json

92 changes: 0 additions & 92 deletions .github/workflows/swagger-apiview.yml

This file was deleted.

0 comments on commit 9eb678d

Please sign in to comment.