fix error workflow(2) #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🚀 Deploy Next.js to cPanel via SSH | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 🧭 Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: 🟢 Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: 📦 Install Dependencies | |
| run: npm ci | |
| - name: 🏗️ Build Next.js App | |
| run: npm run build | |
| - name: 🔍 List files after build | |
| run: ls -la && ls -la .next | |
| - name: 📤 Upload build files to server | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.SSH_PASSPHRASE }} | |
| source: | | |
| .next | |
| public | |
| package.json | |
| app.js | |
| target: ${{ secrets.DEPLOY_DIR }} | |
| overwrite: true | |
| - name: ⚙️ Restart Node.js App on cPanel | |
| uses: appleboy/ssh-action@v1.2.0 | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.SSH_PASSPHRASE }} | |
| script: | | |
| echo "🔧 Activating Node.js environment..." | |
| ${{ secrets.NODE_ENV_PATH }} | |
| echo "📦 Installing production dependencies..." | |
| npm ci --omit=dev | |
| echo "♻️ Restarting Node.js app..." | |
| touch tmp/restart.txt || true | |
| echo "✅ Deployment complete!" |