Skip to content

Deploy to Production #9

Deploy to Production

Deploy to Production #9

Workflow file for this run

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 "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' }}