diff --git a/.github/workflows/update-sdk-definitions.yaml b/.github/workflows/update-sdk-definitions.yaml new file mode 100644 index 0000000..376d281 --- /dev/null +++ b/.github/workflows/update-sdk-definitions.yaml @@ -0,0 +1,94 @@ +name: Update SDK definitions + +on: + schedule: + - cron: "0 8 * * *" # daily at 08:00 UTC + workflow_dispatch: + repository_dispatch: + types: [update-sdk-definitions] + +permissions: + contents: write + pull-requests: write + +jobs: + update-definitions: + name: Regenerate SDK clients from upstream OpenAPI specs + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: main + + - name: Install uv + uses: astral-sh/setup-uv@38f3f104447c67c051c4a08e39b64a148898af3a # v4.2.0 + + - name: Install dependencies + run: uv sync --group dev + + - name: Regenerate sandbox SDK client + run: | + echo "Downloading sandbox definition from blaxel-ai/sandbox" + curl -sf -o ./definition.yml \ + "https://raw.githubusercontent.com/blaxel-ai/sandbox/refs/heads/main/sandbox-api/docs/openapi.yml" + + rm -rf src/blaxel/core/sandbox/client/api src/blaxel/core/sandbox/client/models + .venv/bin/openapi-python-client generate \ + --path=definition.yml \ + --output-path=./tmp-sdk-sandbox \ + --overwrite \ + --custom-template-path=./templates \ + --config=./openapi-python-client.yml + cp -r ./tmp-sdk-sandbox/blaxel/* ./src/blaxel/core/sandbox/client + rm -rf ./tmp-sdk-sandbox definition.yml + + - name: Regenerate controlplane SDK client + run: | + echo "Downloading controlplane definition from blaxel-ai/controlplane" + curl -sf -o ./definition.yml \ + "https://api.blaxel.ai/v0/openapi/controlplane.yml" + + rm -rf src/blaxel/core/client/api src/blaxel/core/client/models + .venv/bin/openapi-python-client generate \ + --path=definition.yml \ + --output-path=./tmp-sdk-python \ + --overwrite \ + --custom-template-path=./templates \ + --config=./openapi-python-client.yml + cp -r ./tmp-sdk-python/blaxel/* ./src/blaxel/core/client + rm -rf ./tmp-sdk-python definition.yml + + - name: Format and lint + run: | + uv run ruff format + uv run ruff check --fix + + - name: Check for changes + id: diff + run: | + if [ -z "$(git status --porcelain)" ]; then + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "No definition changes detected" + else + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "Definition changes detected:" + git status --short + fi + + - name: Create pull request + if: steps.diff.outputs.changed == 'true' + uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: automated/update-sdk-definitions + commit-message: "chore: update SDK definitions from upstream OpenAPI specs" + title: "chore: update SDK definitions from upstream OpenAPI specs" + body: | + Automated PR to sync the generated SDK clients with the latest OpenAPI specs from: + - [`blaxel-ai/sandbox`](https://github.com/blaxel-ai/sandbox) (sandbox client) + - [`blaxel-ai/controlplane`](https://github.com/blaxel-ai/controlplane) (controlplane client) + + Generated by the **Update SDK definitions** workflow. + labels: automated + delete-branch: true