Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/auto-generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Auto-Generate SDK
on:
repository_dispatch:
types: [spec-release]

jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout SDK Repo
uses: actions/checkout@v4
with:
path: python-sdk

- name: Checkout UCP Spec Repo
uses: actions/checkout@v4
with:
repository: nearlyforget/ucp_nan
ref: ${{ github.event.client_payload.version }}
path: ucp-spec

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Generate Code
env:
UCP_SPEC_PATH: ${{ github.workspace }}/ucp-spec/spec
SDK_PATH: ${{ github.workspace }}/python-sdk
run: |
echo "Generating Pydantic models from $UCP_SPEC_PATH"
OUTPUT_DIR="$SDK_PATH/src/ucp_sdk/models"
rm -r -f "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

cd "$SDK_PATH"
uv run \
--link-mode=copy \
--extra-index-url https://pypi.org/simple python \
-m datamodel_code_generator \
--input "$UCP_SPEC_PATH" \
--input-file-type jsonschema \
--output "$OUTPUT_DIR" \
--output-model-type pydantic_v2.BaseModel \
--use-schema-description \
--field-constraints \
--use-field-description \
--enum-field-as-literal all \
--disable-timestamp \
--use-double-quotes \
--no-use-annotated \
--allow-extra-fields \
--formatters ruff-format ruff-check

- name: Update `pyproject.toml` version
id: version_bump
run: |
# Get version from payload, e.g. "v1.2.0"
TAG_VERSION="${{ github.event.client_payload.version }}"
# Remove leading 'v' for PEP440 compliance, e.g. "1.2.0"
PY_VERSION=${TAG_VERSION#v}
# Use sed to find 'version = "..."' and replace it
sed -i "s/^version = \".*\"/version = \"$PY_VERSION\"/" python-sdk/pyproject.toml
echo "Updated pyproject.toml to version $PY_VERSION"

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
path: python-sdk
token: ${{ secrets.PAT_TOKEN }}
title: "feat: Update SDK to match UCP ${{ github.event.client_payload.version }}"
body: "This PR was auto-generated by the release of UCP ${{ github.event.client_payload.version }}.

Includes updated models and version bump to `${{ github.event.client_payload.version }}`."
branch: "auto-update-sdk-${{ github.event.client_payload.version }}"
base: main
31 changes: 31 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/action@v3.0.1
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
.ruff_cache/
__pycache__/
.venv/
*.py[cod]
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

exclude: '^(\.github/|\.vscode/|node_modules/).*|CODE_OF_CONDUCT\.md|CHANGELOG\.md'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--unsafe]
- id: check-json
- id: check-added-large-files
- id: check-shebang-scripts-are-executable
- id: check-executables-have-shebangs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.13
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --ignore, "D,E501"]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
files: \.(md|yaml|yml|json)$
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
Loading