Skip to content

Commit

Permalink
perf(CI): 简化流水线校验流程
Browse files Browse the repository at this point in the history
  • Loading branch information
142vip.cn committed Oct 27, 2023
1 parent f9f1702 commit 30007d8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 63 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ name: CD
on:
push:
branches:
- master
- next
workflow_dispatch:

Expand All @@ -35,20 +34,21 @@ jobs:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

# ## 依赖下载完成后,或执行思维导图编译
# - name: PNPM Install
# uses: pnpm/action-setup@v2
# with:
# version: 7
# run_install: |
# args: [--frozen-lockfile, --registry=https://registry.npmmirror.com]
# 安装Node环境
## 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 8

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

- name: Install Dependencies
run: |
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
release:
name: "创建Github发布"
runs-on: ubuntu-latest
## 主库master、next且执行release更新时执行
## 主库next且执行release更新时执行
if: github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')

steps:
Expand Down
77 changes: 26 additions & 51 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
name: CI
## 触发条件
on:
# 提PR到next分支触发CI
pull_request:
branches:
- 'master'
- 'next'
- '!pages/**'
- next
push:
branches:
- master
- next

# 手动触发部署
workflow_dispatch:

Expand All @@ -27,10 +26,10 @@ env:
UserName: 142vip

jobs:
install-init:
name: "流水线初始化"
Base-Build:
name: "基础编译构建"
runs-on: ubuntu-latest
if: github.repository == '142vip/JavaScriptCollection'
if: github.repository == '142vip/JavaScriptCollection' && github.event_name == 'pull_request'
permissions:
actions: read
pull-requests: read
Expand All @@ -43,51 +42,27 @@ jobs:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

# ## 依赖下载完成后,或执行思维导图编译
# - name: PNPM Install
# uses: pnpm/action-setup@v2
# with:
# version: 7
# run_install: |
# args: [--frozen-lockfile, --registry=https://registry.npmmirror.com]
# 安装Node环境
## 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v2
with:
version: 8

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

## 下载依赖,并执行初始化脚本:钩子函数、思维导图构建
- name: Install Dependencies
run: |
./scripts/ci
- 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: ubuntu-latest
if: github.repository == '142vip/JavaScriptCollection'
needs:
- install-init
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Restore Dependencies From Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Code LintFix
run: |
./scripts/lint --fix
Expand All @@ -100,12 +75,11 @@ jobs:
run: |
./scripts/bundle build_proxy
Build-Docker-Image:
name: "构建Docker镜像"
## macos不支持docker的使用
runs-on: ubuntu-latest
needs:
- install-init
## 主库master、next且执行release更新时执行
if: github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')
permissions:
Expand All @@ -119,7 +93,10 @@ jobs:
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0

- name: Set up Docker
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login Docker
Expand All @@ -131,19 +108,17 @@ jobs:
--password=${{ secrets.DOCKER_PASSWORD }} \
${{env.REGISTRY}}
- name: Restore Dependencies From Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install Dependencies
run: |
./scripts/ci
## 构建,支持domain
- name: Build To Dist
run: |
./scripts/bundle build_proxy
./scripts/bundle build
## 快速构建并推送
- name: Push Docker Image
run: |
./scripts/bundle image_faster
./scripts/bundle image_faster
40 changes: 38 additions & 2 deletions scripts/ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
#!/bin/bash
##
## 依赖安装脚本
## 使用:
## ./scripts/ci
##

# 期望的 pnpm 大版本号
majorVersionRequired="8"

# 检测 pnpm 是否已安装并且大版本号符合要求
checkPNPMVersion() {
local pnpmVersionInstalled=$(pnpm --version 2>/dev/null) # 获取已安装的 pnpm 版本
if [[ $pnpmVersionInstalled =~ ^$majorVersionRequired ]]; then
echo "已安装的 pnpm 版本:$pnpmVersionInstalled"
echo "已安装的 pnpm 大版本号符合要求."
return 0
else
echo "未安装 pnpm 或 pnpm 大版本号不符合要求."
return 1
fi
}

# 安装pnpm
installRequiredPNPM(){
npm i pnpm@$majorVersionRequired -g
}


## 判断是PNPM安装且版本符合要求
if command -v pnpm &> /dev/null && checkPNPMVersion; then
echo "无需安装 pnpm@@$majorVersionRequired"
else
echo "安装 pnpm@$majorVersionRequired..."
installRequiredPNPM;
fi

# 安装项目依赖
pnpm i --frozen-lockfile --registry https://registry.npmmirror.com

## 安装依赖
npm i pnpm@8 -g && pnpm i --frozen-lockfile --registry https://registry.npmmirror.com

0 comments on commit 30007d8

Please sign in to comment.