Deploy latest version of ObserverX to SSH server. #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to SSH server on push | |
run-name: Deploy latest version of ObserverX to SSH server. | |
on: [push] | |
jobs: | |
Deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Run CI deploy script | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.DEPLOY_HOST }} | |
username: ${{ secrets.DEPLOY_USERNAME }} | |
password: ${{ secrets.DEPLOY_PASSWORD }} | |
port: ${{ secrets.DEPLOY_PORT }} | |
script: | | |
source ~/.bashrc | |
export PNPM_HOME="~/.local/share/pnpm" | |
case ":$PATH:" in | |
*":$PNPM_HOME:"*) ;; | |
*) export PATH="$PNPM_HOME:$PATH" ;; | |
esac | |
export NVM_DIR=~/.nvm | |
source ~/.nvm/nvm.sh | |
echo "[INFO] ObserverX server CI script running with PID $$" | |
script_home=$(realpath ~/projects/observerx-panel/) | |
export script_home | |
kill -9 `cat "$script_home/nohup_pid.txt"` | |
rm "$script_home/nohup_pid.txt" | |
echo "[INFO] Killed existing CI processes." | |
echo ${{ secrets.DEPLOY_PASSWORD }} | sudo -S lsof -i:443 | grep node | awk '{print $2}' | xargs kill -9 | |
old_version=$(pnpm list -g @observerx/panel-server | grep @observerx/panel-server | awk '{print $2}') | |
latest_version=$(npm view @observerx/panel-server version) | |
if [ $old_version == $latest_version ] | |
then | |
echo "[INFO] Package already at latest version ($latest_version), skipping update." | |
else | |
echo "[INFO] Installing latest packages..." | |
pnpm add -g @observerx/panel-server@latest | |
new_version=$(pnpm list -g @observerx/panel-server | grep @observerx/panel-server | awk '{print $2}') | |
echo "[INFO] Installed latest packages: $old_version -> $new_version" | |
fi | |
echo "[INFO] Starting server..." | |
cd ~/projects/observerx-panel | |
nohup bash -c "echo \"Starting with PID $$\"; until observerx-admin start; do echo \"Server crashed with exit code $?. Respawning..\" >&2; sleep 10; done" > "$script_home/observerx.log" 2>&1 & | |
echo $! > "$script_home/nohup_pid.txt" | |
echo "[INFO] Server Started." |