-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
172 lines (147 loc) · 5.7 KB
/
deploy.sh
File metadata and controls
172 lines (147 loc) · 5.7 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
#!/usr/bin/env bash
set -euo pipefail
# ============================================================================
# OverLab Action Bots – Deployment Script (Bash)
# Copies selected bots to target repositories and sets up workflows.
# Usage: ./deploy.sh <bot-list> <repo-path1> [repo-path2 ...]
# <bot-list> : comma-separated bot names (e.g., "lfb,endb,ss") or "all"
# <repo-path>: absolute or relative path to local Git repository
# ============================================================================
if [[ $# -lt 2 ]]; then
echo "❌ Usage: $0 <bot-list> <repo-path1> [repo-path2 ...]"
echo " <bot-list> : comma-separated bot names (lfb,endb,ss,...) or 'all'"
exit 1
fi
BOT_LIST="$1"
shift
REPO_PATHS=("$@")
# ----------------------------------------------------------------------------
# Configuration – directory names of available bots
# ----------------------------------------------------------------------------
AVAILABLE_BOTS=(
lfb endb ss bg dc rd sm w2 ev ccr db nat bb cube
)
# Resolve bot list
if [[ "$BOT_LIST" == "all" ]]; then
SELECTED_BOTS=("${AVAILABLE_BOTS[@]}")
else
IFS=',' read -ra SELECTED_BOTS <<< "$BOT_LIST"
fi
# Validate bots
for bot in "${SELECTED_BOTS[@]}"; do
if [[ ! -d "$bot" ]]; then
echo "❌ Bot directory '$bot' not found in OLABS root."
exit 1
fi
done
# ----------------------------------------------------------------------------
# Helper: copy bot to target repository
# ----------------------------------------------------------------------------
deploy_bot() {
local repo="$1"
local bot="$2"
local bot_action_dir="$repo/.github/actions/olabs-$bot"
echo " 🤖 Deploying bot: $bot → $repo/.github/actions/olabs-$bot"
mkdir -p "$bot_action_dir"
# Copy action.yml, entrypoint script, and common library
cp "$bot/$bot.yml" "$bot_action_dir/action.yml"
cp "$bot/$bot.sh" "$bot_action_dir/entrypoint.sh" 2>/dev/null || cp "$bot/$bot.go" "$bot_action_dir/entrypoint.go" 2>/dev/null
chmod +x "$bot_action_dir/entrypoint.sh" 2>/dev/null || true
cp "common/common.sh" "$bot_action_dir/"
chmod +x "$bot_action_dir/common.sh" 2>/dev/null || true
# Create workflow file
mkdir -p "$repo/.github/workflows"
local workflow_file="$repo/.github/workflows/olabs-$bot.yml"
cat > "$workflow_file" <<EOF
name: OLABS $bot
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:
jobs:
run-$bot:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run OverLab $bot
uses: ./.github/actions/olabs-$bot
EOF
echo " ✅ Workflow created: $workflow_file"
}
# ----------------------------------------------------------------------------
# Helper: copy per‑bot config example
# ----------------------------------------------------------------------------
deploy_config() {
local repo="$1"
local bot="$2"
local global_config_file="$repo/overlab_actions.md"
local config_dir=".overlab_actions"
# Determine config directory from global config if it exists
if [[ -f "$global_config_file" ]]; then
local detected_config_dir
detected_config_dir=$(grep -i '^CONFIG_DIR' "$global_config_file" 2>/dev/null | head -1 | cut -d'=' -f2 | sed 's/[[:space:]]*//g')
if [[ -n "$detected_config_dir" ]]; then
config_dir="$detected_config_dir"
fi
fi
local bot_config_dir="$repo/$config_dir/$bot"
mkdir -p "$bot_config_dir"
local config_example="$bot/$bot.md"
if [[ -f "$config_example" && ! -f "$bot_config_dir/config.md" ]]; then
cp "$config_example" "$bot_config_dir/config.md"
echo " ✅ Per‑bot config created: $bot_config_dir/config.md (example)"
else
echo " ⏩ Per‑bot config already exists or example missing, skipping."
fi
}
# ----------------------------------------------------------------------------
# Helper: deploy global config template if missing
# ----------------------------------------------------------------------------
deploy_global_config() {
local repo="$1"
local global_config_file="$repo/overlab_actions.md"
if [[ ! -f "$global_config_file" ]]; then
cp "overlab_actions.md" "$global_config_file"
echo " ✅ Global config created: $global_config_file (edit it!)"
else
echo " ⏩ Global config already exists, skipping."
fi
}
# ----------------------------------------------------------------------------
# Main deployment loop
# ----------------------------------------------------------------------------
for repo in "${REPO_PATHS[@]}"; do
# Expand tilde and resolve absolute/relative path
repo=$(eval echo "$repo")
repo=$(cd "$repo" 2>/dev/null && pwd) || {
echo "⚠️ Cannot access directory: $repo, skipping."
continue
}
echo "📦 Deploying to repository: $repo"
# Ensure target is a Git repository
if [[ ! -d "$repo/.git" ]]; then
echo "⚠️ $repo is not a Git repository, skipping."
continue
fi
# Create required base directories
mkdir -p "$repo/.github/workflows"
mkdir -p "$repo/.github/actions"
# Deploy global config template
deploy_global_config "$repo"
# Deploy each selected bot
for bot in "${SELECTED_BOTS[@]}"; do
deploy_bot "$repo" "$bot"
deploy_config "$repo" "$bot"
done
echo " ✅ Deployment to $repo completed."
echo ""
done
echo "🎉 All deployments finished."
echo "➡️ Next steps:"
echo " - Edit 'overlab_actions.md' in each repository root."
echo " - Review per‑bot configs in .overlab_actions/<bot>/config.md."
echo " - Commit and push the changes to activate bots."