From 22a273f515916b6087496fc0f4420d120d7727af Mon Sep 17 00:00:00 2001 From: xygodcyx <109750146+xygodcyx@users.noreply.github.com> Date: Tue, 21 May 2024 20:37:29 +0800 Subject: [PATCH] Auto Upload.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 自动打包vue项目和运行nodejs服务器 目录格式最好为: ./client ./server --- .github/workflows/main.yml | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..39b3d1de --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,51 @@ +name: Full Stack Deployment + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # 前端构建步骤 + - name: Build Vue App + working-directory: ./client + run: | + npm install + npm run build + env: + NODE_ENV: production + + # 缓存前端构建依赖 + - name: Cache frontend dependencies + uses: actions/cache@v2 + with: + path: client/node_modules + key: ${{ runner.os }}-frontend-${{ hashFiles('client/package-lock.json') }} + + # 复制前端构建结果到后端的public目录 + - name: Copy frontend build output to server + run: cp -r ./client/dist ./server/public + + # 后端构建步骤 + - name: Build and start Node.js server + working-directory: ./server + run: | + npm install + npm run build + npm start & + env: + NODE_ENV: production + + # 缓存后端构建依赖 + - name: Cache backend dependencies + uses: actions/cache@v2 + with: + path: server/node_modules + key: ${{ runner.os }}-backend-${{ hashFiles('server/package-lock.json') }}