name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: docker

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

      - name: Set up SSH
        run: |
          mkdir -p ~/.ssh/
          echo "${{ secrets.SSH_KEY }}" > ./deploy.key
          chmod 600 ./deploy.key
          echo "${{ secrets.SSH_KNOWN_HOSTS }}" > ~/.ssh/known_hosts

      - name: Install PM2
        run: npm i -g pm2

      - name: Deploy
        run: pm2 deploy ecosystem.config.cjs production
