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