Update README files #33
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 Splitly API to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'api/**' | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| name: Deploy to Production Server | |
| runs-on: ubuntu-latest | |
| # ADD THIS SECTION ⬇️ | |
| permissions: | |
| deployments: write | |
| contents: read | |
| statuses: write | |
| environment: | |
| name: production-api | |
| url: https://splitly.be.khangdev.me | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Start Deployment | |
| uses: bobheadxi/deployments@v1 | |
| id: deployment | |
| with: | |
| step: start | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| env: production-api | |
| ref: ${{ github.sha }} # ADD THIS LINE | |
| - name: Deploy to VPS via SSH | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: 22 | |
| script: | | |
| # Navigate to project directory | |
| cd ~/splitly | |
| # Pull latest changes | |
| git fetch origin | |
| git reset --hard origin/main | |
| # Navigate to API directory | |
| cd ~/splitly/api | |
| # Install all dependencies (including devDependencies for build) | |
| npm install | |
| # Build the project with Babel | |
| npm run build | |
| # Restart PM2 process | |
| if pm2 describe splitly-api > /dev/null 2>&1; then | |
| pm2 restart splitly-api | |
| else | |
| BUILD_MODE=production pm2 start ./build/src/server.js --name splitly-api | |
| fi | |
| # Save PM2 config | |
| pm2 save | |
| # Show status | |
| pm2 status | |
| echo "✅ API Deployment completed successfully!" | |
| - name: Update Deployment Status | |
| uses: bobheadxi/deployments@v1 | |
| if: always() | |
| with: | |
| step: finish | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| status: ${{ job.status }} | |
| env: production-api | |
| deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
| env_url: https://splitly.be.khangdev.me |