Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generate SDKs clients automatically #36

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/generate-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Generate Client

# Runs this action whenever there are any changes to the master branch.
on:
push:
branches:
- '*'

jobs:
client:
runs-on: ubuntu-latest

# Checks out the entire repo.
steps:
- name: Checks out repo
uses: actions/checkout@v1

# Generates a openapi.yaml file based on the FastAPI project.
- name: Generate OpenAPI file
uses: column-street/fastapi-openapi-specs-action@v1.0.0
with:
moduleDir: .
fileName: generate_openapi_json.py
appName: app

# Uses an external tool, openapitools-generator-action, to generate the client code.
# The 'openapirc.json' file is the following: { "packageName": "fast", "projectName": "fast" }
# and it lives inside the master branch of the repository. Comamnd outputs a new folder called
# 'python-client' with the relevant client code.
- name: Generate Python Client
uses: triaxtec/openapitools-generator-action@v1.0.0
with:
generator: python
openapi-file: openapi.yaml
config-file: openapirc.yaml

# Deletes every file in the folder, except '.git' and the new generated 'python-client' folder.
# Moves all content of the 'python-client' folder to the root directory.
- name: Cleans the branch up.
run: |
# Removes all files except the .git and python-client folder.
shopt -s extglob
sudo rm -rf !(.|..|.git|python-client)
# Moves all of the content of the python-client folder out,
# and deletes the folder.
mv python-client/* .
rm -rf python-client

# Commits the new changes into a new branch called 'client'.
- name: Commit changes.
run: |
git checkout -b client
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Generated client." -a || true

# Pushes all of these changes into the GitHub repository.
- name: Push changes to client branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: client
force: True