From a07077d4cc301979267f58ef19ae32e9b8130740 Mon Sep 17 00:00:00 2001 From: Holt Skinner Date: Tue, 20 May 2025 13:20:01 -0700 Subject: [PATCH 1/4] ci: Create GitHub Action to generate `types.py` from specification JSON --- .github/workflows/update-a2a-types.yml | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/update-a2a-types.yml diff --git a/.github/workflows/update-a2a-types.yml b/.github/workflows/update-a2a-types.yml new file mode 100644 index 00000000..56bf302a --- /dev/null +++ b/.github/workflows/update-a2a-types.yml @@ -0,0 +1,86 @@ +name: Update A2A Schema from Specification + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + check_and_update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.13" + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Configure uv shell + run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + - name: Install dependencies (datamodel-code-generator) + run: uv sync + + - name: Define output file variable + id: vars + run: | + GENERATED_FILE="./src/a2a/types.py" + echo "GENERATED_FILE=$GENERATED_FILE" >> "$GITHUB_OUTPUT" + + - name: Run datamodel-codegen + run: | + set -euo pipefail # Exit immediately if a command exits with a non-zero status + + REMOTE_URL="https://raw.githubusercontent.com/google/A2A/refs/heads/main/specification/json/a2a.json" + GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}" + + echo "Running datamodel-codegen..." + uv run datamodel-codegen \ + --url "$REMOTE_URL" \ + --input-file-type jsonschema \ + --output "$GENERATED_FILE" \ + --target-python-version 3.10 \ + --output-model-type pydantic_v2.BaseModel \ + --disable-timestamp \ + --use-schema-description \ + --use-union-operator \ + --use-field-description \ + --use-default \ + --use-default-kwarg \ + --use-one-literal-as-default \ + --class-name A2A \ + --use-standard-collections + echo "Codegen finished." + + - name: Commit and push if generated file changed + if: github.ref == 'refs/heads/main' # Or your default branch name + run: | + set -euo pipefail + + GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}" + + # Check if the generated file has any changes compared to HEAD + if git diff --quiet "$GENERATED_FILE"; then + echo "$GENERATED_FILE has no changes after codegen. Nothing to commit." + else + echo "Changes detected in $GENERATED_FILE. Committing..." + # Configure git user for the commit + git config user.name "github-actions" + git config user.email "github-actions@github.com" + + # Add the generated file + git add "$GENERATED_FILE" + + # Commit changes + git commit -m "🤖 chore: Auto-update A2A schema from specification" + + # Push changes + git push + echo "Changes committed and pushed." + fi From c1e853b5bdcd4064f886bacdbd49645eff80349f Mon Sep 17 00:00:00 2001 From: holtskinner Date: Wed, 21 May 2025 12:16:48 -0700 Subject: [PATCH 2/4] Update to use a2a-bot --- .github/workflows/update-a2a-types.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-a2a-types.yml b/.github/workflows/update-a2a-types.yml index 56bf302a..c053ef22 100644 --- a/.github/workflows/update-a2a-types.yml +++ b/.github/workflows/update-a2a-types.yml @@ -71,8 +71,8 @@ jobs: else echo "Changes detected in $GENERATED_FILE. Committing..." # Configure git user for the commit - git config user.name "github-actions" - git config user.email "github-actions@github.com" + git config user.name "a2a-bot" + git config user.email "a2a-bot@google.com" # Add the generated file git add "$GENERATED_FILE" From 5b660c03729ed3e59911ff4b244bd46215b26ef6 Mon Sep 17 00:00:00 2001 From: holtskinner Date: Wed, 21 May 2025 12:21:07 -0700 Subject: [PATCH 3/4] Update to create PR --- .github/workflows/update-a2a-types.yml | 50 ++++++++++++-------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/.github/workflows/update-a2a-types.yml b/.github/workflows/update-a2a-types.yml index c053ef22..50c4e3e0 100644 --- a/.github/workflows/update-a2a-types.yml +++ b/.github/workflows/update-a2a-types.yml @@ -2,12 +2,15 @@ name: Update A2A Schema from Specification on: schedule: - - cron: "0 0 * * *" + - cron: "0 0 * * *" # Runs daily at 00:00 UTC workflow_dispatch: jobs: check_and_update: runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write steps: - name: Checkout code @@ -58,29 +61,22 @@ jobs: --use-standard-collections echo "Codegen finished." - - name: Commit and push if generated file changed - if: github.ref == 'refs/heads/main' # Or your default branch name - run: | - set -euo pipefail - - GENERATED_FILE="${{ steps.vars.outputs.GENERATED_FILE }}" - - # Check if the generated file has any changes compared to HEAD - if git diff --quiet "$GENERATED_FILE"; then - echo "$GENERATED_FILE has no changes after codegen. Nothing to commit." - else - echo "Changes detected in $GENERATED_FILE. Committing..." - # Configure git user for the commit - git config user.name "a2a-bot" - git config user.email "a2a-bot@google.com" - - # Add the generated file - git add "$GENERATED_FILE" - - # Commit changes - git commit -m "🤖 chore: Auto-update A2A schema from specification" - - # Push changes - git push - echo "Changes committed and pushed." - fi + - name: Create Pull Request if generated file changed + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + committer: a2a-bot + author: a2a-bot + commit-message: "chore: 🤖 Auto-update A2A schema from specification" + title: "chore: 🤖 Auto-update A2A Schema from Specification" + body: | + This PR automatically updates the A2A schema types based on the latest specification. + + This update was triggered by the scheduled workflow run. + See the workflow run details: [${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) + branch: "a2a-schema-update" + base: main + labels: | + automated + dependencies + add-paths: ${{ steps.vars.outputs.GENERATED_FILE }} From ee862229fdaa5e41ad5ce25ae6f02bc29dba982b Mon Sep 17 00:00:00 2001 From: holtskinner Date: Wed, 21 May 2025 12:22:21 -0700 Subject: [PATCH 4/4] Remove token --- .github/workflows/update-a2a-types.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/update-a2a-types.yml b/.github/workflows/update-a2a-types.yml index 50c4e3e0..b68beed6 100644 --- a/.github/workflows/update-a2a-types.yml +++ b/.github/workflows/update-a2a-types.yml @@ -64,7 +64,6 @@ jobs: - name: Create Pull Request if generated file changed uses: peter-evans/create-pull-request@v6 with: - token: ${{ secrets.GITHUB_TOKEN }} committer: a2a-bot author: a2a-bot commit-message: "chore: 🤖 Auto-update A2A schema from specification"