Skip to content

Merge pull request #14 from nuon-dev/main #56

Merge pull request #14 from nuon-dev/main

Merge pull request #14 from nuon-dev/main #56

Workflow file for this run

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: deploy
on:
push:
branches: [deploy]
jobs:
build:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- name: deploy-server
uses: milanmk/actions-file-deployer@master
with:
remote-protocol: sftp
remote-host: ${{ secrets.SERVER_HOST }}
remote-user: ${{ secrets.SERVER_USER }}
remote-password: ${{ secrets.SERVER_PASSWORD }}
remote-path: /home/nuon
remote-port: 22
local-path: ./server
sync: full
- name: npm install client
working-directory: client
run: npm install
- name: npm install server
working-directory: server
run: npm install
- name: client build
env:
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
working-directory: client
run: npm run build
- name: deploy-client
uses: milanmk/actions-file-deployer@master
with:
remote-protocol: sftp
remote-host: ${{ secrets.SERVER_HOST }}
remote-user: ${{ secrets.SERVER_USER }}
remote-password: ${{ secrets.SERVER_PASSWORD }}
remote-path: /var/www/nuon
remote-port: 22
local-path: client/out
sync: full
- name: Restart API with PM2
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
port: 22
debug: true
script: |
set -e
echo "=== Starting server restart process ==="
cd /home/nuon
echo "Current directory: $(pwd)"
echo "=== Installing dependencies ==="
npm install
echo "=== Checking environment files ==="
ls -la .env* || echo "No .env files found"
echo "=== Checking for pending migrations ==="
MIGRATION_STATUS=$(npm run migration:check --silent)
echo "Migration status: $MIGRATION_STATUS"
if [ "$MIGRATION_STATUS" = "pending" ]; then
echo "=== Creating database backup before migration ==="
npm run db:backup
echo "✅ Database backup completed successfully"
echo "=== Running database migrations ==="
npm run migration:run
echo "✅ Database migrations completed successfully"
else
echo "✅ No pending migrations, skipping backup and migration"
fi
echo "=== Current PM2 processes ==="
pm2 list || echo "PM2 list failed"
echo "=== Reloading nuon process ==="
pm2 reload nuon || pm2 start npm --name "nuon" -- start
echo "=== Final PM2 processes ==="
pm2 list
echo "=== PM2 logs (last 10 lines) ==="
timeout 10s pm2 logs nuon --lines 10 || echo "Could not fetch logs or timeout"
echo "=== Server restart completed ==="