Skip to content

Commit

Permalink
draft python and typescript client codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Mar 12, 2024
1 parent 7bbc94e commit 423484d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/client-codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Client Codegen

on:
push:
branches:
- main
- 'releases/**'
pull_request:
branches:
- main
- 'releases/**'

jobs:
py-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Install OpenAPI Generator CLI
# todo error - this needs java
run: npm install @openapitools/openapi-generator-cli -g

- name: Generate Client Code
run: openapi-generator-cli generate -i docs/user/reference/openapi.yml -g python -o /python-client

- name: Build sdist and wheel
run: cd /python-client && pipx run build

- name: Upload sdist and wheel as artifacts
uses: actions/upload-artifact@v3
with:
name: py-build
path: py-build

pypi-publish:
# upload to PyPI and make a release on every tag
needs: [py-build]

runs-on: ubuntu-latest
permissions:
# this permission is mandatory for trusted publishing To PyPI
id-token: write
# This permission allows the CI to create the release environment
contents: write
# Specify the GitHub Environment to publish to
environment: release

steps:
# download sdist and wheel from dist job
- uses: actions/[email protected]

# publish to PyPI using trusted publishing
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1.8.4

js-dist:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '21' # Choose the Node.js version that suits your project

- name: Install OpenAPI Generator CLI
run: npm install @openapitools/openapi-generator-cli -g

- name: Generate TypeScript Fetch Client
run: openapi-generator-cli generate -i docs/user/reference/openapi.yml -g typescript-fetch -o /ts-fetch-client

# Optional: Install dependencies and build the TypeScript project
# This step assumes you have a package.json file and a build script
- name: Install Dependencies and Build
run: |
cd /ts-fetch-client
npm install
npm run build
# Optional: Commit and push the generated code to a specific branch
- name: Commit Generated Code
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add /ts-fetch-client
git commit -m "Generate TypeScript fetch client"
git push origin HEAD:branch-name-to-push-to
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-node@v4
with:
node-version: '21.x'
registry-url: 'https://registry.npmjs.org'

- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 7 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.4.0"
}
}

0 comments on commit 423484d

Please sign in to comment.