Update deploy.yml #8
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@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
version: 8 | |
- 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: Install pm2 | |
run: | | |
npm install -g pm2 | |
- 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 }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_SSH_KEY }} | |
script: | | |
bash -l {0} | |
cd /home/project/blog-web | |
git pull origin master | |
pnpm install --production | |
/opt/hostedtoolcache/node/18.18.0/x64/bin/pm2 restart blog-web | |