diff --git a/.github/workflows/auto-generate.yml b/.github/workflows/auto-generate.yml new file mode 100644 index 0000000..9ef5f0e --- /dev/null +++ b/.github/workflows/auto-generate.yml @@ -0,0 +1,68 @@ +# Copyright 2026 UCP Authors +# +# 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 Models + +on: + repository_dispatch: + types: [spec-release] + workflow_dispatch: + inputs: + version: + description: 'Version to release (e.g. v1.2.3)' + required: true + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - name: Checkout SDK + uses: actions/checkout@v4 + + - name: Checkout Specification + uses: actions/checkout@v4 + with: + repository: Universal-Commerce-Protocol/ucp + ref: ${{ github.event.client_payload.version || github.event.inputs.version }} + path: ucp-repo + token: ${{ secrets.CROSS_REPO_READ_PAT }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Generate Models + run: | + export SCHEMA_DIR="ucp-repo/source/schemas" + ./generate_models.sh + + - name: Update version in pyproject.toml + run: | + TAG_VERSION="${{ github.event.client_payload.version || github.event.inputs.version }}" + PY_VERSION=${TAG_VERSION#v} + sed -i "s/^version = ".*"/version = "$PY_VERSION"/" pyproject.toml + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.CROSS_REPO_READ_PAT }} + commit-message: "chore: update models to ${{ github.event.client_payload.version || github.event.inputs.version }}" + title: "Update models to ${{ github.event.client_payload.version || github.event.inputs.version }}" + body: "This PR updates the SDK models based on the latest specification release ${{ github.event.client_payload.version || github.event.inputs.version }}." + branch: "auto-update-models-${{ github.event.client_payload.version || github.event.inputs.version }}" + base: main \ No newline at end of file diff --git a/generate_models.sh b/generate_models.sh index 26afb35..60aa330 100755 --- a/generate_models.sh +++ b/generate_models.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Copyright 2026 UCP Authors # Generate Pydantic models from UCP JSON Schemas # Ensure we are in the script's directory @@ -8,7 +9,7 @@ cd "$(dirname "$0")" || exit OUTPUT_DIR="src/ucp_sdk/models" # Schema directory (relative to this script) -SCHEMA_DIR="../../spec/" +SCHEMA_DIR="${SCHEMA_DIR:-../../spec/}" echo "Generating Pydantic models from $SCHEMA_DIR..."