name: Deploy site

on:
  push:
    branches: [ main ]

  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 'latest'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Test
        run: npm run test 

      - name: "Deploy"
        uses: milanmk/actions-file-deployer@master
        with:
          remote-protocol: "sftp"
          remote-host: ${{ secrets.SFTP_HOST }}
          remote-user: ${{ secrets.SFTP_USERNAME }}
          remote-password: ${{ secrets.SFTP_PASSWORD }}
          remote-path: "/root/www-aaronjy-me/"