2026-03-21 21:09:49 -03:00
|
|
|
name: BotServer CI/CD
|
2025-12-16 13:25:26 -03:00
|
|
|
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches: ["main"]
|
|
|
|
|
pull_request:
|
|
|
|
|
branches: ["main"]
|
|
|
|
|
|
2025-12-17 21:56:28 -03:00
|
|
|
env:
|
2026-02-06 09:26:44 -03:00
|
|
|
CARGO_BUILD_JOBS: 8
|
2025-12-18 17:14:36 -03:00
|
|
|
CARGO_NET_RETRY: 10
|
2026-04-03 09:40:16 -03:00
|
|
|
RUSTC_WRAPPER: sccache
|
2026-04-10 20:40:23 -03:00
|
|
|
WORKSPACE: /opt/gbo/data/botserver
|
|
|
|
|
CARGO_TARGET_DIR: /opt/gbo/data/botserver/target
|
2026-04-03 09:45:02 -03:00
|
|
|
PATH: /home/gbuser/.cargo/bin:/home/gbuser/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
2025-12-17 21:56:28 -03:00
|
|
|
|
2025-12-16 13:25:26 -03:00
|
|
|
jobs:
|
|
|
|
|
build:
|
|
|
|
|
runs-on: gbo
|
|
|
|
|
|
|
|
|
|
steps:
|
2026-03-31 15:28:11 -03:00
|
|
|
- name: Setup Git
|
2026-03-31 12:15:25 -03:00
|
|
|
run: |
|
|
|
|
|
git config --global http.sslVerify false
|
|
|
|
|
git config --global --add safe.directory "*"
|
2025-12-16 13:25:26 -03:00
|
|
|
|
2026-04-10 20:40:23 -03:00
|
|
|
- name: Setup Workspace
|
2026-01-25 12:27:50 -03:00
|
|
|
run: |
|
2026-04-10 20:40:23 -03:00
|
|
|
mkdir -p $WORKSPACE
|
2026-03-20 21:39:58 -03:00
|
|
|
cd $WORKSPACE
|
2026-04-10 20:50:58 -03:00
|
|
|
# Clean existing .git to avoid conflicts
|
|
|
|
|
rm -rf /opt/gbo/data/botserver/.git 2>/dev/null || true
|
2026-04-10 20:40:23 -03:00
|
|
|
# Update or clone botserver (preserve git history for sccache fingerprints)
|
|
|
|
|
if [ -d botserver/.git ]; then
|
|
|
|
|
git -C botserver pull origin main
|
|
|
|
|
else
|
|
|
|
|
git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/BotServer.git botserver
|
|
|
|
|
fi
|
|
|
|
|
# Get workspace Cargo.toml from gb and strip unused members
|
|
|
|
|
if [ -d /opt/gbo/data/botserver/.git ]; then
|
|
|
|
|
git -C /opt/gbo/data/botserver pull origin main
|
|
|
|
|
else
|
|
|
|
|
git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git /opt/gbo/data/botserver
|
|
|
|
|
fi
|
|
|
|
|
cp /opt/gbo/data/botserver/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
|
|
|
|
|
# Ensure target dir exists
|
|
|
|
|
mkdir -p target
|
2026-01-25 18:01:19 -03:00
|
|
|
|
2025-12-17 22:40:45 -03:00
|
|
|
- name: Install system dependencies
|
|
|
|
|
run: |
|
2026-04-01 18:19:10 -03:00
|
|
|
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
|
|
|
|
|
sudo apt-get update -qq -o Acquire::Retries=3 -o Acquire::http::Timeout=30
|
|
|
|
|
sudo apt-get install -y --no-install-recommends $MISSING
|
|
|
|
|
else
|
|
|
|
|
echo "All system dependencies already installed"
|
|
|
|
|
fi
|
2025-12-17 22:40:45 -03:00
|
|
|
|
2026-04-09 18:33:53 -03:00
|
|
|
- name: Build BotServer
|
2026-04-10 20:40:23 -03:00
|
|
|
working-directory: /opt/gbo/data/botserver
|
2026-04-09 18:33:53 -03:00
|
|
|
run: |
|
|
|
|
|
export SCCACHE_IDLE_TIMEOUT=300
|
|
|
|
|
export SCCACHE_CACHE_SIZE=10G
|
|
|
|
|
sccache --stop-server 2>/dev/null || true
|
2026-04-10 20:40:23 -03:00
|
|
|
sleep 1
|
2026-04-09 18:33:53 -03:00
|
|
|
sccache --start-server
|
2026-04-10 20:40:23 -03:00
|
|
|
cargo build -p botserver -j 8 2>&1 | tee /tmp/build.log
|
|
|
|
|
echo "=== sccache stats ==="
|
|
|
|
|
sccache --show-stats
|
|
|
|
|
echo "=== Binary info ==="
|
|
|
|
|
ls -lh target/debug/botserver
|
|
|
|
|
stat -c '%y' target/debug/botserver
|
2026-04-09 18:33:53 -03:00
|
|
|
|
2026-04-10 20:40:23 -03:00
|
|
|
- name: Save build log
|
|
|
|
|
if: always()
|
|
|
|
|
run: cp /tmp/build.log /tmp/botserver$(date +%Y%m%d-%H%M%S).log || true
|
2025-12-16 22:29:29 -03:00
|
|
|
|
2026-03-31 19:09:01 -03:00
|
|
|
- name: Deploy via ssh tar gzip
|
2025-12-16 13:25:26 -03:00
|
|
|
run: |
|
2026-04-03 20:36:25 -03:00
|
|
|
set -e
|
2026-04-03 20:04:31 -03:00
|
|
|
SSH_ARGS="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o BatchMode=yes"
|
2026-03-31 18:58:24 -03:00
|
|
|
echo "=== Deploy started ==="
|
2026-03-31 19:09:01 -03:00
|
|
|
echo "Step 1: Checking binary..."
|
2026-04-10 20:40:23 -03:00
|
|
|
ls -lh /opt/gbo/data/botserver/target/debug/botserver
|
2026-04-10 15:36:12 -03:00
|
|
|
echo "Step 2: Backing up old binary..."
|
2026-04-05 19:38:54 -03:00
|
|
|
ssh $SSH_ARGS system "cp /opt/gbo/bin/botserver /tmp/botserver.bak 2>/dev/null || true"
|
2026-04-03 20:39:42 -03:00
|
|
|
echo "Step 3: Stopping botserver service..."
|
|
|
|
|
ssh $SSH_ARGS system "sudo systemctl stop botserver || true"
|
2026-04-03 20:35:38 -03:00
|
|
|
echo "Step 4: Transferring new binary..."
|
2026-04-10 20:40:23 -03:00
|
|
|
tar cf -C /opt/gbo/data/botserver/target/debug botserver | gzip -1 | ssh $SSH_ARGS system "gzip -d | tar xf - -C /opt/gbo/bin && chmod +x /opt/gbo/bin/botserver && chown gbuser:gbuser /opt/gbo/bin/botserver && echo 'Transfer complete'"
|
2026-04-03 20:39:42 -03:00
|
|
|
echo "Step 5: Starting botserver service..."
|
|
|
|
|
ssh $SSH_ARGS system "sudo systemctl start botserver && echo 'Botserver started'"
|
2026-04-03 20:04:31 -03:00
|
|
|
echo "=== Deploy completed ==="
|
|
|
|
|
|
2026-03-21 20:47:13 -03:00
|
|
|
- name: Verify botserver started
|
|
|
|
|
run: |
|
2026-04-03 20:04:31 -03:00
|
|
|
sleep 30
|
|
|
|
|
SSH_ARGS="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o BatchMode=yes"
|
2026-04-03 20:36:25 -03:00
|
|
|
ssh $SSH_ARGS system "pgrep -f botserver >/dev/null && echo 'OK: botserver is running' || echo 'WARNING: botserver may still be starting'"
|
2026-04-10 20:40:23 -03:00
|
|
|
|
|
|
|
|
- name: Save deploy log
|
|
|
|
|
if: always()
|
|
|
|
|
run: cp /tmp/deploy.log /tmp/deploy$(date +%Y%m%d-%H%M%S).log || true
|