1+ name : Reusable OpenAPI to SDK Generation
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ product_line_slug :
7+ description : ' Slug for the product line (e.g., "finfeedapi")'
8+ required : true
9+ type : string
10+ api_type_slug :
11+ description : ' Slug for the API type (e.g., "sec-api", "stock-api")'
12+ required : true
13+ type : string
14+ commit_message_subject :
15+ description : ' Subject for the commit message (e.g., "FinFeedAPI SEC API Historical")'
16+ required : true
17+ type : string
18+ secrets :
19+ PAT_TOKEN :
20+ description : ' PAT token for committing changes'
21+ required : true
22+
23+ jobs :
24+ build-and-commit-sdk :
25+ runs-on : ubuntu-latest
26+ steps :
27+ - name : Checkout repository
28+ uses : actions/checkout@v4
29+ with :
30+ token : ${{ secrets.PAT_TOKEN }}
31+
32+ - name : Set up Java
33+ uses : actions/setup-java@v4
34+ with :
35+ distribution : ' temurin'
36+ java-version : ' 17'
37+
38+ - name : Install OpenAPI Generator CLI
39+ run : |
40+ npm install -g @openapitools/openapi-generator-cli
41+ openapi-generator-cli version-manager set 7.5.0
42+
43+ - name : Generate SDKs
44+ run : |
45+ set -e
46+
47+ echo "Generating SDKs using configurations for ${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}"
48+ SDK_OUTPUT_DIR="${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}/sdk"
49+
50+ # Create the base output directory if it doesn't exist
51+ mkdir -p "${SDK_OUTPUT_DIR}"
52+
53+ echo "Cleaning previous SDKs (if any) from ${SDK_OUTPUT_DIR}..."
54+ rm -rf "${SDK_OUTPUT_DIR:?}"/*
55+
56+ echo "Running OpenAPI Generator CLI batch process..."
57+ cd "${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}/"
58+ openapi-generator-cli batch ./sdk-config/*.yaml -v
59+
60+ echo "SDKs generation complete for ${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}."
61+
62+ - name : Commit and Push SDK
63+ if : github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
64+ run : |
65+ git config --global user.name 'GitHub Actions Bot'
66+ git config --global user.email '[email protected] ' 67+
68+ # Navigate to repository root
69+ cd "${{ github.workspace }}"
70+
71+ git add "${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}/sdk/"
72+
73+ # Check if there are actual changes to commit
74+ if git diff --staged --quiet; then
75+ echo "No changes to commit in SDK for ${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}."
76+ else
77+ echo "Changes detected, committing for ${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}..."
78+ git commit -m "Auto-generate SDK for ${{ inputs.commit_message_subject }}"
79+
80+ git config pull.rebase false
81+
82+ CURRENT_BRANCH=$(echo "${{ github.ref }}" | sed 's!refs/heads/!!')
83+ echo "Pulling latest changes from origin/${CURRENT_BRANCH}..."
84+ git pull origin ${CURRENT_BRANCH}
85+
86+ echo "Pushing changes to origin/${CURRENT_BRANCH}..."
87+ git push origin ${CURRENT_BRANCH}
88+ echo "Push complete for ${{ inputs.product_line_slug }}/${{ inputs.api_type_slug }}."
89+ fi
0 commit comments