Skip to content

Commit 9c21e1a

Browse files
lkawkalkawka
andauthored
ci: Script for checking-out experimental types (#507)
# Description Added a script for creating a new feature branch with types generated from unmerged A2A spec changes. We need to begin development on several upcoming spec changes that are currently unmerged but are highly likely to be included in the next release, such as the task/list method. To do that, we need updated types, which this script provides. # Prerequisites - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [x] Ensure the tests and linter pass (Run `bash scripts/format.sh` from the repository root to format) - [x] Appropriate docs were updated (if necessary) --------- Co-authored-by: lkawka <lkawka@google.com>
1 parent 17e7597 commit 9c21e1a

File tree

2 files changed

+129
-8
lines changed

2 files changed

+129
-8
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
A2A_SPEC_REPO="https://github.com/a2aproject/A2A.git" # URL for the A2A spec repo.
8+
A2A_SPEC_BRANCH="main" # Name of the branch with experimental changes.
9+
FEATURE_BRANCH="experimental-types" # Name of the feature branch to create.
10+
ROOT_DIR=$(git rev-parse --show-toplevel)
11+
12+
usage() {
13+
cat <<EOF
14+
Usage: $0 [OPTIONS]
15+
16+
Creates a new feature branch with types generated from unmerged A2A spec changes.
17+
18+
This script clones the A2A spec repository, checks out a specific branch,
19+
and creates a new local feature branch from it.
20+
21+
The script requires uv and buf to be installed.
22+
23+
OPTIONS:
24+
-r, --spec-repo URL for the A2A spec repository.
25+
(Default: "$A2A_SPEC_REPO")
26+
27+
-b, --spec-branch Name of the branch with the experimental changes.
28+
(Default: "$A2A_SPEC_BRANCH")
29+
30+
-f, --feature-branch Name of the new feature branch to create.
31+
(Default: "$FEATURE_BRANCH")
32+
33+
-h, --help Display this help message and exit.
34+
35+
EXAMPLE:
36+
# Run with all default settings:
37+
$0
38+
39+
# Run with custom settings:
40+
$0 -r "https://github.com/spec-fork/A2A.git" -b "spec-change" -f "my-branch"
41+
EOF
42+
}
43+
44+
# Handle command-line arguments.
45+
while [[ $# -gt 0 ]]; do
46+
case $1 in
47+
-h|--help)
48+
usage
49+
exit 0
50+
;;
51+
-r|--spec-repo)
52+
A2A_SPEC_REPO="$2"
53+
shift 2
54+
;;
55+
-b|--spec-branch)
56+
A2A_SPEC_BRANCH="$2"
57+
shift 2
58+
;;
59+
-f|--feature-branch)
60+
FEATURE_BRANCH="$2"
61+
shift 2
62+
;;
63+
*)
64+
echo "Error: Unknown option '$1'" >&2
65+
usage
66+
exit 1
67+
;;
68+
esac
69+
done
70+
71+
72+
TMP_WORK_DIR=$(mktemp -d)
73+
echo "Created a temporary working directory: $TMP_WORK_DIR"
74+
trap 'rm -rf -- "$TMP_WORK_DIR"' EXIT
75+
cd $TMP_WORK_DIR
76+
77+
echo "Cloning the \"$A2A_SPEC_REPO\" repository..."
78+
git clone $A2A_SPEC_REPO spec_repo
79+
cd spec_repo
80+
81+
echo "Checking out the \"$A2A_SPEC_BRANCH\" branch..."
82+
git checkout "$A2A_SPEC_BRANCH"
83+
84+
echo "Invoking the generate_types.sh script..."
85+
GENERATED_FILE="$ROOT_DIR/src/a2a/types.py"
86+
$ROOT_DIR/scripts/generate_types.sh "$GENERATED_FILE" --input-file "$TMP_WORK_DIR/spec_repo/specification/json/a2a.json"
87+
88+
89+
echo "Running buf generate..."
90+
cd "$ROOT_DIR"
91+
buf generate
92+
uv run "$ROOT_DIR/scripts/grpc_gen_post_processor.py"
93+
94+
95+
echo "Committing generated types file to the \"$FEATURE_BRANCH\" branch..."
96+
git checkout -b "$FEATURE_BRANCH"
97+
git add "$GENERATED_FILE" "$ROOT_DIR/src/a2a/grpc"
98+
git commit -m "Experimental types"

scripts/generate_types.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,44 @@
44
# Treat unset variables as an error.
55
set -euo pipefail
66

7-
# Check if an output file path was provided as an argument.
8-
if [ -z "$1" ]; then
9-
echo "Error: Output file path must be provided as the first argument." >&2
7+
REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
8+
9+
GENERATED_FILE=""
10+
INPUT_FILE=""
11+
12+
# Parse command-line arguments
13+
while [[ $# -gt 0 ]]; do
14+
case "$1" in
15+
--input-file)
16+
INPUT_FILE="$2"
17+
shift 2
18+
;;
19+
*)
20+
GENERATED_FILE="$1"
21+
shift 1
22+
;;
23+
esac
24+
done
25+
26+
if [ -z "$GENERATED_FILE" ]; then
27+
echo "Error: Output file path must be provided." >&2
28+
echo "Usage: $0 [--input-file <path>] <output-file-path>"
1029
exit 1
1130
fi
1231

13-
REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
14-
GENERATED_FILE="$1"
15-
1632
echo "Running datamodel-codegen..."
17-
echo " - Source URL: $REMOTE_URL"
33+
declare -a source_args
34+
if [ -n "$INPUT_FILE" ]; then
35+
echo " - Source File: $INPUT_FILE"
36+
source_args=("--input" "$INPUT_FILE")
37+
else
38+
echo " - Source URL: $REMOTE_URL"
39+
source_args=("--url" "$REMOTE_URL")
40+
fi
1841
echo " - Output File: $GENERATED_FILE"
1942

2043
uv run datamodel-codegen \
21-
--url "$REMOTE_URL" \
44+
"${source_args[@]}" \
2245
--input-file-type jsonschema \
2346
--output "$GENERATED_FILE" \
2447
--target-python-version 3.10 \

0 commit comments

Comments
 (0)