forked from i-am-bee/agentstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.toml
More file actions
326 lines (260 loc) · 9.55 KB
/
tasks.toml
File metadata and controls
326 lines (260 loc) · 9.55 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
## grouped tasks
["setup"]
depends = ["*:setup"]
["check"]
depends = ["*:check"]
["fix"]
depends = ["*:fix"]
["test"]
depends = ["*:test"]
## git hooks
["git-hooks:pre-commit"]
hide = true
depends = ["check"]
## common tasks
### setup
["common:setup"]
depends = ["common:setup:*"]
["common:setup:mise-local-toml"]
hide = true
dir = "{{config_root}}"
run = "test -f mise.local.toml || cp mise.local.toml-example mise.local.toml"
sources = ["mise.local.toml-example"]
outputs = { auto = true }
["common:setup:git-hooks"]
hide = true
dir = "{{config_root}}"
run = "test ! -d .git || (printf '#!/bin/sh\n{{ mise_bin }} run git-hooks:pre-commit' >.git/hooks/pre-commit && chmod +x .git/hooks/pre-commit)"
sources = [".git/hooks/pre-commit"]
outputs = { auto = true }
["common:setup:pnpm"]
hide = true
dir = "{{config_root}}"
run = "pnpm install"
sources = ["pnpm-lock.yaml", "pnpm-workspace.yaml", "apps/*/package.json", "docs/package.json", "agents/*/*/package.json"]
outputs = { auto = true }
### check
["common:check"]
depends = ["common:check:*"]
["common:check:license"]
dir = "{{config_root}}"
run = "addlicense -check -l apache -s=only -c '© BeeAI a Series of LF Projects, LLC' $(fd '\\.(py|[jt]sx?|html|s?css)$')"
["common:check:version"]
dir = "{{config_root}}"
run = '''
#!/usr/bin/env bash
set -euo pipefail
version=$(
{
yq -r .version helm/Chart.yaml
yq -r .appVersion helm/Chart.yaml
yq -r .project.version apps/agentstack-cli/pyproject.toml
yq -r .project.version apps/agentstack-sdk-py/pyproject.toml
yq -r .version apps/agentstack-sdk-ts/package.json
yq -r .project.version apps/agentstack-server/pyproject.toml
yq -r .version apps/agentstack-ui/package.json
yq -r .version apps/beeai-web/package.json
yq -r '.providers[].location | split(":")[-1]' agent-registry.yaml
} | sort -u
)
if [[ $(wc -l <<<"$version") -ne 1 ]]; then echo "ERROR: Version mismatch detected: $(echo $version)" >&2; exit 1; fi
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then echo "ERROR: $version is not valid semver (X.Y.Z or X.Y.Z-rcN)" >&2; exit 1; fi
if [[ "${GITHUB_REF:-}" == refs/tags/* ]] && [[ $GITHUB_REF != "refs/tags/v$version" ]]; then echo "ERROR: GITHUB_REF '$GITHUB_REF' does not match 'refs/tags/v$version'" >&2; exit 1; fi
'''
### fix
["common:fix"]
depends = ["common:fix:*"]
["common:fix:license"]
dir = "{{config_root}}"
run = "addlicense -l apache -s=only -c '© BeeAI a Series of LF Projects, LLC' $(fd '\\.(py|[jt]sx?|html|s?css)$')"
### test
["common:test"]
run = "true" # Empty tests in case there are no tests
# Platform tasks
["agentstack:start"]
depends = ["agentstack-server:build"]
dir = "{{config_root}}"
run = """
#!/bin/bash
set -e
UI_IMPORT=""
UI_TAG=""
if [[ ! "$*" =~ 'ui.enabled=false' ]]; then
{{ mise_bin }} run agentstack-ui:build
UI_IMPORT="--import ghcr.io/i-am-bee/agentstack/agentstack-ui:local"
UI_TAG="--set ui.image.tag=local"
fi
{{ mise_bin }} run agentstack-cli:run -- platform start \
--import "ghcr.io/i-am-bee/agentstack/agentstack-server:local" \
$UI_IMPORT \
--set image.tag=local \
$UI_TAG "$@"
"""
["agentstack:delete"]
run = "{{ mise_bin }} run agentstack-cli:run -- platform delete"
["agentstack:stop"]
run = "{{ mise_bin }} run agentstack-cli:run -- platform stop"
["agentstack:stop-all"]
run = """
#!/bin/bash
# Stop all lima VMs
EXCEPT='{{option(name="except", default="")}}'
{% raw %}
TO_STOP="$(LIMA_HOME=~/.agentstack/lima limactl list -f '{{.Name}};{{.Status}}' | grep -v "Stopped" | cut -d';' -f1 2>/dev/null | sed '/^[^a-z]*$/d' | sed "/^$EXCEPT$/d")"
{% endraw %}
{% raw %}
echo "$TO_STOP" | xargs -rn 1 -I"{}" mise run agentstack-cli:run -- platform stop --vm-name="{}"
{% endraw %}
"""
["agentstack:shell"]
raw = true
shell = "echo"
dir = "{{cwd}}"
run = """
deactivate () {
export PS1="$__OLD_PS1"
# Restore LIMA_HOME to its original state (set or unset)
[[ -n "$__OLD_LIMA_HOME" ]] && export LIMA_HOME="$__OLD_LIMA_HOME" || unset LIMA_HOME
[[ -n "$__OLD_KUBECONFIG" ]] && export KUBECONFIG="$__OLD_KUBECONFIG" || unset KUBECONFIG
# Clean up the backup values
unset __OLD_PS1
unset __OLD_LIMA_HOME
unset __OLD_KUBECONFIG
unset -f deactivate
echo "Environment for '$VM_NAME' deactivated."
}
while [[ -n "$__OLD_PS1" ]]; do
deactivate;
done
VM_NAME={{option(name="vm-name", default="agentstack")}}
echo "Activating environment for '$VM_NAME'..."
export __OLD_PS1="$PS1"
export __OLD_LIMA_HOME="$LIMA_HOME"
export __OLD_KUBECONFIG="$KUBECONFIG"
export KUBECONFIG="${HOME}/.agentstack/lima/${VM_NAME}/copied-from-guest/kubeconfig.yaml"
export LIMA_HOME=~/.agentstack/lima
export PS1="(${VM_NAME}) ${__OLD_PS1}"
"""
["release"]
dir = "{{config_root}}"
run = '''
#!/bin/bash
set -eu -o pipefail
# Ensure on main branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" != "main" ]]; then
echo "ERROR: You must be on the 'main' branch (current: $current_branch)"
exit 1
fi
# Ensure working directory is clean
if [[ -n "$(git status --porcelain)" ]]; then
echo "ERROR: Working directory not clean"
git status
exit 1
fi
current_version=$(yq -r '.version' helm/Chart.yaml)
# Compute suggested next rc version
if [[ "$current_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-rc([0-9]+))?$ ]]; then
if [[ -n "${BASH_REMATCH[5]}" ]]; then
suggested_new_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}-rc$((${BASH_REMATCH[5]} + 1))"
else
suggested_new_version="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((${BASH_REMATCH[3]} + 1))-rc1"
fi
else
echo "ERROR: Invalid version format of current version. Use #.#.#[-rc#]"
exit 1
fi
# Prompt for new version
new_version=$(gum input --prompt.foreground="8" --prompt "Bump from ${current_version} -> " --value "$suggested_new_version")
if [[ ! "$new_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$ ]]; then
echo "ERROR: Invalid version format of new version. Use #.#.#[-rc#]"
exit 1
fi
# Update all version fields
yq -i ".version = \"$new_version\"" helm/Chart.yaml
yq -i ".appVersion = \"$new_version\"" helm/Chart.yaml
(cd apps/agentstack-sdk-py && toml set 'project.version' "$new_version" --toml-path pyproject.toml && uv lock)
(cd apps/agentstack-cli && toml set 'project.version' "$new_version" --toml-path pyproject.toml && uv lock)
(cd apps/agentstack-server && toml set 'project.version' "$new_version" --toml-path pyproject.toml && uv lock)
for agent in agents/*; do (cd $agent && uv lock); done
yq -i ".version = \"$new_version\"" apps/agentstack-sdk-ts/package.json
yq -i ".version = \"$new_version\"" apps/agentstack-ui/package.json
yq -i ".version = \"$new_version\"" apps/beeai-web/package.json
yq -i ".providers[].location |= sub(\":(.*)\$\"; \":\" + \"$new_version\")" agent-registry.yaml
perl -pi -e "s/^(LATEST_AGENTSTACK_VERSION=).*/\${1}$new_version/" install.sh
if [[ "$new_version" != *"-rc"* ]]; then perl -pi -e "s/^(LATEST_STABLE_AGENTSTACK_VERSION=).*/\${1}$new_version/" install.sh; fi
# Confirm commit and push
if gum confirm "Release version $new_version now?"; then
(
set -eux -o pipefail
git add .
git commit -m "release: v$new_version"
git tag "v$new_version"
git push --atomic origin main "v$new_version"
)
if command -v gh >/dev/null; then
gum spin --title="Waiting for GitHub Action to start..." sleep 10
gh run watch $(gh run list --workflow=Release --branch=v$new_version --limit=1 --json databaseId,status -q '.[0].databaseId') || true
fi
echo "GitHub action started. Check the progress and result on: https://github.com/i-am-bee/agentstack/actions/workflows/release.yml"
fi
'''
["sync-images-to-ghcr"]
dir = "{{config_root}}"
depends = ["helm:build:dependencies"]
run = '''
#!/bin/bash
set -euo pipefail
DRY_RUN='{{flag(name='dryrun')}}'
{% raw %}
echo "Extracting images from helm chart..."
# Extract images from helm chart
images=$(helm template \
--set phoenix.enabled=true \
--set encryptionKey=dummy \
--set auth.enabled=false \
--set auth.jwtSecretKey=kyticka \
--set providerBuilds.enabled=true \
--set localDockerRegistry.enabled=true \
./helm 2>/dev/null | \
sed -n '/^[[:space:]]*image:/{ /{{/d; s/.*image:[[:space:]]*//p; }' | \
sed 's/"\([^"]*\)"/\1/' | grep -v 'agentstack')
echo "Found images:"
echo "$images"
# Process each image
echo "$images" | while IFS= read -r ghcr_image; do
if [[ -z "$ghcr_image" ]]; then
continue
fi
echo "Processing image: $ghcr_image"
# Remove ghcr.io/i-am-bee/ prefix to get Docker Hub image
if [[ $ghcr_image =~ ^ghcr\.io/i-am-bee/(.+)$ ]]; then
dockerhub_image="${BASH_REMATCH[1]}"
echo "GHCR image: $ghcr_image"
echo "Docker Hub image: $dockerhub_image"
# Check if image exists in GHCR
if docker manifest inspect "$ghcr_image" >/dev/null 2>&1; then
echo "✅ Image $ghcr_image already exists in GHCR"
continue
fi
echo "❌ Image $ghcr_image not found in GHCR"
if [[ "$DRY_RUN" == "true" ]]; then
echo "🔍 DRY RUN: Would sync $dockerhub_image -> $ghcr_image"
continue
fi
# Check if source image exists in Docker Hub
if ! docker manifest inspect "$dockerhub_image" >/dev/null 2>&1; then
echo "❌ Source image $dockerhub_image not found in Docker Hub"
continue
fi
echo "🔄 Syncing $dockerhub_image -> $ghcr_image"
# Copy image with all architectures using skopeo
skopeo copy --multi-arch all docker://"$dockerhub_image" docker://"$ghcr_image"
echo "✅ Successfully synced $ghcr_image"
else
echo "⚠️ Skipping image with unexpected format: $ghcr_image"
fi
done
echo "Image sync completed!"
{% endraw %}
'''