Skip to content

Commit

Permalink
perf: 修改CI代码拉取策略,简化scripts脚本命令 (#54)
Browse files Browse the repository at this point in the history
* perf: 修改CI代码拉取策略,简化scripts脚本命令

* feat: markmap-cli开发环境依赖

---------

Co-authored-by: chu fan <[email protected]>
  • Loading branch information
mmdapl and chu fan authored Oct 10, 2023
1 parent 75acf78 commit 5e1aedb
Show file tree
Hide file tree
Showing 5 changed files with 1,268 additions and 32 deletions.
53 changes: 41 additions & 12 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,28 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0
## 淘宝镜像加速
registry-url: 'https://registry.npmmirror.com'
cache: 'pnpm'

- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Install Dependencies
run: |
pnpm i --frozen-lockfile --registry https://registry.npmmirror.com
- name: Cache Dependencies
uses: actions/cache@v3
Expand All @@ -52,13 +58,16 @@ jobs:
## 部署到Github-Pages
deploy-github:
name: "部署到Github-Pages"
needs: install-init
needs:
- install-init
runs-on: macos-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Restore Dependencies From cache
Expand All @@ -69,6 +78,11 @@ jobs:
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}


## 支持思维导图转化
- name: Build Mark-Map
run: |
./scripts/mark-map
# 运行构建脚本
- name: Build VuePress Site
run: ls -a && ./scripts/bundle build_proxy
Expand All @@ -84,13 +98,16 @@ jobs:
## 部署到vercel平台
deploy-vercel:
name: "部署到Vercel平台"
needs: install-init
needs:
- install-init
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Restore Dependencies From Cache
Expand All @@ -100,6 +117,11 @@ jobs:
node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}

## 支持思维导图转化
- name: Build Mark-Map
run: |
./scripts/mark-map
- name: Pull Vercel Environment Information
run: vercel -v && vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

Expand All @@ -114,17 +136,24 @@ jobs:
release:
name: "创建Github发布"
runs-on: macos-latest
needs: install-init
needs:
- install-init
## 主库master、next且执行release更新时执行
if: github.repository == '142vip/408CSFamily' && startsWith(github.event.head_commit.message, 'chore(release):')

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

## 支持思维导图转化
- name: Build Mark-Map
run: |
./scripts/mark-map
### 打成压缩包
- name: Create Zip Package
run: |
Expand Down
55 changes: 39 additions & 16 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
## 代码CI快速集成流水线,lint、fix、build


name: CI
## 触发条件
on:
# 提PR到next分支触发CI
pull_request:
branches:
- 'master'
- 'next'
- '!pages/**'
- next
push:
branches:
- master
Expand All @@ -28,9 +26,10 @@ jobs:
pull-requests: read

steps:
- name: checkout code
uses: actions/checkout@v3
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

Expand All @@ -43,24 +42,31 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18.18.0
## 淘宝镜像加速
registry-url: 'https://registry.npmmirror.com'
cache: 'pnpm'

- name: Install Dependencies
run: pnpm i --frozen-lockfile --registry https://registry.npmmirror.com
run: |
pnpm i --frozen-lockfile --registry https://registry.npmmirror.com
- name: Cache Dependencies
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}

Base-Build:
name: "基础编译构建"
runs-on: macos-latest
needs: install-init
needs:
- install-init
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Restore Dependencies From Cache
Expand All @@ -70,18 +76,27 @@ jobs:
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Code LintFix
run: ./scripts/lint --fix
run: |
./scripts/lint --fix
## 支持思维导图转化
- name: Build Mark-Map
run: |
./scripts/mark-map
- name: Build Site
run: ./scripts/bundle build
run: |
./scripts/bundle build
- name: Build Site With Proxy
run: ./scripts/bundle build_proxy
run: |
./scripts/bundle build_proxy
Build-Docker-Image:
name: "构建Docker镜像"
runs-on: macos-latest
needs: install-init
needs:
- install-init
## 主库且tag更新时执行
if: github.repository == '142vip/408CSFamily' && startsWith(github.ref, 'refs/tags/v')
permissions:
Expand All @@ -90,8 +105,9 @@ jobs:

steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

Expand All @@ -110,10 +126,17 @@ jobs:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}

## 支持思维导图转化
- name: Build Mark-Map
run: |
./scripts/mark-map
## 构建,支持domain
- name: Build To Dist
run: ./scripts/bundle build_proxy
run: |
./scripts/bundle build_proxy
## 快速构建并推送
- name: Push Docker Image
run: ./scripts/bundle image_faster
run: |
./scripts/bundle image_faster
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
},
"scripts": {
"preinstall": "chmod +x ./scripts/*",
"postinstall": "npm run build:mark-map",
"prepare": "rm -f .husky/pre-commit && husky install && npx husky add .husky/pre-commit \"./scripts/lint --fix\" && chmod +x .husky/pre-commit",
"dev": "vuepress dev docs",
"build": "./scripts/bundle build && npm run build:mark-map",
"build:mark-map": "./scripts/mark-map",
"build": "./scripts/bundle build ",
"build:proxy": "./scripts/bundle build_proxy",
"build:mark-map": "./scripts/mark-map",
"deploy:vercel": "vercel --prod",
"clean": "find . -name \"node_modules\" -type d -exec rm -rf '{}' + "
},
"scripts-info": {
"preinstall": "在安装依赖前分配脚本权限",
"postinstall": "在安装依赖后编译markdown文档转化为思维导图",
"prepare": "安装依赖预执行脚本",
"build:mark-map": "./scripts/mark-map",
"dev": "本地启动项目",
Expand All @@ -44,6 +46,7 @@
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.17.0",
"husky": "^8.0.3",
"markmap-cli": "^0.15.4",
"shelljs": "^0.8.5",
"typescript": "^3.9.10",
"vercel": "^32.4.1",
Expand Down
Loading

0 comments on commit 5e1aedb

Please sign in to comment.