|
| 1 | +name: Client Codegen |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'releases/**' |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - 'releases/**' |
| 12 | + |
| 13 | +jobs: |
| 14 | + py-build: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v2 |
| 24 | + with: |
| 25 | + python-version: "3.9" |
| 26 | + |
| 27 | + - name: Install OpenAPI Generator CLI |
| 28 | + # todo error - this needs java |
| 29 | + run: npm install @openapitools/openapi-generator-cli -g |
| 30 | + |
| 31 | + - name: Generate Client Code |
| 32 | + run: openapi-generator-cli generate -i docs/user/reference/openapi.yml -g python -o /python-client |
| 33 | + |
| 34 | + - name: Build sdist and wheel |
| 35 | + run: cd /python-client && pipx run build |
| 36 | + |
| 37 | + - name: Upload sdist and wheel as artifacts |
| 38 | + uses: actions/upload-artifact@v3 |
| 39 | + with: |
| 40 | + name: py-build |
| 41 | + path: py-build |
| 42 | + |
| 43 | + pypi-publish: |
| 44 | + # upload to PyPI and make a release on every tag |
| 45 | + needs: [py-build] |
| 46 | + |
| 47 | + runs-on: ubuntu-latest |
| 48 | + permissions: |
| 49 | + # this permission is mandatory for trusted publishing To PyPI |
| 50 | + id-token: write |
| 51 | + # This permission allows the CI to create the release environment |
| 52 | + contents: write |
| 53 | + # Specify the GitHub Environment to publish to |
| 54 | + environment: release |
| 55 | + |
| 56 | + steps: |
| 57 | + # download sdist and wheel from dist job |
| 58 | + - uses: actions/download-artifact@v4.1.4 |
| 59 | + |
| 60 | + # publish to PyPI using trusted publishing |
| 61 | + - name: Publish to PyPI |
| 62 | + uses: pypa/gh-action-pypi-publish@release/v1.8.4 |
| 63 | + |
| 64 | + js-dist: |
| 65 | + runs-on: 'ubuntu-latest' |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Set up Node.js |
| 70 | + uses: actions/setup-node@v4 |
| 71 | + with: |
| 72 | + node-version: '21' # Choose the Node.js version that suits your project |
| 73 | + |
| 74 | + - name: Install OpenAPI Generator CLI |
| 75 | + run: npm install @openapitools/openapi-generator-cli -g |
| 76 | + |
| 77 | + - name: Generate TypeScript Fetch Client |
| 78 | + run: openapi-generator-cli generate -i docs/user/reference/openapi.yml -g typescript-fetch -o /ts-fetch-client |
| 79 | + |
| 80 | + # Optional: Install dependencies and build the TypeScript project |
| 81 | + # This step assumes you have a package.json file and a build script |
| 82 | + - name: Install Dependencies and Build |
| 83 | + run: | |
| 84 | + cd /ts-fetch-client |
| 85 | + npm install |
| 86 | + npm run build |
| 87 | +
|
| 88 | + # Optional: Commit and push the generated code to a specific branch |
| 89 | + - name: Commit Generated Code |
| 90 | + run: | |
| 91 | + git config --local user.email "action@github.com" |
| 92 | + git config --local user.name "GitHub Action" |
| 93 | + git add /ts-fetch-client |
| 94 | + git commit -m "Generate TypeScript fetch client" |
| 95 | + git push origin HEAD:branch-name-to-push-to |
| 96 | + env: |
| 97 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - uses: actions/setup-node@v4 |
| 100 | + with: |
| 101 | + node-version: '21.x' |
| 102 | + registry-url: 'https://registry.npmjs.org' |
| 103 | + |
| 104 | + - run: npm ci |
| 105 | + - run: npm publish |
| 106 | + env: |
| 107 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments