Skip to content

chore(ci): pr preview #2

chore(ci): pr preview

chore(ci): pr preview #2

name: PR Server Deploy
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- apps/server/**
jobs:
server-deploy:
runs-on: ubuntu-latest
environment: ${{ github.ref == 'refs/heads/master' && 'production' || 'development' }}
steps:
- uses: actions/checkout@v4
- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Deploy to Server
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
PORT=$((8000 + PR_NUMBER))
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST <<EOF
mkdir -p $DEPLOY_DIR/pr-$PR_NUMBER
cd $DEPLOY_DIR/pr-$PR_NUMBER
# Clone or pull the latest code
if [ ! -d .git ]; then
git clone -b ${{ github.event.pull_request.head.ref }} https://github.com/${{ github.repository }}.git .
else
git pull origin ${{ github.event.pull_request.head.ref }}
fi
cd apps/server
cat > .env <<EOL
PORT=$PORT
DB_URL=${{ secrets.DB_URL }}
nodemailer_host=smtp.163.com
[email protected]
nodemailer_auth_pass=${{ secrets.NODEMAILER_AUTH_PASS }}
jwt_secret=agshddgfsd
REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}
REDIS_URL=redis-13502.c261.us-east-1-4.ec2.redns.redis-cloud.com
EOL
cd ../..
# Start container with dynamic port
docker compose down
SERVER_PORT=$PORT NODE_ENV=dev docker compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build
EOF
env:
DEPLOY_DIR: ${{ secrets.DEPLOY_DIR }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}