Skip to content

Commit b0d6575

Browse files
author
lkawka
committed
feat: script for checking-out experimental types
1 parent 051ab20 commit b0d6575

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
3+
# Exit immediately if a command exits with a non-zero status.
4+
# Treat unset variables as an error.
5+
set -euo pipefail
6+
7+
TMP_WORK_DIR="/tmp/experimental_types" # Folder for temporary files.
8+
A2A_SPEC_REPO="https://github.com/a2aproject/A2A.git" # URL for the A2A spec repo.
9+
A2A_SPEC_BRANCH="main" # Name of the branch with experimental changes.
10+
FEATURE_BRANCH="experimental-types" # Name of the feature branch to create.
11+
ROOT_DIR=`pwd`"/.."
12+
13+
usage() {
14+
cat <<EOF
15+
Usage: $0 [OPTIONS]
16+
17+
Creates a new feature branch with types generated from unmerged A2A spec changes.
18+
19+
This script clones the A2A spec repository, checks out a specific branch,
20+
and creates a new local feature branch from it.
21+
22+
OPTIONS:
23+
-r, --spec-repo URL for the A2A spec repository.
24+
(Default: "$A2A_SPEC_REPO")
25+
26+
-b, --spec-branch Name of the branch with the experimental changes.
27+
(Default: "$A2A_SPEC_BRANCH")
28+
29+
-f, --feature-branch Name of the new feature branch to create.
30+
(Default: "$FEATURE_BRANCH")
31+
32+
-t, --tmp-dir Directory for temporary checkout files.
33+
(Default: "$TMP_WORK_DIR")
34+
35+
-h, --help Display this help message and exit.
36+
37+
EXAMPLE:
38+
# Run with all default settings:
39+
$0
40+
41+
# Run with custom settings:
42+
$0 -r "https://github.com/edenreich/A2A.git" -b "feature/implement-list-tasks" -f "task-list"
43+
EOF
44+
}
45+
46+
# Handle command-line arguments.
47+
while [[ $# -gt 0 ]]; do
48+
case $1 in
49+
-h|--help)
50+
usage
51+
exit 0
52+
;;
53+
-r|--spec-repo)
54+
A2A_SPEC_REPO="$2"
55+
shift 2
56+
;;
57+
-b|--spec-branch)
58+
A2A_SPEC_BRANCH="$2"
59+
shift 2
60+
;;
61+
-f|--feature-branch)
62+
FEATURE_BRANCH="$2"
63+
shift 2
64+
;;
65+
-t|--tmp-dir)
66+
TMP_WORK_DIR="$2"
67+
shift 2
68+
;;
69+
*)
70+
echo "Error: Unknown option '$1'" >&2
71+
usage
72+
exit 1
73+
;;
74+
esac
75+
done
76+
77+
echo "Creating a temporary \"$TMP_WORK_DIR\" folder for A2A spec repo..."
78+
rm -fR $TMP_WORK_DIR # Remove preexisting files if any exist.
79+
mkdir -p $TMP_WORK_DIR
80+
cd $TMP_WORK_DIR
81+
82+
echo "Cloning the \"$A2A_SPEC_REPO\" repository..."
83+
git clone $A2A_SPEC_REPO
84+
cd A2A
85+
86+
echo " Checking out the \"$A2A_SPEC_BRANCH\" branch..."
87+
git checkout $A2A_SPEC_BRANCH
88+
89+
echo "Running datamodel-codegen..."
90+
GENERATED_FILE="$ROOT_DIR/src/a2a/types.py"
91+
uv run datamodel-codegen \
92+
--input "$TMP_WORK_DIR/A2A/specification/json/a2a.json" \
93+
--input-file-type jsonschema \
94+
--output "$GENERATED_FILE" \
95+
--target-python-version 3.10 \
96+
--output-model-type pydantic_v2.BaseModel \
97+
--disable-timestamp \
98+
--use-schema-description \
99+
--use-union-operator \
100+
--use-field-description \
101+
--use-default \
102+
--use-default-kwarg \
103+
--use-one-literal-as-default \
104+
--class-name A2A \
105+
--use-standard-collections \
106+
--use-subclass-enum \
107+
--base-class a2a._base.A2ABaseModel \
108+
--field-constraints \
109+
--snake-case-field \
110+
--no-alias
111+
112+
echo "Formatting generated types file with ruff..."
113+
uv run ruff format "$GENERATED_FILE"
114+
115+
echo "Committing generated types file to the \"$FEATURE_BRANCH\" branch..."
116+
cd $ROOT_DIR
117+
git checkout -b "$FEATURE_BRANCH"
118+
git add "$GENERATED_FILE"
119+
git commit -m "Experimental types"
120+
121+
echo "Cleaning up..."
122+
yes | rm -R $TMP_WORK_DIR

0 commit comments

Comments
 (0)