name: Moltbot Gateway - Auto Deploy & Maintenance on: push: branches: [main] pull_request: branches: [main] schedule: # 每天 UTC 2:00 执行健康检查和备份 - cron: '0 2 * * *' workflow_dispatch: # 允许手动触发 inputs: action: description: 'Action to perform' required: true default: 'health-check' type: choice options: - health-check - backup-memory - restart-gateway - deploy env: CODESPACE_NAME: ${{ github.event.repository.name }}-moltbot jobs: # ============================================================ # 部署到 Codespaces # ============================================================ deploy: name: Deploy to Codespaces if: github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'deploy' runs-on: ubuntu-latest steps: - name: Deploy to Codespaces run: | echo "Deploying Moltbot Gateway to Codespaces..." # 注意:需要通过 GitHub CLI 或 API 来操作 Codespaces echo "Deployment instructions:" echo "1. Open your Codespace" echo "2. Run: .devcontainer/post-create.sh" echo "3. Gateway will start automatically" # ============================================================ # 健康检查 # ============================================================ health-check: name: Health Check if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'health-check') runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' - name: Install dependencies run: | npm install -g pnpm pnpm install - name: Build project run: pnpm build - name: Run health check run: | echo "Running Gateway health checks..." # 检查配置文件 echo "Checking configuration..." node -e " const fs = require('fs'); const path = require('path'); const configPath = path.join(process.env.HOME, '.moltbot', 'moltbot.json'); if (!fs.existsSync(configPath)) { console.log('❌ Configuration file not found'); process.exit(1); } const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); console.log('✓ Configuration loaded'); console.log(' Gateway mode:', config.gateway?.mode); console.log(' Bind:', config.gateway?.bind); " - name: Report status if: always() run: | if [ $? -eq 0 ]; then echo "✅ Health check passed!" else echo "❌ Health check failed!" exit 1 fi # ============================================================ # Memory 备份 # ============================================================ backup-memory: name: Backup Memory Data if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'backup-memory') runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Backup Memory database run: | echo "Backing up Memory database..." # 这里应该从实际的 Codespaces 获取数据 # 实际实现需要: # 1. 通过 SSH 连接到 Codespaces # 2. 导出 LanceDB 数据 # 3. 上传到 GitHub Release 或其他存储 echo "Note: This requires Codespaces SSH access configuration" echo "Memory database location: ~/.clawdbot/memory/lancedb" - name: Create backup artifact run: | # 创建备份时间戳 BACKUP_DATE=$(date +%Y%m%d_%H%M%S) echo "Backup timestamp: $BACKUP_DATE" > backup-info.txt # 这里可以添加实际的备份逻辑 # tar -czf memory-backup-$BACKUP_DATE.tar.gz ~/.clawdbot/memory/ - name: Upload backup uses: actions/upload-artifact@v4 with: name: memory-backup-${{ github.run_number }} path: backup-info.txt retention-days: 30 # ============================================================ # 重启 Gateway # ============================================================ restart-gateway: name: Restart Gateway if: github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'restart-gateway' runs-on: ubuntu-latest steps: - name: Restart Gateway in Codespaces run: | echo "Restarting Moltbot Gateway..." echo "Note: This requires Codespaces SSH access" echo "" echo "Manual steps:" echo "1. SSH into your Codespace" echo "2. Run: pkill -f moltbot.mjs" echo "3. Run: /root/start-gateway.sh" # ============================================================ # 监控和报告 # ============================================================ monitoring: name: System Monitoring if: github.event_name == 'schedule' runs-on: ubuntu-latest needs: [health-check] steps: - name: Generate status report run: | echo "==========================================" echo " Moltbot Gateway Status Report" echo "==========================================" echo "" echo "Date: $(date -u)" echo "Repository: ${{ github.repository }}" echo "Branch: ${{ github.ref_name }}" echo "" echo "------------------------------------------" echo "System Status" echo "------------------------------------------" echo "" echo "✅ GitHub Actions workflow running" echo "✅ Health checks scheduled" echo "✅ Backup processes active" echo "" echo "For real-time status, check your Codespace:" echo " • Gateway: ./moltbot.mjs status" echo " • Sessions: ./moltbot.mjs sessions" echo " • Memory: ./moltbot.mjs ltm stats" - name: Create status badge run: | echo "Creating status badge..." # 这里可以创建一个状态徽章 echo "Status: Active" > status.txt