Skip to content

Commit

Permalink
feat:添加ci/cd功能
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyangfifa committed Oct 21, 2024
1 parent d884154 commit a3b64a3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# react-workflow

构建 react 工作流

### 支持 ci/cd 上传构建后页面到 github action
* 需要在仓库中的 settings -> pages 页面,设置 Build and deployment 为 GitHub Actions。

0 comments on commit a3b64a3

Please sign in to comment.