Skip to content

chore: upgrade model #150

chore: upgrade model

chore: upgrade model #150

Workflow file for this run

name: 🚀 Build & Deploy
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy:
# Use self-hosted runner if available, fallback to GitHub-hosted otherwise
runs-on: [self-hosted, linux, x64]
environment:
name: production
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🟩 Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: 💾 Restore pnpm cache
uses: actions/cache@v4
with:
path: |
~/.local/share/pnpm/store/v3
node_modules
*/node_modules
key: deps-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
deps-${{ runner.os }}-
- name: 📦 Install dependencies
uses: pnpm/action-setup@v4
with:
version: 10
run_install: |
- recursive: true
args: [--frozen-lockfile, --prefer-offline]
- name: 🧪 Run backend tests
run: |
echo "🧪 Running backend test suite with coverage..."
COVERAGE_REPORTERS=text pnpm --filter backend test:coverage
echo "✅ All backend tests passed with coverage!"
continue-on-error: false
- name: 🏗️ Build frontend
run: pnpm build:frontend
env:
VITE_TURNSTILE_SITE_KEY: ${{ secrets.VITE_TURNSTILE_SITE_KEY }}
- name: 🚀 Deploy backend
run: |
BACKEND_PATH="${{ secrets.BACKEND_PATH }}"
echo "📤 Copying backend files to $BACKEND_PATH ..."
mkdir -p "$BACKEND_PATH"
rsync -az --delete --exclude 'node_modules' --exclude '.git' --exclude '__tests__' --exclude 'coverage' --exclude 'lcov-report' backend/ "$BACKEND_PATH/"
echo "🔑 Setting up environment variables..."
cat > "$BACKEND_PATH/.env" << 'ENVEOF'
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
TURNSTILE_SECRET_KEY=${{ secrets.TURNSTILE_SECRET_KEY }}
PORT=5000
NODE_ENV=production
ENVEOF
chmod 600 "$BACKEND_PATH/.env"
echo "📦 Installing backend dependencies..."
cd "$BACKEND_PATH"
pnpm install --prod
echo "🛑 Stopping all existing PM2 processes (if any)..."
pm2 stop all || true
pm2 delete all || true
echo "🚀 Starting backend with PM2..."
pm2 start index.js --name "stackconverter-backend" -f
pm2 save
echo "✅ Deployment completed successfully!"
echo "🔧 Backend: http://localhost:5000"
- name: 🚀 Deploy frontend
run: |
FRONTEND_PATH="${{ secrets.FRONTEND_PATH }}"
echo "📤 Copying frontend build to $FRONTEND_PATH ..."
mkdir -p "$FRONTEND_PATH"
rsync -az --delete frontend/dist/ "$FRONTEND_PATH/"
- name: ✅ Run health check
run: |
echo "🔍 Checking PM2 status and backend health..."
pm2 status | grep stackconverter-backend
curl -s http://localhost:5000/ > /dev/null && echo "✅ Backend healthy" || echo "❌ Backend not responding"
ls -la "${{ secrets.FRONTEND_PATH }}"
ls -la "${{ secrets.BACKEND_PATH }}"
echo "🎉 Deployment Summary:"
echo "✅ Frontend: https://amiroff.me/stackconverter/"
echo "✅ Backend: http://localhost:5000"
echo "✅ PM2 managing backend process"
echo "✅ Environment variables configured"
echo ""
echo "📝 Next steps:"
echo "1. Test the application at https://amiroff.me/stackconverter/"
echo "2. Check PM2 logs: pm2 logs stackconverter-backend"
echo "3. Monitor with: pm2 monit"