44# Treat unset variables as an error.
55set -euo pipefail
66
7- TMP_WORK_DIR=" /tmp/experimental_types" # Folder for temporary files.
87A2A_SPEC_REPO=" https://github.com/a2aproject/A2A.git" # URL for the A2A spec repo.
98A2A_SPEC_BRANCH=" main" # Name of the branch with experimental changes.
109FEATURE_BRANCH=" experimental-types" # Name of the feature branch to create.
11- ROOT_DIR=` pwd ` " /.. "
10+ ROOT_DIR=$( git rev-parse --show-toplevel )
1211
1312usage () {
1413 cat << EOF
@@ -29,9 +28,6 @@ OPTIONS:
2928 -f, --feature-branch Name of the new feature branch to create.
3029 (Default: "$FEATURE_BRANCH ")
3130
32- -t, --tmp-dir Directory for temporary checkout files.
33- (Default: "$TMP_WORK_DIR ")
34-
3531 -h, --help Display this help message and exit.
3632
3733EXAMPLE:
@@ -74,22 +70,22 @@ while [[ $# -gt 0 ]]; do
7470 esac
7571done
7672
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
73+ TMP_WORK_DIR= $( mktemp -d )
74+ echo " Created a temporary working directory: $TMP_WORK_DIR "
75+ trap ' rm -rf -- " $TMP_WORK_DIR" ' EXIT
8076cd $TMP_WORK_DIR
8177
8278echo " Cloning the \" $A2A_SPEC_REPO \" repository..."
83- git clone $A2A_SPEC_REPO
84- cd A2A
79+ git clone $A2A_SPEC_REPO spec_repo
80+ cd spec_repo
8581
86- echo " Checking out the \" $A2A_SPEC_BRANCH \" branch..."
82+ echo " Checking out the \" $A2A_SPEC_BRANCH \" branch..."
8783git checkout $A2A_SPEC_BRANCH
8884
8985echo " Running datamodel-codegen..."
9086GENERATED_FILE=" $ROOT_DIR /src/a2a/types.py"
9187uv run datamodel-codegen \
92- --input " $TMP_WORK_DIR /A2A /specification/json/a2a.json" \
88+ --input " $TMP_WORK_DIR /spec_repo /specification/json/a2a.json" \
9389 --input-file-type jsonschema \
9490 --output " $GENERATED_FILE " \
9591 --target-python-version 3.10 \
@@ -117,6 +113,3 @@ cd $ROOT_DIR
117113git checkout -b " $FEATURE_BRANCH "
118114git add " $GENERATED_FILE "
119115git commit -m " Experimental types"
120-
121- echo " Cleaning up..."
122- yes | rm -R $TMP_WORK_DIR
0 commit comments