aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/deploy.yml
blob: 8daf580fb800f4641ebcdc507388ba38b19d266d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Deploy App

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  auto-deploy:
    runs-on: self-hosted

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

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 18

      - name: Install dependencies
        run: bun install

      - name: Generate Prisma
        run: bunx prisma generate || exit

      - name: Build the project
        run: BUILD_DIR=temp bun run build || exit

      - name: Check if temp directory exists
        run: |
          if [ ! -d "temp" ]; then
            echo '\033[31m temp Directory not exists!\033[0m'
            exit 1
          fi

      - name: Remove .next directory
        run: rm -rf .next

      - name: Move temp to .next directory
        run: mv temp .next

      - name: Set PORT
        run: echo "PORT=1000" >> $GITHUB_ENV

      - name: Check if PM2 process exists
        run: |
          if pm2 list | grep -q 'moopa'; then
            echo "PM2 process 'moopa' exists"
          else
            echo "PM2 process 'moopa' does not exist, starting a new process"
          pm2 start bun -n moopa -- start
          fi
          
      - name: Reload PM2
        run: pm2 reload moopa --update-env