name: CI setup production
on:
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v3
      - uses: oven-sh/setup-bun@v1
      - uses: kielabokkie/ssh-key-and-known-hosts-action@v1
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
          ssh-host: ${{ secrets.DEPLOY_HOST }}
      - name: Install pm2
        run: bun install pm2 -g
        shell: bash
      - name: Deploy using pm2
        run: pm2 deploy ecosystem.config.js production setup
        env:
          # Deploy environment variables 
          DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
          SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
          DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
          # App environment variables
          APP_NAME: ${{ secrets.APP_NAME }}
          SITE_NAME: ${{ secrets.SITE_NAME }}
          PORT: ${{ secrets.PORT }}
          DISCORD_JOIN_WEBHOOK_URL: ${{ secrets.DISCORD_JOIN_WEBHOOK_URL }}
        shell: bash
