name: BotServer CI/CD on: push: branches: ["main"] pull_request: branches: ["main"] env: CARGO_BUILD_JOBS: 4 CARGO_NET_RETRY: 10 jobs: build: runs-on: gbo steps: - name: Setup Git run: | git config --global http.sslVerify false git config --global --add safe.directory "*" - name: Setup Workspace inside container run: | echo "=== Setting up workspace inside container ===" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 system "incus exec system -- bash -c ' mkdir -p /opt/gbo/ci/botserver cd /opt/gbo/ci/botserver # Clone botlib if [ -d botlib/.git ]; then git -C botlib fetch --depth 1 origin main && git -C botlib checkout FETCH_HEAD else git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/botlib.git botlib fi # Clone botserver if [ -d botserver/.git ]; then git -C botserver fetch --depth 1 origin main && git -C botserver checkout FETCH_HEAD else git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/BotServer.git botserver fi # Clone gb workspace and get Cargo.toml git clone --depth 1 --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git /tmp/gb-ws 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 rm -rf /tmp/gb-ws echo \"Workspace setup complete\" '" - name: Install system dependencies in container run: | ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 system "incus exec system -- bash -c ' 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 -o Acquire::Retries=3 -o Acquire::http::Timeout=30 apt-get install -y --no-install-recommends \$MISSING else echo \"All system dependencies already installed\" fi '" - name: Build BotServer inside container run: | echo "=== Building BotServer inside container ===" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=60 system "incus exec system -- bash -c ' cd /opt/gbo/ci/botserver export CARGO_BUILD_JOBS=4 cargo build -p botserver --features chat 2>&1 | tee /tmp/build.log ls -lh target/debug/botserver '" - name: Save build log run: | ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 system "incus exec system -- cat /tmp/build.log > /tmp/botserver-build.log" || true cat /tmp/botserver-build.log 2>/dev/null | tail -30 || echo "Build log not available" - name: Deploy BotServer run: | echo "=== Deploy started ===" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 system "incus exec system -- bash -c ' echo \"Step 1: Killing old botserver...\" pgrep -f botserver && killall botserver 2>/dev/null || echo \"No running botserver\" sleep 2 echo \"Step 2: Removing old binary...\" rm -f /opt/gbo/bin/botserver echo \"Step 3: Copying new binary...\" cp /opt/gbo/ci/botserver/target/debug/botserver /opt/gbo/bin/botserver chmod +x /opt/gbo/bin/botserver echo \"Step 4: Setting permissions...\" chown gbuser:gbuser /opt/gbo/bin/botserver ls -lh /opt/gbo/bin/botserver echo \"=== Deploy completed ===\" '" - name: Verify botserver started run: | sleep 10 ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 system "incus exec system -- bash -c ' pgrep -f botserver && echo \"OK: botserver is running\" || (echo \"ERROR: botserver not running\" && cat /opt/gbo/logs/error.log | tail -20 && exit 1) '"