name: Production deploy on: push: branches: - main jobs: build: runs-on: host steps: - name: Ensure Node.js (install if missing) run: | if ! command -v node >/dev/null 2>&1; then echo "Node.js not found, installing..." curl -fsSL https://deb.nodesource.com/setup_20.x | bash - apt-get install -y nodejs else echo "Node.js already installed: $(node -v)" fi - name: Clone repository run: | set -e REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" echo "Cloning repo from: ${REPO_URL}" rm -rf repo git clone "${REPO_URL}" repo - name: Copy backend to /data/wildgrowth/weizhuozhongzhi-ai run: | set -e cd repo mkdir -p /data/wildgrowth/backend rm -rf /data/wildgrowth/backend/* cp -r backend/* /data/wildgrowth/backend/ - name: create env file run: | set -e cd /data/wildgrowth/backend cp env.online .env - name: npm install and prisma run: | set -e cd /data/wildgrowth/backend npm install npm run prisma:generate npm run prisma:migrate:deploy - name: Build backend run: | set -e cd /data/wildgrowth/backend npm run build - name: Start or reload with pm2 run: | set -e cd /data/wildgrowth/backend if pm2 describe wildgrowth >/dev/null 2>&1; then pm2 reload wildgrowth else pm2 start ./dist/index.js --name "wildgrowth" fi