Skip to content

Commit 46889d5

Browse files
committed
workflow template for openapi to sdk
1 parent 56d027a commit 46889d5

File tree

4 files changed

+135
-133
lines changed

4 files changed

+135
-133
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: FinFeedAPI SEC API OpenAPI to SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- master # Adjust to your default branch (e.g., main) if different
7+
paths:
8+
- 'finfeedapi/sec-api/spec/sec-api-historical.json'
9+
pull_request:
10+
branches:
11+
- master # Adjust to your default branch (e.g., main) if different
12+
paths:
13+
- 'finfeedapi/sec-api/spec/sec-api-historical.json'
14+
15+
jobs:
16+
call-reusable-workflow:
17+
uses: ./.github/workflows/reusable-openapi-to-sdk.yaml
18+
with:
19+
product_line_slug: "finfeedapi"
20+
api_type_slug: "sec-api"
21+
commit_message_subject: "FinFeedAPI SEC API Historical"
22+
secrets:
23+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: FinFeedAPI Stock API OpenAPI to SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- master # Adjust to your default branch (e.g., main) if different
7+
paths:
8+
- 'finfeedapi/stock-api/spec/stock-api-historical.json'
9+
pull_request:
10+
branches:
11+
- master # Adjust to your default branch (e.g., main) if different
12+
paths:
13+
- 'finfeedapi/stock-api/spec/stock-api-historical.json'
14+
15+
jobs:
16+
call-reusable-workflow:
17+
uses: ./.github/workflows/reusable-openapi-to-sdk.yaml
18+
with:
19+
product_line_slug: "finfeedapi"
20+
api_type_slug: "stock-api"
21+
commit_message_subject: "FinFeedAPI Stock API Historical"
22+
secrets:
23+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

.github/workflows/generate-sec-api-python-sdk.yaml

Lines changed: 0 additions & 133 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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

Comments
 (0)