generalbots/.forgejo/workflows/botserver.yaml
Rodrigo Rodriguez (Pragmatismo) e8e1b7d65b
All checks were successful
BotServer CI/CD / build (push) Successful in 1m37s
ci: Move workspace to /tmp to avoid permission issues
- Use /tmp/persistent-botserver instead of /opt/gbo/data
- Use /tmp/sccache and /tmp/cargo for caches
- Runner has full permissions on /tmp
- Fixes 'Operation not permitted' on chown
2026-04-17 12:53:30 -03:00

122 lines
4.1 KiB
YAML

name: BotServer CI/CD
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
CARGO_BUILD_JOBS: 8
CARGO_NET_RETRY: 10
RUSTC_WRAPPER: sccache
SCCACHE_DIR: /tmp/sccache
CARGO_HOME: /tmp/cargo
CARGO_TARGET_DIR: /tmp/persistent-botserver/target
jobs:
build:
runs-on: gbo
steps:
- name: Install system dependencies
run: |
PKGS="libpq-dev libssl-dev liblzma-dev pkg-config"
MISSING=""
for pkg in $PKGS; do
dpkg -s "$pkg" >/dev/null 2>&1 || MISSING="$MISSING $pkg"
done
if [ -n "$MISSING" ]; then
apt-get update -qq
apt-get install -y --no-install-recommends $MISSING
fi
- name: Setup Workspace
run: |
# Use /tmp for workspace (runner has full permissions)
mkdir -p /tmp/sccache
mkdir -p /tmp/cargo
mkdir -p /tmp/persistent-botserver
mkdir -p /tmp/gb-ws
- name: Setup Git
run: |
git config --global http.sslVerify false
git config --global --add safe.directory "*"
- name: Update Repositories
run: |
set -e
cd /tmp/persistent-botserver
# Update botlib
if [ -d botlib/.git ]; then
echo "Updating botlib..."
(cd botlib && git pull origin main)
else
echo "Cloning botlib..."
git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/botlib.git botlib
fi
# Update botserver
if [ -d botserver/.git ]; then
echo "Updating botserver..."
(cd botserver && git pull origin main)
else
echo "Cloning botserver..."
git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/BotServer.git botserver
fi
# Update gb workspace
if [ -d /tmp/gb-ws/.git ]; then
(cd /tmp/gb-ws && git pull origin main)
else
git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git /tmp/gb-ws
fi
# Copy Cargo.toml
cp /tmp/gb-ws/Cargo.toml Cargo.toml
for m in botapp botdevice bottest botui botbook botmodels botplugin bottemplates; do
grep -v "\"$m\"" Cargo.toml > /tmp/c.toml && mv /tmp/c.toml Cargo.toml
done
- name: Build BotServer
working-directory: /tmp/persistent-botserver
run: |
export PATH="/home/gbuser/.cargo/bin:/home/gbuser/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin:$PATH"
sccache --start-server 2>/dev/null || true
echo "Building BotServer..."
cargo build --package botserver 2>&1 | tee /tmp/build.log
sccache --stop-server 2>/dev/null || true
continue-on-error: true
- name: Deploy
run: |
set -e
SSH_ARGS="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5"
echo "Stopping botserver..."
ssh $SSH_ARGS system "sudo systemctl stop botserver 2>/dev/null || true; sleep 2"
echo "Deploying binary..."
scp $SSH_ARGS /tmp/persistent-botserver/target/debug/botserver system:/tmp/botserver-new
ssh $SSH_ARGS system "sudo mv /tmp/botserver-new /opt/gbo/bin/botserver && sudo chmod +x /opt/gbo/bin/botserver && sudo chown gbuser:gbuser /opt/gbo/bin/botserver"
echo "Starting botserver..."
ssh $SSH_ARGS system "sudo systemctl daemon-reload && sudo systemctl start botserver"
echo "Health check..."
sleep 5
for i in $(seq 1 30); do
if ssh $SSH_ARGS system "curl -sf http://localhost:8080/health" 2>/dev/null; then
echo "Health check passed!"
break
fi
echo "waiting ($i/30)..."
sleep 2
done
- name: Verify
run: |
SSH_ARGS="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no"
ssh $SSH_ARGS system "pgrep -f botserver >/dev/null && echo OK || echo FAIL"