-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
168 lines (147 loc) · 5.26 KB
/
deploy.ps1
File metadata and controls
168 lines (147 loc) · 5.26 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
OverLab Action Bots – Deployment Script (PowerShell)
.DESCRIPTION
Copies selected bots to target repositories and sets up workflows.
.PARAMETER BotList
Comma-separated bot names (e.g., "lfb,endb,ss") or "all"
.PARAMETER RepoPaths
One or more paths to local Git repositories
.EXAMPLE
.\deploy.ps1 all C:\repos\my-project
.\deploy.ps1 lfb,endb ../other-repo
#>
param(
[Parameter(Mandatory=$true)]
[string]$BotList,
[Parameter(Mandatory=$true, ValueFromRemainingArguments=$true)]
[string[]]$RepoPaths
)
# Available bots
$AvailableBots = @(
"lfb", "endb", "ss", "bg", "dc", "rd", "sm", "w2", "ev", "ccr", "db", "nat", "bb", "cube"
)
# Resolve bot list
if ($BotList -eq "all") {
$SelectedBots = $AvailableBots
} else {
$SelectedBots = $BotList -split ','
}
# Validate bots
foreach ($bot in $SelectedBots) {
if (-not (Test-Path "$bot")) {
Write-Error "Bot directory '$bot' not found in OLABS root."
exit 1
}
}
function Deploy-Bot {
param(
[string]$RepoPath,
[string]$Bot
)
$BotActionDir = Join-Path $RepoPath ".github/actions/olabs-$Bot"
Write-Host " 🤖 Deploying bot: $Bot → $BotActionDir"
New-Item -ItemType Directory -Force -Path $BotActionDir | Out-Null
# Copy action.yml, entrypoint script, and common library
Copy-Item "$Bot/$Bot.yml" "$BotActionDir/action.yml"
if (Test-Path "$Bot/$Bot.sh") {
Copy-Item "$Bot/$Bot.sh" "$BotActionDir/entrypoint.sh"
} elseif (Test-Path "$Bot/$Bot.go") {
Copy-Item "$Bot/$Bot.go" "$BotActionDir/entrypoint.go"
}
Copy-Item "common/common.sh" "$BotActionDir/"
# Create workflow file
$WorkflowDir = Join-Path $RepoPath ".github/workflows"
New-Item -ItemType Directory -Force -Path $WorkflowDir | Out-Null
$WorkflowFile = Join-Path $WorkflowDir "olabs-$Bot.yml"
@"
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
"@ | Out-File -FilePath $WorkflowFile -Encoding utf8
Write-Host " ✅ Workflow created: $WorkflowFile"
}
function Deploy-Config {
param(
[string]$RepoPath,
[string]$Bot
)
$GlobalConfigFile = Join-Path $RepoPath "overlab_actions.md"
$ConfigDir = ".overlab_actions"
# Read CONFIG_DIR from global config if it exists
if (Test-Path $GlobalConfigFile) {
$line = Select-String -Path $GlobalConfigFile -Pattern '^CONFIG_DIR\s*=' | Select-Object -First 1
if ($line) {
$ConfigDir = ($line -split '=', 2)[1].Trim()
}
}
$BotConfigDir = Join-Path $RepoPath $ConfigDir $Bot
New-Item -ItemType Directory -Force -Path $BotConfigDir | Out-Null
$ConfigExample = Join-Path $Bot "$Bot.md"
$ConfigTarget = Join-Path $BotConfigDir "config.md"
if ((Test-Path $ConfigExample) -and -not (Test-Path $ConfigTarget)) {
Copy-Item $ConfigExample $ConfigTarget
Write-Host " ✅ Per‑bot config created: $ConfigTarget (example)"
} else {
Write-Host " ⏩ Per‑bot config already exists or example missing, skipping."
}
}
function Deploy-GlobalConfig {
param([string]$RepoPath)
$GlobalConfigFile = Join-Path $RepoPath "overlab_actions.md"
if (-not (Test-Path $GlobalConfigFile)) {
Copy-Item "overlab_actions.md" $GlobalConfigFile
Write-Host " ✅ Global config created: $GlobalConfigFile (edit it!)"
} else {
Write-Host " ⏩ Global config already exists, skipping."
}
}
# ----------------------------------------------------------------------------
# Main deployment loop
# ----------------------------------------------------------------------------
foreach ($rawRepo in $RepoPaths) {
# Resolve full path
$repo = Resolve-Path $rawRepo -ErrorAction SilentlyContinue
if (-not $repo) {
Write-Warning "Cannot access directory: $rawRepo, skipping."
continue
}
$repo = $repo.Path
Write-Host "📦 Deploying to repository: $repo"
# Check if it's a Git repository
if (-not (Test-Path (Join-Path $repo ".git"))) {
Write-Warning "$repo is not a Git repository, skipping."
continue
}
# Create base directories
New-Item -ItemType Directory -Force -Path (Join-Path $repo ".github/workflows") | Out-Null
New-Item -ItemType Directory -Force -Path (Join-Path $repo ".github/actions") | Out-Null
# Deploy global config
Deploy-GlobalConfig $repo
# Deploy each selected bot
foreach ($bot in $SelectedBots) {
Deploy-Bot $repo $bot
Deploy-Config $repo $bot
}
Write-Host " ✅ Deployment to $repo completed." -ForegroundColor Green
Write-Host ""
}
Write-Host "🎉 All deployments finished." -ForegroundColor Green
Write-Host "➡️ Next steps:" -ForegroundColor Yellow
Write-Host " - Edit 'overlab_actions.md' in each repository root." -ForegroundColor Yellow
Write-Host " - Review per‑bot configs in .overlab_actions/<bot>/config.md." -ForegroundColor Yellow
Write-Host " - Commit and push the changes to activate bots." -ForegroundColor Yellow