diff --git a/.forgejo/workflows/botserver.yaml b/.forgejo/workflows/botserver.yaml index 53686f14..f1328310 100644 --- a/.forgejo/workflows/botserver.yaml +++ b/.forgejo/workflows/botserver.yaml @@ -10,8 +10,8 @@ env: CARGO_BUILD_JOBS: 8 CARGO_NET_RETRY: 10 RUSTC_WRAPPER: sccache - WORKSPACE: /home/gbuser/workspace - CARGO_TARGET_DIR: /home/gbuser/target + WORKSPACE: /opt/gbo/data/botserver + CARGO_TARGET_DIR: /opt/gbo/data/botserver/target 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 jobs: @@ -24,21 +24,34 @@ jobs: git config --global http.sslVerify false git config --global --add safe.directory "*" - - name: Clean and Clone Fresh + - name: Setup Workspace run: | + mkdir -p $WORKSPACE cd $WORKSPACE - rm -rf gb-ws - git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/gb.git gb-ws - cd gb-ws - git submodule update --init --recursive - mkdir -p /home/gbuser/target - - - name: Cache sccache - uses: actions/cache@v4 - with: - path: ~/.cache/sccache - key: sccache-botserver-${{ github.sha }} - restore-keys: sccache-botserver- + # Update or clone botlib (preserve git history for sccache fingerprints) + if [ -d botlib/.git ]; then + git -C botlib pull origin main + else + git clone --branch main https://alm.pragmatismo.com.br/GeneralBots/botlib.git botlib + fi + # 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 - name: Install system dependencies run: | @@ -55,21 +68,23 @@ jobs: fi - name: Build BotServer - working-directory: /home/gbuser/workspace/gb-ws + working-directory: /opt/gbo/data/botserver run: | - set -e - # Kill any stuck cargo processes - pkill -9 cargo 2>/dev/null || true - pkill -9 rustc 2>/dev/null || true - rm -f target/.cargo-lock 2>/dev/null || true - export SCCACHE_IDLE_TIMEOUT=300 export SCCACHE_CACHE_SIZE=10G sccache --stop-server 2>/dev/null || true + sleep 1 sccache --start-server + 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 - # Build will use existing /home/gbuser/target for incremental compilation - cargo build -p botserver -j 8 + - name: Save build log + if: always() + run: cp /tmp/build.log /tmp/botserver$(date +%Y%m%d-%H%M%S).log || true - name: Deploy via ssh tar gzip run: | @@ -77,13 +92,13 @@ jobs: SSH_ARGS="-i /home/gbuser/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o ServerAliveInterval=5 -o ServerAliveCountMax=2 -o BatchMode=yes" echo "=== Deploy started ===" echo "Step 1: Checking binary..." - ls -lh /home/gbuser/target/debug/botserver + ls -lh /opt/gbo/data/botserver/target/debug/botserver echo "Step 2: Backing up old binary..." ssh $SSH_ARGS system "cp /opt/gbo/bin/botserver /tmp/botserver.bak 2>/dev/null || true" echo "Step 3: Stopping botserver service..." ssh $SSH_ARGS system "sudo systemctl stop botserver || true" echo "Step 4: Transferring new binary..." - tar cf - -C /home/gbuser/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'" + 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'" echo "Step 5: Starting botserver service..." ssh $SSH_ARGS system "sudo systemctl start botserver && echo 'Botserver started'" echo "=== Deploy completed ===" @@ -93,3 +108,7 @@ jobs: 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" ssh $SSH_ARGS system "pgrep -f botserver >/dev/null && echo 'OK: botserver is running' || echo 'WARNING: botserver may still be starting'" + + - name: Save deploy log + if: always() + run: cp /tmp/deploy.log /tmp/deploy$(date +%Y%m%d-%H%M%S).log || true