|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: ADK Issue Fix Implementation |
| 16 | + |
| 17 | +on: |
| 18 | + issue_comment: |
| 19 | + types: [created] |
| 20 | + workflow_dispatch: |
| 21 | + inputs: |
| 22 | + issue_url: |
| 23 | + description: 'The URL of the GitHub issue to fix' |
| 24 | + required: true |
| 25 | + type: string |
| 26 | + |
| 27 | +jobs: |
| 28 | + issue-fix: |
| 29 | + if: >- |
| 30 | + github.repository == 'google/adk-python' && ( |
| 31 | + github.event_name == 'workflow_dispatch' || |
| 32 | + (github.event_name == 'issue_comment' && |
| 33 | + !github.event.issue.pull_request && |
| 34 | + startsWith(github.event.comment.body, '/adk-issue-fix') && ( |
| 35 | + github.event.comment.author_association == 'OWNER' || |
| 36 | + github.event.comment.author_association == 'MEMBER' || |
| 37 | + github.event.comment.author_association == 'COLLABORATOR' |
| 38 | + )) |
| 39 | + ) |
| 40 | + runs-on: ubuntu-latest |
| 41 | + permissions: |
| 42 | + issues: write |
| 43 | + contents: write |
| 44 | + pull-requests: write |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v6 |
| 49 | + with: |
| 50 | + token: ${{ secrets.ADK_TRIAGE_AGENT }} |
| 51 | + fetch-depth: 0 |
| 52 | + |
| 53 | + - name: Set up Python |
| 54 | + uses: actions/setup-python@v6 |
| 55 | + with: |
| 56 | + python-version: '3.11' |
| 57 | + |
| 58 | + - name: Authenticate to Google Cloud |
| 59 | + id: auth |
| 60 | + uses: 'google-github-actions/auth@v3' |
| 61 | + with: |
| 62 | + credentials_json: '${{ secrets.ADK_GCP_SA_KEY }}' |
| 63 | + |
| 64 | + - name: Install Google Antigravity SDK |
| 65 | + run: pip install google-antigravity |
| 66 | + |
| 67 | + - name: Run Antigravity Fix |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.ADK_TRIAGE_AGENT }} |
| 70 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 71 | + run: | |
| 72 | + python scripts/run_antigravity.py "/adk-issue-fix ${{ github.event.issue.html_url || inputs.issue_url }}" |
| 73 | +
|
| 74 | + - name: Check for changes and create Pull Request |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.ADK_TRIAGE_AGENT }} |
| 77 | + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} |
| 78 | + run: | |
| 79 | + if [ -n "$(git status --porcelain)" ]; then |
| 80 | + echo "Changes detected in workspace. Committing and creating Pull Request..." |
| 81 | +
|
| 82 | + # Setup git configs |
| 83 | + git config --local user.name "adk-bot" |
| 84 | + git config --local user.email "adk-bot@google.com" |
| 85 | +
|
| 86 | + # Extract issue number and export it for python |
| 87 | + ISSUE_URL="${{ github.event.issue.html_url || inputs.issue_url }}" |
| 88 | + export ISSUE_NUMBER=$(echo "$ISSUE_URL" | grep -oP '/issues/\K[0-9]+') |
| 89 | +
|
| 90 | + # Determine branch name to push |
| 91 | + CURRENT_BRANCH=$(git branch --show-current) |
| 92 | + EXPECTED_BRANCH="fix/issue-${ISSUE_NUMBER}" |
| 93 | + if [ "$CURRENT_BRANCH" != "$EXPECTED_BRANCH" ]; then |
| 94 | + echo "Error: Current branch is '$CURRENT_BRANCH', but expected '$EXPECTED_BRANCH'." |
| 95 | + echo "The Antigravity Agent was expected to create and checkout '$EXPECTED_BRANCH'." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + BRANCH_NAME="$CURRENT_BRANCH" |
| 99 | +
|
| 100 | + # Run Antigravity to stage and commit changes with autogenerated message |
| 101 | + python scripts/run_antigravity.py "Analyze the unstaged changes in the workspace, stage all of them, and commit them using git. Generate a highly precise conventional commit message based on the diff." |
| 102 | +
|
| 103 | + # Append the closes tag using Python to avoid relying on LLM formatting |
| 104 | + python -c "import os, subprocess; msg = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'], text=True); tag = 'closes https://github.com/google/adk-python/issues/' + os.environ['ISSUE_NUMBER']; subprocess.run(['git', 'commit', '--amend', '-m', msg.strip() + '\n\n' + tag], check=True) if tag not in msg else None" |
| 105 | +
|
| 106 | + # Retrieve the username of the authenticated user |
| 107 | + BOT_USER=$(gh api user --jq .login) |
| 108 | + echo "Authenticated bot user is $BOT_USER" |
| 109 | +
|
| 110 | + # Ensure the fork exists |
| 111 | + gh repo fork google/adk-python --clone=false || true |
| 112 | +
|
| 113 | + # Push the branch to the bot fork |
| 114 | + git remote add fork "https://x-access-token:${{ secrets.ADK_TRIAGE_AGENT }}@github.com/${BOT_USER}/adk-python.git" |
| 115 | + git push fork "$BRANCH_NAME" --force |
| 116 | +
|
| 117 | + # Retrieve the commit message of the last commit |
| 118 | + COMMIT_MSG=$(git log -1 --pretty=%B) |
| 119 | +
|
| 120 | + # Create PR from the bot fork to the main repository |
| 121 | + gh pr create \ |
| 122 | + --repo google/adk-python \ |
| 123 | + --title "fix(issue): fix issue #${ISSUE_NUMBER}" \ |
| 124 | + --body "$COMMIT_MSG" \ |
| 125 | + --head "${BOT_USER}:$BRANCH_NAME" \ |
| 126 | + --base "main" |
| 127 | + else |
| 128 | + echo "No changes made by the agent. Skipping PR creation." |
| 129 | + fi |
0 commit comments