Skip to content

Commit 26345f7

Browse files
mrice32Reinis-FRPclaude
authored
feat: improve PM notifier run-local script (#4933)
Signed-off-by: Matt Rice <matthewcrice32@gmail.com> Co-authored-by: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1cccaa0 commit 26345f7

File tree

1 file changed

+90
-24
lines changed

1 file changed

+90
-24
lines changed

packages/monitor-v2/src/monitor-polymarket/run-local.sh

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@ prompt() {
4040
echo -e "${GREEN}[?]${NC} $1"
4141
}
4242

43+
# Ensure a repo is on master and up to date.
44+
# Usage: ensure_repo_up_to_date <repo_path> <repo_name>
45+
ensure_repo_up_to_date() {
46+
local repo_path="$1"
47+
local repo_name="$2"
48+
local current_branch
49+
50+
current_branch="$(git -C "$repo_path" rev-parse --abbrev-ref HEAD)"
51+
52+
if [[ "$current_branch" != "master" ]]; then
53+
warn "$repo_name is on branch '$current_branch', not 'master'."
54+
prompt "Switch $repo_name to master? (y/N)"
55+
read -r SWITCH_BRANCH
56+
if [[ "$SWITCH_BRANCH" =~ ^[Yy]$ ]]; then
57+
git -C "$repo_path" checkout master
58+
success "$repo_name switched to master"
59+
else
60+
info "Skipping branch switch for $repo_name (staying on '$current_branch')"
61+
return
62+
fi
63+
fi
64+
65+
git -C "$repo_path" fetch origin master --quiet
66+
local local_rev remote_rev
67+
local_rev="$(git -C "$repo_path" rev-parse HEAD)"
68+
remote_rev="$(git -C "$repo_path" rev-parse origin/master)"
69+
70+
if [[ "$local_rev" != "$remote_rev" ]]; then
71+
warn "$repo_name master is behind origin/master."
72+
prompt "Pull latest changes for $repo_name? (y/N)"
73+
read -r PULL_CHANGES
74+
if [[ "$PULL_CHANGES" =~ ^[Yy]$ ]]; then
75+
git -C "$repo_path" pull origin master
76+
success "$repo_name is now up to date"
77+
else
78+
info "Skipping pull for $repo_name"
79+
fi
80+
else
81+
success "$repo_name master is up to date"
82+
fi
83+
}
84+
4385
# Header
4486
echo ""
4587
echo "=============================================="
@@ -74,30 +116,38 @@ success "UMA Protocol path: $UMA_PROTOCOL"
74116
echo ""
75117

76118
# Check for bot-configs repository
77-
prompt "Enter the path to your bot-configs repository (required for .env generation):"
78-
echo " If you don't have it, clone it first:"
79-
echo " git clone git@github.com:UMAprotocol/bot-configs.git"
80-
echo ""
119+
BOT_CONFIGS_CLONED_TEMP=false
120+
prompt "Enter the path to your bot-configs repository, or press Enter to clone into a temp directory:"
81121
read -r UMA_BOT_CONFIGS
82122

83123
if [[ -z "$UMA_BOT_CONFIGS" ]]; then
84-
error "bot-configs path is required"
85-
exit 1
86-
fi
124+
UMA_BOT_CONFIGS="$(mktemp -d)/bot-configs"
125+
info "Cloning bot-configs into $UMA_BOT_CONFIGS..."
126+
git clone git@github.com:UMAprotocol/bot-configs.git "$UMA_BOT_CONFIGS"
127+
BOT_CONFIGS_CLONED_TEMP=true
128+
success "bot-configs cloned to: $UMA_BOT_CONFIGS"
129+
else
130+
# Expand ~ if present
131+
UMA_BOT_CONFIGS="${UMA_BOT_CONFIGS/#\~/$HOME}"
87132

88-
# Expand ~ if present
89-
UMA_BOT_CONFIGS="${UMA_BOT_CONFIGS/#\~/$HOME}"
133+
if [[ ! -d "$UMA_BOT_CONFIGS" ]]; then
134+
error "bot-configs directory not found: $UMA_BOT_CONFIGS"
135+
exit 1
136+
fi
90137

91-
if [[ ! -d "$UMA_BOT_CONFIGS" ]]; then
92-
error "bot-configs directory not found: $UMA_BOT_CONFIGS"
93-
exit 1
138+
if [[ ! -f "$UMA_BOT_CONFIGS/scripts/print-env-file.js" ]]; then
139+
error "Invalid bot-configs repository: scripts/print-env-file.js not found"
140+
exit 1
141+
fi
142+
success "bot-configs path: $UMA_BOT_CONFIGS"
94143
fi
144+
echo ""
95145

96-
if [[ ! -f "$UMA_BOT_CONFIGS/scripts/print-env-file.js" ]]; then
97-
error "Invalid bot-configs repository: scripts/print-env-file.js not found"
98-
exit 1
146+
# Ensure both repos are on master and up to date
147+
ensure_repo_up_to_date "$UMA_PROTOCOL" "UMA Protocol"
148+
if [[ "$BOT_CONFIGS_CLONED_TEMP" != "true" ]]; then
149+
ensure_repo_up_to_date "$UMA_BOT_CONFIGS" "bot-configs"
99150
fi
100-
success "bot-configs path: $UMA_BOT_CONFIGS"
101151
echo ""
102152

103153
# Export paths
@@ -110,16 +160,23 @@ echo " Step 2: Install Dependencies (bot-configs)"
110160
echo "=============================================="
111161
echo ""
112162

113-
prompt "Do you need to install/update dependencies in bot-configs? (y/N)"
114-
read -r INSTALL_BOT_CONFIGS_DEPS
115-
116-
if [[ "$INSTALL_BOT_CONFIGS_DEPS" =~ ^[Yy]$ ]]; then
117-
info "Installing dependencies in bot-configs..."
163+
if [[ "$BOT_CONFIGS_CLONED_TEMP" == "true" ]]; then
164+
info "Installing dependencies in freshly cloned bot-configs..."
118165
cd "$UMA_BOT_CONFIGS"
119166
yarn install
120167
success "bot-configs dependencies installed"
121168
else
122-
info "Skipping bot-configs dependency installation"
169+
prompt "Do you need to install/update dependencies in bot-configs? (y/N)"
170+
read -r INSTALL_BOT_CONFIGS_DEPS
171+
172+
if [[ "$INSTALL_BOT_CONFIGS_DEPS" =~ ^[Yy]$ ]]; then
173+
info "Installing dependencies in bot-configs..."
174+
cd "$UMA_BOT_CONFIGS"
175+
yarn install
176+
success "bot-configs dependencies installed"
177+
else
178+
info "Skipping bot-configs dependency installation"
179+
fi
123180
fi
124181
echo ""
125182

@@ -156,7 +213,8 @@ if [[ "$GENERATE_ENV" == "true" ]]; then
156213

157214
# Set POLLING_DELAY=0 for one-shot mode
158215
if grep -q '^POLLING_DELAY=' "$ENV_FILE"; then
159-
sed -i 's/^POLLING_DELAY=.*/POLLING_DELAY=0/' "$ENV_FILE"
216+
sed -i.bak 's/^POLLING_DELAY=.*/POLLING_DELAY=0/' "$ENV_FILE"
217+
rm -f "${ENV_FILE}.bak"
160218
else
161219
echo 'POLLING_DELAY=0' >> "$ENV_FILE"
162220
fi
@@ -166,11 +224,19 @@ else
166224
info "Using existing .env.local file"
167225
# Ensure POLLING_DELAY=0 for one-shot mode
168226
if grep -q '^POLLING_DELAY=' "$ENV_FILE"; then
169-
sed -i 's/^POLLING_DELAY=.*/POLLING_DELAY=0/' "$ENV_FILE"
227+
sed -i.bak 's/^POLLING_DELAY=.*/POLLING_DELAY=0/' "$ENV_FILE"
228+
rm -f "${ENV_FILE}.bak"
170229
else
171230
echo 'POLLING_DELAY=0' >> "$ENV_FILE"
172231
fi
173232
fi
233+
234+
# Clean up temp bot-configs clone (contains sensitive data)
235+
if [[ "$BOT_CONFIGS_CLONED_TEMP" == "true" ]]; then
236+
info "Removing temporary bot-configs clone..."
237+
rm -rf "$UMA_BOT_CONFIGS"
238+
success "Temporary bot-configs removed"
239+
fi
174240
echo ""
175241

176242
# Step 4: Build monitor-v2

0 commit comments

Comments
 (0)