Skip to content

Commit 04492d2

Browse files
committed
feat(scripts): add version support to generate_types.sh
- Add A2A_SPEC_VERSION environment variable (default: v0.3.0) - Support version specification via --version flag - Auto-detect version type (tag/branch/commit SHA) - Add URL validation before generating types - Improve error messages and usage documentation - Add input file existence validation Signed-off-by: Luca Muscariello <[email protected]>
1 parent dc59430 commit 04492d2

File tree

1 file changed

+73
-10
lines changed

1 file changed

+73
-10
lines changed

scripts/generate_types.sh

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

7-
REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
7+
# A2A specification version to use
8+
# Can be overridden via environment variable: A2A_SPEC_VERSION=v1.2.0 ./generate_types.sh
9+
# Or via command-line flag: ./generate_types.sh --version v1.2.0 output.py
10+
# Use a specific git tag, branch name, or commit SHA
11+
# Examples: "v1.0.0", "v1.2.0", "main", "abc123def"
12+
A2A_SPEC_VERSION="${A2A_SPEC_VERSION:-v0.3.0}"
13+
14+
# Build URL based on version format
15+
# Tags use /refs/tags/, branches use /refs/heads/, commits use direct ref
16+
build_remote_url() {
17+
local version="$1"
18+
local base_url="https://raw.githubusercontent.com/a2aproject/A2A"
19+
20+
if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
21+
# Looks like a version tag (v1.0.0, v1.2.3)
22+
echo "${base_url}/refs/tags/${version}/specification/json/a2a.json"
23+
elif [[ "$version" =~ ^[0-9a-f]{7,40}$ ]]; then
24+
# Looks like a commit SHA (7+ hex chars)
25+
echo "${base_url}/${version}/specification/json/a2a.json"
26+
else
27+
# Assume it's a branch name (main, develop, etc.)
28+
echo "${base_url}/refs/heads/${version}/specification/json/a2a.json"
29+
fi
30+
}
31+
32+
REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION")
833

934
GENERATED_FILE=""
1035
INPUT_FILE=""
1136

1237
# Parse command-line arguments
1338
while [[ $# -gt 0 ]]; do
1439
case "$1" in
15-
--input-file)
16-
INPUT_FILE="$2"
17-
shift 2
18-
;;
19-
*)
20-
GENERATED_FILE="$1"
21-
shift 1
22-
;;
40+
--input-file)
41+
INPUT_FILE="$2"
42+
shift 2
43+
;;
44+
--version)
45+
A2A_SPEC_VERSION="$2"
46+
REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION")
47+
shift 2
48+
;;
49+
*)
50+
GENERATED_FILE="$1"
51+
shift 1
52+
;;
2353
esac
2454
done
2555

2656
if [ -z "$GENERATED_FILE" ]; then
2757
echo "Error: Output file path must be provided." >&2
28-
echo "Usage: $0 [--input-file <path>] <output-file-path>"
58+
echo "Usage: $0 [--input-file <path>] [--version <version>] <output-file-path>"
59+
echo ""
60+
echo "Options:"
61+
echo " --input-file <path> Use a local JSON schema file instead of fetching from remote"
62+
echo " --version <version> Specify A2A spec version (default: v0.3.0)"
63+
echo " Can be a git tag (v1.0.0), branch (main), or commit SHA"
64+
echo ""
65+
echo "Environment variables:"
66+
echo " A2A_SPEC_VERSION Override default spec version"
67+
echo ""
68+
echo "Examples:"
69+
echo " $0 src/a2a/types.py"
70+
echo " $0 --version v1.2.0 src/a2a/types.py"
71+
echo " $0 --input-file local/a2a.json src/a2a/types.py"
72+
echo " A2A_SPEC_VERSION=main $0 src/a2a/types.py"
2973
exit 1
3074
fi
3175

3276
echo "Running datamodel-codegen..."
3377
declare -a source_args
3478
if [ -n "$INPUT_FILE" ]; then
3579
echo " - Source File: $INPUT_FILE"
80+
if [ ! -f "$INPUT_FILE" ]; then
81+
echo "Error: Input file does not exist: $INPUT_FILE" >&2
82+
exit 1
83+
fi
3684
source_args=("--input" "$INPUT_FILE")
3785
else
86+
echo " - A2A Spec Version: $A2A_SPEC_VERSION"
3887
echo " - Source URL: $REMOTE_URL"
88+
89+
# Validate that the remote URL is accessible
90+
echo " - Validating remote URL..."
91+
if ! curl --fail --silent --head "$REMOTE_URL" >/dev/null 2>&1; then
92+
echo "" >&2
93+
echo "Error: Unable to access A2A specification at version '$A2A_SPEC_VERSION'" >&2
94+
echo "URL: $REMOTE_URL" >&2
95+
echo "" >&2
96+
echo "The version may not exist. Available versions can be found at:" >&2
97+
echo " https://github.com/a2aproject/A2A/tags" >&2
98+
echo "" >&2
99+
exit 1
100+
fi
101+
39102
source_args=("--url" "$REMOTE_URL")
40103
fi
41104
echo " - Output File: $GENERATED_FILE"

0 commit comments

Comments
 (0)