deploy.yml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. name: Deploy
  2. on:
  3. # 推送时执行
  4. push:
  5. branches: [dev]
  6. # 可手动执行
  7. workflow_dispatch:
  8. jobs:
  9. deploy-web:
  10. runs-on: ubuntu-latest
  11. steps:
  12. # 1、检出源码
  13. - name: Checkout
  14. uses: actions/checkout@master
  15. # 2、安装 PNPM
  16. - name: Setup PNPM
  17. uses: pnpm/action-setup@v2
  18. with:
  19. version: latest
  20. # 3、安装 Node 环境
  21. - name: Setup Node
  22. uses: actions/setup-node@v3
  23. with:
  24. node-version: 18
  25. cache: pnpm
  26. cache-dependency-path: ./pnpm-lock.yaml
  27. # 4、安装依赖
  28. - name: Install Dependencies
  29. run: pnpm i --frozen-lockfile
  30. # 5、打包
  31. - name: Build
  32. run: pnpm build
  33. # 6、拷贝到服务器
  34. - name: Copy
  35. uses: appleboy/scp-action@v0.1.7
  36. with:
  37. host: ${{ secrets.SERVER_HOST }}
  38. port: ${{ secrets.SERVER_PORT }}
  39. username: ${{ secrets.SERVER_USERNAME }}
  40. password: ${{ secrets.SERVER_PASSWORD }}
  41. source: ./dist/*
  42. target: /tmp/html
  43. strip_components: 1
  44. # 7、重启 Nginx
  45. - name: Restart
  46. uses: appleboy/ssh-action@master
  47. with:
  48. host: ${{ secrets.SERVER_HOST }}
  49. port: ${{ secrets.SERVER_PORT }}
  50. username: ${{ secrets.SERVER_USERNAME }}
  51. password: ${{ secrets.SERVER_PASSWORD }}
  52. script: |
  53. rm -rf ${{ secrets.SERVER_PATH }}/*
  54. mv /tmp/html/* ${{ secrets.SERVER_PATH }}
  55. chmod -R 777 ${{ secrets.SERVER_PATH }}