name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: docker

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Use Node.js 19
        uses: actions/setup-node@v4
        with:
          node-version: 19

      - name: Install rsync
        run: |
          apt-get update
          apt-get install -y rsync

      - name: Install dependencies
        run: npm install

      - name: Build app
        run: npm run build

      - name: Add Deploy Key to SSH
        run: |
          mkdir ~/.ssh
          echo "${{ secrets.SSH_KEY }}" >> ~/.ssh/id_ed25519_embroideryviewer
          chmod 400 ~/.ssh/id_ed25519_embroideryviewer
          echo -e "Host embroideryviewer\n\tUser embroideryviewer\n\tHostname 45.76.5.44\n\tIdentityFile ~/.ssh/id_ed25519_embroideryviewer\n\tStrictHostKeyChecking No" >> ~/.ssh/config

      - name: Upload changes to server
        run: rsync -avz --progress dist/ embroideryviewer:web/prod