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
|
|
|
|
|
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-01-25 12:27:50 -03:00
|
|
|
- name: Setup Workspace
|
|
|
|
|
run: |
|
2026-03-20 21:39:58 -03:00
|
|
|
mkdir -p $WORKSPACE
|
|
|
|
|
cd $WORKSPACE
|
2026-04-10 08:17:28 -03:00
|
|
|
|
|
|
|
|
# Fetch latest changes first
|
|
|
|
|
echo "=== Checking for updates ==="
|
|
|
|
|
|
|
|
|
|
# Update or clone botlib
|
2026-03-20 21:39:58 -03:00
|
|
|
if [ -d botlib/.git ]; then
|
2026-04-10 08:17:28 -03:00
|
|
|
echo "Updating botlib..."
|
|
|
|
|
git -C botlib fetch origin main
|
|
|
|
|
if ! git -C botlib diff origin/main --quiet 2>/dev/null; then
|
|
|
|
|
echo "botlib has changes, pulling..."
|
|
|
|
|
git -C botlib pull --ff-only origin main
|
|
|
|
|
else
|
|
|
|
|
echo "botlib up to date"
|
|
|
|
|
fi
|
2026-03-20 21:39:58 -03:00
|
|
|
else
|
2026-04-04 08:09:50 -03:00
|
|
|
git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/botlib.git botlib
|
2026-03-20 21:39:58 -03:00
|
|
|
fi
|
2026-04-10 08:17:28 -03:00
|
|
|
|
|
|
|
|
# Update or clone botserver
|
2026-03-20 21:39:58 -03:00
|
|
|
if [ -d botserver/.git ]; then
|
2026-04-10 08:17:28 -03:00
|
|
|
echo "Updating botserver..."
|
|
|
|
|
git -C botserver fetch origin main
|
|
|
|
|
if ! git -C botserver diff origin/main --quiet 2>/dev/null; then
|
|
|
|
|
echo "botserver has changes, pulling..."
|
|
|
|
|
git -C botserver pull --ff-only origin main
|
|
|
|
|
else
|
|
|
|
|
echo "botserver up to date"
|
|
|
|
|
fi
|
2026-03-20 21:39:58 -03:00
|
|
|
else
|
2026-04-04 08:09:50 -03:00
|
|
|
git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/BotServer.git botserver
|
2026-03-20 21:39:58 -03:00
|
|
|
fi
|
2026-04-10 08:17:28 -03:00
|
|
|
|
|
|
|
|
# Get workspace Cargo.toml from gb
|
2026-04-03 09:40:16 -03:00
|
|
|
if [ -d /opt/gbo/data/gb-ws/.git ]; then
|
2026-04-10 08:17:28 -03:00
|
|
|
git -C /opt/gbo/data/gb-ws fetch origin main
|
|
|
|
|
if ! git -C /opt/gbo/data/gb-ws diff origin/main --quiet 2>/dev/null; then
|
|
|
|
|
echo "gb-ws has changes, pulling..."
|
|
|
|
|
git -C /opt/gbo/data/gb-ws pull --ff-only origin main
|
|
|
|
|
else
|
|
|
|
|
echo "gb-ws up to date"
|
|
|
|
|
fi
|
2026-04-03 09:40:16 -03:00
|
|
|
else
|
2026-04-04 08:09:50 -03:00
|
|
|
git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git /opt/gbo/data/gb-ws
|
2026-04-03 09:40:16 -03:00
|
|
|
fi
|
2026-04-10 08:17:28 -03:00
|
|
|
|
|
|
|
|
# Only rebuild if there were actual changes
|
|
|
|
|
echo "$WORKSPACE" > /tmp/workspace_path
|
|
|
|
|
|
2026-04-03 09:40:16 -03:00
|
|
|
cp /opt/gbo/data/gb-ws/Cargo.toml Cargo.toml
|
2026-03-20 21:45:17 -03:00
|
|
|
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
|
2026-04-10 08:17:28 -03:00
|
|
|
|
2026-04-10 08:14:53 -03:00
|
|
|
# Ensure target dir exists (use persistent location for sccache)
|
|
|
|
|
mkdir -p /opt/gbo/data/botserver/target
|
2026-04-10 08:17:28 -03:00
|
|
|
|
|
|
|
|
# Pre-fetch dependencies
|
|
|
|
|
cargo fetch 2>/dev/null || true
|
2026-04-10 08:14:53 -03:00
|
|
|
|
|
|
|
|
- name: Cache sccache
|
|
|
|
|
uses: actions/cache@v4
|
|
|
|
|
with:
|
|
|
|
|
path: ~/.cache/sccache
|
|
|
|
|
key: sccache-botserver-${{ github.sha }}
|
|
|
|
|
restore-keys: sccache-botserver-
|
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
|
|
|
|
|
working-directory: /opt/gbo/data/botserver
|
|
|
|
|
run: |
|
|
|
|
|
set -e
|
|
|
|
|
export SCCACHE_IDLE_TIMEOUT=300
|
|
|
|
|
export SCCACHE_CACHE_SIZE=10G
|
|
|
|
|
sccache --stop-server 2>/dev/null || true
|
|
|
|
|
sleep 1
|
|
|
|
|
sccache --start-server
|
2026-04-10 08:17:28 -03:00
|
|
|
|
2026-04-10 08:29:45 -03:00
|
|
|
# Check if there are changes to rebuild (check botserver submodule)
|
|
|
|
|
cd /opt/gbo/data/botserver/botserver
|
|
|
|
|
git fetch origin main
|
|
|
|
|
|
2026-04-10 08:36:05 -03:00
|
|
|
# Get current commit and origin/main commit
|
|
|
|
|
CURRENT_COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "")
|
|
|
|
|
ORIGIN_COMMIT=$(git rev-parse origin/main 2>/dev/null || echo "")
|
|
|
|
|
echo "Current commit: $CURRENT_COMMIT"
|
|
|
|
|
echo "Origin commit: $ORIGIN_COMMIT"
|
2026-04-10 08:29:45 -03:00
|
|
|
|
2026-04-10 08:36:05 -03:00
|
|
|
# Compare commits - if different, there are changes to deploy
|
|
|
|
|
if [ "$CURRENT_COMMIT" = "$ORIGIN_COMMIT" ] && [ -f /opt/gbo/data/botserver/target/debug/botserver ]; then
|
|
|
|
|
echo "No changes - already at origin/main and binary exists, skipping build"
|
2026-04-10 08:29:45 -03:00
|
|
|
echo "=== sccache stats ==="
|
|
|
|
|
sccache --show-stats || true
|
|
|
|
|
exit 0
|
2026-04-10 08:17:28 -03:00
|
|
|
fi
|
|
|
|
|
|
2026-04-10 08:36:05 -03:00
|
|
|
echo "Changes detected or no binary - will build"
|
|
|
|
|
|
|
|
|
|
cd /opt/gbo/data/botserver
|
2026-04-09 18:33:53 -03:00
|
|
|
echo "=== Starting build in background ==="
|
|
|
|
|
cargo build -p botserver -j 8 > /tmp/build.log 2>&1 &
|
|
|
|
|
BUILD_PID=$!
|
|
|
|
|
echo "Build PID: $BUILD_PID"
|
|
|
|
|
|
|
|
|
|
echo "=== Waiting for build to complete (PID: $BUILD_PID) ==="
|
|
|
|
|
while kill -0 $BUILD_PID 2>/dev/null; do
|
|
|
|
|
echo "Build in progress... (sleeping 30s)"
|
|
|
|
|
sleep 30
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
wait $BUILD_PID
|
|
|
|
|
EXIT_CODE=$?
|
|
|
|
|
|
|
|
|
|
echo "=== Build finished with exit code: $EXIT_CODE ==="
|
|
|
|
|
|
|
|
|
|
if [ $EXIT_CODE -ne 0 ]; then
|
|
|
|
|
echo "=== Build FAILED ==="
|
|
|
|
|
tail -100 /tmp/build.log
|
|
|
|
|
exit $EXIT_CODE
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "=== sccache stats ==="
|
|
|
|
|
sccache --show-stats
|
|
|
|
|
echo "=== Binary info ==="
|
|
|
|
|
ls -lh target/debug/botserver
|
|
|
|
|
stat -c '%y' target/debug/botserver
|
2025-12-16 22:29:29 -03:00
|
|
|
|
|
|
|
|
- name: Save build log
|
|
|
|
|
if: always()
|
2026-04-03 09:40:16 -03:00
|
|
|
run: cp /tmp/build.log /tmp/botserver-$(date +%Y%m%d-%H%M%S).log || true
|
2025-12-16 13:25:26 -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-03 09:40:16 -03:00
|
|
|
ls -lh /opt/gbo/data/botserver/target/debug/botserver
|
2026-04-05 19:38:54 -03:00
|
|
|
echo "Step 2: Backing up old binary (ignore if not exists)..."
|
|
|
|
|
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..."
|
|
|
|
|
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-03-21 20:47:13 -03:00
|
|
|
|
2026-03-20 19:51:08 -03:00
|
|
|
- name: Save deploy log
|
|
|
|
|
if: always()
|
2026-04-03 09:40:16 -03:00
|
|
|
run: cp /tmp/deploy.log /tmp/deploy-$(date +%Y%m%d-%H%M%S).log || true
|