name: Deploy

# Déclenché à chaque push sur master → build + déploiement automatique.
on:
  push:
    branches: [master]
  workflow_dispatch:

concurrency:
  group: deploy-${{ github.ref }}
  cancel-in-progress: false

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

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Deploy to /var/www/highland + restart PM2
        run: |
          set -e
          mkdir -p /var/www/highland
          rsync -a --delete \
            --exclude='.git' \
            --exclude='.env' \
            --exclude='.env.local' \
            ./ /var/www/highland/
          cd /var/www/highland
          pm2 restart highland --update-env || pm2 start npm --name highland -- start
          pm2 save
