Skip to content

Merge pull request #52 from splitly25/deploy2 #1

Merge pull request #52 from splitly25/deploy2

Merge pull request #52 from splitly25/deploy2 #1

Workflow file for this run

name: Deploy Splitly Web to VPS
on:
push:
branches:
- main
paths:
- 'web/**'
workflow_dispatch:
jobs:
deploy:
name: Deploy Web to Production Server
runs-on: ubuntu-latest
permissions:
deployments: write
contents: read
statuses: write
environment:
name: production-web
url: https://splitly.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-web
ref: ${{ github.sha }}
- name: Deploy Web 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/web
# Pull latest changes
git pull origin main
# Install dependencies
npm install
# Build the project
npm run build
# Copy built files to nginx directory
sudo cp -r dist/* /var/www/splitly/
sudo chown -R www-data:www-data /var/www/splitly
# Restart PM2 web process (with fallback if process doesn't exist)
pm2 restart splitly-web || pm2 start npm --name "splitly-web" -- run preview -- --port 3001
# Save PM2 config
pm2 save
# Show status
pm2 status
# Test nginx configuration and reload
sudo nginx -t && sudo systemctl reload nginx
echo "✅ Web 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-web
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: https://splitly.khangdev.me