name: Deploy

on:
  push:
    branches: [main]

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

      - uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Build frontend
        run: cd client && npm ci && npm run build

      - name: Deploy to app directory
        run: |
          rsync -a --delete client/dist/ /opt/apps/marketing-app/client/dist/
          rsync -a server/ /opt/apps/marketing-app/server/ --exclude node_modules --exclude '*.db' --exclude uploads --exclude .env

      - name: Install production deps
        run: cd /opt/apps/marketing-app/server && npm ci --production

      - name: Restart service
        run: sudo systemctl restart marketing-app
