Update deploy.yml #4
This file contains 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: Build and Deploy | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest # 构建环境使用 ubuntu | |
steps: | |
- name: Checkout code # 将代码拉到虚拟机 | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18.18.0' | |
- name: Setup pnpm | |
uses: pnpm/[email protected] | |
with: | |
version: 8.12.0 | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build Next.js app | |
run: pnpm build | |
- name: Check pnpm and pm2 installation | |
run: | | |
echo $(which pnpm) | |
echo $(which pm2) | |
- name: Deploy to Custom Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} # 服务器IP或域名 | |
username: ${{ secrets.SERVER_USERNAME }} # 服务器用户名 | |
key: ${{ secrets.SERVER_SSH_KEY }} # 服务器SSH私钥 | |
script: | | |
PNPM_PATH=$(which pnpm) | |
PM2_PATH=$(which pm2) | |
export PATH="$(dirname $PNPM_PATH):$(dirname $PM2_PATH):$PATH" | |
cd /home/project/blog-web | |
git pull origin master | |
pnpm install --production | |
pm2 restart blog-web |