name: Build and Deploy NPM Project to Webserver via SSH

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: docker

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '22'

      - name: Install Dependencies
        run: npm install

      - name: Build Project
        run: npm run build

      - name: Deploy via SCP
        run: |
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key
          chmod 600 private_key

          echo "Deploying via SCP..."
          scp -o StrictHostKeyChecking=no -i private_key -r public/* ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:/mnt/user/appdata/sebin-blog/www

          rm -f private_key
