name: Build and Deploy DAVE | DMGs Site

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    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: '18'

      - name: Install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 8

      - name: Cache pnpm store
        uses: actions/cache@v4
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: Disable Next.js telemetry
        run: npx next telemetry disable

      - name: Install dependencies
        run: pnpm install --no-frozen-lockfile

      - name: Build and deploy
        run: |
          mv src/app/\(cms\) src/app/_cms
          pnpm run build
          rm -rf /var/www/sites/dave-dmg/blog/*
          cp -r out/* /var/www/sites/dave-dmg/blog/