|
| 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" |
0 commit comments