-
Notifications
You must be signed in to change notification settings - Fork 6
141 lines (124 loc) · 5.52 KB
/
deploy.yml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Deploy to Production
on:
workflow_dispatch:
inputs:
reason:
description: "Reason for deployment"
required: false
type: string
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- name: Check Dependencies
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Checking dependencies..."
echo "========================"
# Check Node.js
if ! command -v node &> /dev/null; then
echo "Installing Node.js..."
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
fi
# Check Yarn
if ! command -v yarn &> /dev/null; then
echo "Installing Yarn..."
npm install -g yarn
fi
# Check PM2
if ! command -v pm2 &> /dev/null; then
echo "Installing PM2..."
npm install -g pm2
fi
# Check FFmpeg (required for audio processing)
if ! command -v ffmpeg &> /dev/null; then
echo "Installing FFmpeg..."
sudo apt-get update
sudo apt-get install -y ffmpeg
fi
# Check Python (needed for some node-gyp builds)
if ! command -v python3 &> /dev/null; then
echo "Installing Python3..."
sudo apt-get install -y python3
fi
# Check build tools
if ! command -v make &> /dev/null; then
echo "Installing build tools..."
sudo apt-get install -y build-essential
fi
# Check Canvas dependencies
dpkg -l | grep -qw libcairo2-dev || sudo apt-get install -y libcairo2-dev
dpkg -l | grep -qw libpango1.0-dev || sudo apt-get install -y libpango1.0-dev
dpkg -l | grep -qw libjpeg-dev || sudo apt-get install -y libjpeg-dev
dpkg -l | grep -qw libgif-dev || sudo apt-get install -y libgif-dev
dpkg -l | grep -qw librsvg2-dev || sudo apt-get install -y librsvg2-dev
- name: List Current PM2 Processes
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "List of current pm2 processes:"
echo "==============================="
pm2 ls
- name: Stop AxerBot
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Stopping axerbot..."
pm2 stop axerbot || true
- name: Pull Changes & Build
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Pulling the latest changes..."
cd ~/projects/axerbot || { echo "Directory not found"; exit 1; }
git pull
echo "Installing dependencies..."
yarn
echo "Building..."
npx tsc
- name: Start & Verify
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ~/projects/axerbot
echo "Starting axerbot..."
sleep 2
pm2 start axerbot
echo "Success! Showing startup logs for 30 seconds..."
sleep 3
timeout 30 pm2 logs axerbot --lines 50 || true
exit 0
notify:
needs: deploy
runs-on: ubuntu-latest
if: always()
steps:
- name: Send Discord Notification
uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
status: ${{ needs.deploy.result }}
title: "Deployment Status"
description: |
Deployment ${{ needs.deploy.result }}
Reason: ${{ github.event.inputs.reason || 'No reason provided' }}
color: ${{ needs.deploy.result == 'success' && '0x1df27d' || '0xff5050' }}