From a3b64a36ac59c395a601b4b1c1ee64735a75dbf4 Mon Sep 17 00:00:00 2001 From: fengyangfifa <2314034614@qq.com> Date: Mon, 21 Oct 2024 22:53:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=B7=BB=E5=8A=A0ci/cd=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd.yml | 54 +++++++++++++++++++++++++++++++++++++ README.md | 3 +++ 2 files changed, 57 insertions(+) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..139a2b1 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,54 @@ +name: ci/cd for deployment + +run-name: ${{ github.actor }} are tigger ci/cd action + +on: + push: + branches: ["main"] + +# 必须添加下列权限 +permissions: + contents: read + pages: write + id-token: write + +# 限制并发,当触发新的工作流时,取消之前的工作流 +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout repo code + uses: actions/checkout@v4 + - name: set node version + uses: actions/setup-node@v4 + with: + node-version: "20" + - name: Cache node modules + id: cache-npm + # 缓存node_modules + uses: actions/cache@v4 + with: + path: './node_modules' + key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} + # 命中缓存就跳过安装依赖 + - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} + name: install dependencies + run: npm install + - name: build project + run: npm run build + - name: upload build file + uses: actions/upload-pages-artifact@v3 + with: + # 指定上传文件夹 + path: './dist' + + deploy: + runs-on: ubuntu-latest + needs: build + steps: + - name: deploy to github pages + uses: actions/deploy-pages@v4 diff --git a/README.md b/README.md index 07bcdf5..92f185e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # react-workflow 构建 react 工作流 + +### 支持 ci/cd 上传构建后页面到 github action +* 需要在仓库中的 settings -> pages 页面,设置 Build and deployment 为 GitHub Actions。