Skip to content

Python Client Generation #190

Python Client Generation

Python Client Generation #190

name: Python Client Generation
on:
workflow_dispatch:
inputs:
openapi_short_sha:
description: "The short commit sha that triggered the workflow"
required: true
type: string
env:
NEW_BRANCH: openapi-${{ github.event.inputs.openapi_short_sha }}/clientgen
jobs:
Generate-Python-Client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: OpenAPI Changelist
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
current_sha=$(cat DO_OPENAPI_COMMIT_SHA.txt)
echo "current_sha=$current_sha" >> $GITHUB_ENV
target_sha=${{ github.event.inputs.openapi_short_sha }}
scripts/openapi_changelist.sh $current_sha $target_sha > changelist.md
- name: Removes all generated code
run: make clean
- name: Download spec file and Update DO_OPENAPI_COMMIT_SHA.txt
run: |
curl --fail https://api-engineering.nyc3.digitaloceanspaces.com/spec-ci/DigitalOcean-public-${{ github.event.inputs.openapi_short_sha }}.v2.yaml -o DigitalOcean-public.v2.yaml
echo ${{ github.event.inputs.openapi_short_sha }} > DO_OPENAPI_COMMIT_SHA.txt
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- uses: actions/upload-artifact@v4
with:
name: DigitalOcean-public.v2
path: ./DigitalOcean-public.v2.yaml
- name: Checkout new Branch
run: git checkout -b ${{ env.NEW_BRANCH }}
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.6.1
virtualenvs-path: .venv
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: false
- name: Generate Python client
run: make generate
- name: Generate Python client documentation
run: make generate-docs
- name: Add and commit changes
id: add-commit-changes
continue-on-error: true
run: |
git config --global user.email "[email protected]"
git config --global user.name "API Engineering"
git add .
git commit -m "[bot] Updated client based on ${{ env.NEW_BRANCH }}"
git push --set-upstream origin ${{ env.NEW_BRANCH }}
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Check if branch existed
# If steps.create-pr was anything but successful, it's possible that
# the branch was created in previous pipeline runs so it should be manually deleted.
if: steps.add-commit-changes.outcome != 'success'
run: |
echo "Add and commit changes step failed. It's possible the branch ${{ env.NEW_BRANCH }} already existed. Please delete the branch and re-run the pipeline."
exit 1
- name: Set pr_title outputs
id: pr_title_var
run: echo "PR_TITLE=$(gh pr list --search "${{ github.event.inputs.openapi_short_sha }}" --json title --jq '.[0].title' --repo digitalocean/openapi --state merged)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check pr_title outputs
run: echo "${{ steps.pr_title_var.outputs.PR_TITLE }}"
- name: Create Pull Request
id: create-pr
if: steps.add-commit-changes.outcome == 'success'
run: |
export CURRENT="$(cat DO_OPENAPI_COMMIT_SHA.txt)"
export TARGET="${{ github.event.inputs.openapi_short_sha }}"
export TITLE="${{ steps.pr_title_var.outputs.PR_TITLE }}"
envsubst < scripts/pr_body.md_tmpl > pr_body.md
cat changelist.md >> pr_body.md
echo "PR BODY:"
cat pr_body.md
gh pr create \
--title "[bot] $TITLE: Re-Generated From digitalocean/openapi@$TARGET" \
--body-file pr_body.md \
--head "${{ env.NEW_BRANCH }}" \
-r digitalocean/api-cli
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}