forked from Universal-Commerce-Protocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (86 loc) · 3.33 KB
/
auto-generate.yml
File metadata and controls
96 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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