Update build.yml

This commit is contained in:
bip production
2025-02-23 11:23:58 +08:00
committed by GitHub
parent 41fbc31194
commit f39f63fe7a

View File

@@ -137,7 +137,82 @@ jobs:
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cat ~/.bashrc
# Source ~/.bashrc
source ~/.bashrc
# Install NVM if not already installed
if [ ! -d "$HOME/.nvm" ]; then
echo "NVM is not installed. Installing now..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc
fi
# Verify NVM installation
if ! command -v nvm &> /dev/null; then
echo "NVM installation failed."
exit 1
fi
# Install Node.js if not already installed
if ! command -v node &> /dev/null; then
echo "Node.js is not installed. Installing now..."
nvm install --lts
nvm use --lts
fi
# Install Bun if not already installed
if ! command -v bun &> /dev/null; then
echo "Bun is not installed. Installing now..."
curl -fsSL https://bun.sh/install | bash
export PATH="$HOME/.bun/bin:$PATH"
fi
# Install PM2 if not already installed
if ! command -v pm2 &> /dev/null; then
echo "PM2 is not installed. Installing now..."
bun install --global pm2
fi
# Install dotenv-cli if not already installed
if ! command -v dotenv &> /dev/null; then
echo "dotenv-cli is not installed. Installing now..."
bun install --global dotenv-cli
fi
# Find an available port
PORT=$(curl -s -X GET https://wibu-bot.wibudev.com/api/find-port | jq -r '.[0]')
if [ -z "$PORT" ] || ! [[ "$PORT" =~ ^[0-9]+$ ]]; then
echo "Invalid or missing port from API."
exit 1
fi
# Deploy to VPS
cd /var/www/projects/${{ env.APP_NAME }}/releases/${{ env.APP_VERSION }}
# Set environment variables
dotenv set DATABASE_URL "postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5433/${{ secrets.POSTGRES_DB }}?schema=public"
dotenv set PORT "$PORT"
dotenv set NEXT_PUBLIC_WIBU_URL "localhost:$PORT"
dotenv set WIBU_UPLOAD_DIR "/var/www/projects/${{ env.APP_NAME }}/uploads"
# Create uploads directory
mkdir -p /var/www/projects/${{ env.APP_NAME }}/uploads
# Install dependencies
bun install --production
# Apply database schema
if ! bun prisma db push; then
echo "Database migration failed."
exit 1
fi
# Seed database (optional)
bun prisma db seed || echo "tidak membutuhkan seed"
# Restart the application
pm2 reload ${{ env.APP_NAME }} || pm2 start "bun run start --port $PORT" --name "${{ env.APP_NAME }}-$PORT" --namespace "${{ env.APP_NAME }}"
# Step 4: Set BUILD_STATUS based on success or failure
- name: Set BUILD_STATUS