Skip to content

Update deploy_test.yml #14

Update deploy_test.yml

Update deploy_test.yml #14

Workflow file for this run

name: πŸš€ Deploy Next.js App
on:
push:
branches: [main]
jobs:
build-and-deploy:
name: πŸŽ‰ Build and Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Checkout Repository
uses: actions/checkout@v4
- name: πŸ›  Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: πŸ“‚ Deploy to Server
uses: appleboy/ssh-action@v1.0.0
env:
NODE_VERSION: 20
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
envs: NODE_VERSION
script: |
# Ensure required tools are in PATH
export PATH=$HOME/.local/bin:$HOME/.npm-global/bin:$PATH
# Install or update nvm if not present
if [ ! -d "$HOME/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
# Install Node.js using nvm
nvm install $NODE_VERSION
nvm use $NODE_VERSION
# Install yarn and pm2 globally
npm install -g yarn pm2
# Navigate to the project directory
cd /home/${{ secrets.SERVER_USER }}/public_html
# Pull the latest code
git pull origin main
# Install dependencies and build
yarn install --frozen-lockfile
yarn build
# Start or restart the Next.js app with PM2
if pm2 describe nextjs-app > /dev/null; then
pm2 reload nextjs-app
else
pm2 start yarn --name "nextjs-app" -- start
fi
# Save the PM2 process list
pm2 save