forked from google/adk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·228 lines (200 loc) · 6.44 KB
/
update.sh
File metadata and controls
executable file
·228 lines (200 loc) · 6.44 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#
# ADK Update Script
#
# Safely updates the ADK repository and dependencies while maintaining compatibility.
# Usage: ./update.sh [--skip-tests] [--force]
#
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
SKIP_TESTS=false
FORCE_UPDATE=false
BACKUP_DIR=".backup_$(date +%Y%m%d_%H%M%S)"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--skip-tests)
SKIP_TESTS=true
shift
;;
--force)
FORCE_UPDATE=true
shift
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --skip-tests Skip running tests after update"
echo " --force Force update even if there are uncommitted changes"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
exit 1
;;
esac
done
# Helper functions
print_step() {
echo -e "\n${BLUE}==>${NC} ${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}WARNING:${NC} $1"
}
print_error() {
echo -e "${RED}ERROR:${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
# Check if we're in a git repository
if [ ! -d ".git" ]; then
print_error "Not in a git repository. Please run this from the ADK root directory."
exit 1
fi
print_step "ADK Update Script"
echo "This script will:"
echo " 1. Check for uncommitted changes"
echo " 2. Pull latest changes from GitHub"
echo " 3. Update Python dependencies"
echo " 4. Run compatibility checks"
echo " 5. Run tests (unless --skip-tests)"
echo ""
# Step 1: Check for uncommitted changes
print_step "Checking for uncommitted changes..."
if ! git diff-index --quiet HEAD --; then
if [ "$FORCE_UPDATE" = false ]; then
print_warning "You have uncommitted changes:"
git status --short
echo ""
read -p "Do you want to stash these changes and continue? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git stash push -m "Auto-stash before update $(date +%Y%m%d_%H%M%S)"
print_success "Changes stashed"
else
print_error "Update cancelled. Commit or stash your changes first."
exit 1
fi
else
print_warning "Uncommitted changes detected, but --force flag is set. Continuing..."
fi
else
print_success "Working directory is clean"
fi
# Step 2: Fetch and check for updates
print_step "Checking for updates..."
git fetch origin
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
if [ $LOCAL = $REMOTE ]; then
print_success "Already up to date!"
echo "No updates available from GitHub."
elif [ $LOCAL = $BASE ]; then
print_step "Updates available. Pulling changes..."
# Show what will be updated
echo ""
echo "Changes to be pulled:"
git log --oneline HEAD..@{u} | head -10
echo ""
# Pull changes
git pull origin main
print_success "Successfully pulled latest changes"
else
print_error "Your branch has diverged from origin/main"
echo "Please resolve this manually with 'git status' and 'git pull'"
exit 1
fi
# Step 3: Check for requirements.txt changes
print_step "Checking for dependency updates..."
if git diff HEAD@{1} HEAD --name-only | grep -q "requirements.txt"; then
print_warning "requirements.txt has been updated"
# Backup current environment (if using venv)
if [ -n "$VIRTUAL_ENV" ]; then
print_step "Updating Python dependencies..."
pip install -r requirements.txt --upgrade
print_success "Dependencies updated"
else
print_warning "Not in a virtual environment. You may need to manually install dependencies:"
echo " pip install -r requirements.txt --upgrade"
fi
else
print_success "No dependency changes detected"
fi
# Step 4: Run compatibility checks
print_step "Running compatibility checks..."
# Check Python version
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2)
REQUIRED_VERSION="3.11"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
print_error "Python $REQUIRED_VERSION or higher is required (found $PYTHON_VERSION)"
exit 1
else
print_success "Python version check passed ($PYTHON_VERSION)"
fi
# Check if critical dependencies are installed
print_step "Verifying critical dependencies..."
MISSING_DEPS=()
python3 -c "import atlassian" 2>/dev/null || MISSING_DEPS+=("atlassian-python-api")
python3 -c "import bs4" 2>/dev/null || MISSING_DEPS+=("beautifulsoup4")
python3 -c "import dotenv" 2>/dev/null || MISSING_DEPS+=("python-dotenv")
if [ ${#MISSING_DEPS[@]} -gt 0 ]; then
print_warning "Missing dependencies detected: ${MISSING_DEPS[*]}"
if [ -n "$VIRTUAL_ENV" ]; then
print_step "Installing missing dependencies..."
pip install "${MISSING_DEPS[@]}"
print_success "Missing dependencies installed"
else
print_error "Please install missing dependencies manually:"
echo " pip install ${MISSING_DEPS[*]}"
exit 1
fi
else
print_success "All critical dependencies are installed"
fi
# Step 5: Run tests
if [ "$SKIP_TESTS" = false ]; then
print_step "Running tests..."
if command -v pytest &> /dev/null; then
# Run backend service tests
if pytest backend/services/test_*.py -v --tb=short; then
print_success "All tests passed"
else
print_error "Some tests failed. Please review the output above."
echo ""
echo "You can skip tests with: ./update.sh --skip-tests"
exit 1
fi
else
print_warning "pytest not found. Skipping tests."
echo "Install pytest with: pip install pytest pytest-asyncio"
fi
else
print_warning "Skipping tests (--skip-tests flag)"
fi
# Step 6: Summary
print_step "Update Summary"
echo ""
echo "✓ Repository updated to latest version"
echo "✓ Dependencies verified and updated"
echo "✓ Compatibility checks passed"
if [ "$SKIP_TESTS" = false ]; then
echo "✓ Tests passed"
fi
echo ""
print_success "Update completed successfully!"
echo ""
echo "Recent changes:"
git log --oneline -5
echo ""
echo "To see what changed: git log --stat HEAD@{1}..HEAD"
echo "To see full diff: git diff HEAD@{1}..HEAD"