Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy Website

on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened

concurrency:
group: deploy-preview
cancel-in-progress: true
Comment on lines 12 to 14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concurrency group should include PR number to prevent different PRs from canceling each other's deployments

Suggested change
concurrency:
group: deploy-preview
cancel-in-progress: true
concurrency:
group: deploy-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true


jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

DEPLOY_DIR=/opt/loglife/preview
APP_NAME=loglife-preview
PORT=3001
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All PRs share the same deploy directory, port, and app name, causing conflicts when multiple PRs are open

Suggested change
DEPLOY_DIR=/opt/loglife/preview
APP_NAME=loglife-preview
PORT=3001
DEPLOY_DIR=/opt/loglife/preview-${{ github.event.pull_request.number }}
APP_NAME=loglife-preview-${{ github.event.pull_request.number }}
PORT=$((3000 + ${{ github.event.pull_request.number }}))

BRANCH=${{ github.head_ref }}

if [ ! -d "$DEPLOY_DIR" ]; then
git clone https://github.com/${{ github.repository }}.git "$DEPLOY_DIR"
fi

cd "$DEPLOY_DIR"
git fetch origin
git checkout "$BRANCH"
git reset --hard "origin/$BRANCH"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git reset --hard will discard any uncommitted changes or failed deployment artifacts without verification


cd website
pnpm install --frozen-lockfile
pnpm run build
Comment on lines +51 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling to prevent starting the server if build fails - consider adding set -e at the start of the script

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


pm2 delete "$APP_NAME" || true
PORT=$PORT pm2 start pnpm --name "$APP_NAME" -- start --port $PORT
pm2 save
Loading