Skip to content

Commit 14e4019

Browse files
authored
ci: Create GitHub Action to generate types.py from specification JSON (#67)
1 parent f20bfe7 commit 14e4019

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed

.github/actions/spelling/allow.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dunders
2626
genai
2727
gle
2828
inmemory
29+
kwarg
2930
langgraph
3031
lifecycles
3132
linting

.github/release-please.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
releaseType: python
22
handleGHRelease: true
33
bumpMinorPreMajor: false
4+
bumpPatchForMinorPreMajor: true
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Update A2A Schema from Specification
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
check_and_update:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.13"
20+
21+
- name: Install uv
22+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
23+
24+
- name: Configure uv shell
25+
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
26+
27+
- name: Install dependencies (datamodel-code-generator)
28+
run: uv sync
29+
30+
- name: Define output file variable
31+
id: vars
32+
run: |
33+
GENERATED_FILE="./src/a2a/types.py"
34+
echo "GENERATED_FILE=$GENERATED_FILE" >> "$GITHUB_OUTPUT"
35+
36+
- name: Run datamodel-codegen
37+
run: |
38+
set -euo pipefail # Exit immediately if a command exits with a non-zero status
39+
40+
REMOTE_URL="https://raw.githubusercontent.com/google/A2A/refs/heads/main/specification/json/a2a.json"
41+
GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}"
42+
43+
echo "Running datamodel-codegen..."
44+
uv run datamodel-codegen \
45+
--url "$REMOTE_URL" \
46+
--input-file-type jsonschema \
47+
--output "$GENERATED_FILE" \
48+
--target-python-version 3.10 \
49+
--output-model-type pydantic_v2.BaseModel \
50+
--disable-timestamp \
51+
--use-schema-description \
52+
--use-union-operator \
53+
--use-field-description \
54+
--use-default \
55+
--use-default-kwarg \
56+
--use-one-literal-as-default \
57+
--class-name A2A \
58+
--use-standard-collections
59+
echo "Codegen finished."
60+
61+
- name: Commit and push if generated file changed
62+
if: github.ref == 'refs/heads/main' # Or your default branch name
63+
run: |
64+
set -euo pipefail
65+
66+
GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}"
67+
68+
# Check if the generated file has any changes compared to HEAD
69+
if git diff --quiet "$GENERATED_FILE"; then
70+
echo "$GENERATED_FILE has no changes after codegen. Nothing to commit."
71+
else
72+
echo "Changes detected in $GENERATED_FILE. Committing..."
73+
# Configure git user for the commit
74+
git config user.name "github-actions"
75+
git config user.email "[email protected]"
76+
77+
# Add the generated file
78+
git add "$GENERATED_FILE"
79+
80+
# Commit changes
81+
git commit -m "🤖 chore: Auto-update A2A schema from specification"
82+
83+
# Push changes
84+
git push
85+
echo "Changes committed and pushed."
86+
fi

development.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
## Type generation from spec
44

5-
<!-- TODO replace spec.json with the public url so we always get the latest version-->
6-
75
```bash
8-
uv run datamodel-codegen --input ./spec.json --input-file-type jsonschema --output ./src/a2a/types.py --target-python-version 3.10 --output-model-type pydantic_v2.BaseModel --disable-timestamp --use-schema-description --use-union-operator --use-field-description --use-default --use-default-kwarg --use-one-literal-as-default --class-name A2A --use-standard-collections
6+
uv run datamodel-codegen \
7+
--url https://raw.githubusercontent.com/google/A2A/refs/heads/main/specification/json/a2a.json \
8+
--input-file-type jsonschema \
9+
--output ./src/a2a/types.py \
10+
--target-python-version 3.10 \
11+
--output-model-type pydantic_v2.BaseModel \
12+
--disable-timestamp \
13+
--use-schema-description \
14+
--use-union-operator \
15+
--use-field-description \
16+
--use-default \
17+
--use-default-kwarg \
18+
--use-one-literal-as-default \
19+
--class-name A2A \
20+
--use-standard-collections
921
```

0 commit comments

Comments
 (0)