name: Build and Deploy

on:
  push:
    tags:
      - 'v*'

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Deploy to /opt/wled-controller
        run: |
          DEPLOY_DIR=/opt/wled-controller

          # Ensure deploy directory exists
          mkdir -p "$DEPLOY_DIR/data" "$DEPLOY_DIR/logs" "$DEPLOY_DIR/config"

          # Copy server files to deploy directory
          rsync -a --delete \
            --exclude 'data/' \
            --exclude 'logs/' \
            server/ "$DEPLOY_DIR/"

          # Build and restart
          cd "$DEPLOY_DIR"
          docker compose down
          docker compose up -d --build
