|
| 1 | +name: Update A2A Schema from Specification |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * *" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check_and_update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: "3.13" |
| 20 | + |
| 21 | + - name: Install uv |
| 22 | + run: curl -LsSf https://astral.sh/uv/install.sh | sh |
| 23 | + |
| 24 | + - name: Configure uv shell |
| 25 | + run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH |
| 26 | + |
| 27 | + - name: Install dependencies (datamodel-code-generator) |
| 28 | + run: uv sync |
| 29 | + |
| 30 | + - name: Define output file variable |
| 31 | + id: vars |
| 32 | + run: | |
| 33 | + GENERATED_FILE="./src/a2a/types.py" |
| 34 | + echo "GENERATED_FILE=$GENERATED_FILE" >> "$GITHUB_OUTPUT" |
| 35 | +
|
| 36 | + - name: Run datamodel-codegen |
| 37 | + run: | |
| 38 | + set -euo pipefail # Exit immediately if a command exits with a non-zero status |
| 39 | +
|
| 40 | + REMOTE_URL="https://raw.githubusercontent.com/google/A2A/refs/heads/main/specification/json/a2a.json" |
| 41 | + GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}" |
| 42 | +
|
| 43 | + echo "Running datamodel-codegen..." |
| 44 | + uv run datamodel-codegen \ |
| 45 | + --url "$REMOTE_URL" \ |
| 46 | + --input-file-type jsonschema \ |
| 47 | + --output "$GENERATED_FILE" \ |
| 48 | + --target-python-version 3.10 \ |
| 49 | + --output-model-type pydantic_v2.BaseModel \ |
| 50 | + --disable-timestamp \ |
| 51 | + --use-schema-description \ |
| 52 | + --use-union-operator \ |
| 53 | + --use-field-description \ |
| 54 | + --use-default \ |
| 55 | + --use-default-kwarg \ |
| 56 | + --use-one-literal-as-default \ |
| 57 | + --class-name A2A \ |
| 58 | + --use-standard-collections |
| 59 | + echo "Codegen finished." |
| 60 | +
|
| 61 | + - name: Commit and push if generated file changed |
| 62 | + if: github.ref == 'refs/heads/main' # Or your default branch name |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | +
|
| 66 | + GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}" |
| 67 | +
|
| 68 | + # Check if the generated file has any changes compared to HEAD |
| 69 | + if git diff --quiet "$GENERATED_FILE"; then |
| 70 | + echo "$GENERATED_FILE has no changes after codegen. Nothing to commit." |
| 71 | + else |
| 72 | + echo "Changes detected in $GENERATED_FILE. Committing..." |
| 73 | + # Configure git user for the commit |
| 74 | + git config user.name "github-actions" |
| 75 | + git config user.email "[email protected]" |
| 76 | +
|
| 77 | + # Add the generated file |
| 78 | + git add "$GENERATED_FILE" |
| 79 | +
|
| 80 | + # Commit changes |
| 81 | + git commit -m "🤖 chore: Auto-update A2A schema from specification" |
| 82 | +
|
| 83 | + # Push changes |
| 84 | + git push |
| 85 | + echo "Changes committed and pushed." |
| 86 | + fi |
0 commit comments