Skip to content

Commit 844d2be

Browse files
author
微信公众号:储凡
authored
Merge pull request #81 from 142vip/fix/ci
2 parents f9f1702 + 30007d8 commit 844d2be

File tree

3 files changed

+74
-63
lines changed

3 files changed

+74
-63
lines changed

.github/workflows/CD.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ name: CD
88
on:
99
push:
1010
branches:
11-
- master
1211
- next
1312
workflow_dispatch:
1413

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

38-
# ## 依赖下载完成后,或执行思维导图编译
39-
# - name: PNPM Install
40-
# uses: pnpm/action-setup@v2
41-
# with:
42-
# version: 7
43-
# run_install: |
44-
# args: [--frozen-lockfile, --registry=https://registry.npmmirror.com]
45-
# 安装Node环境
37+
## 安装PNPM
38+
- name: PNPM Install
39+
uses: pnpm/action-setup@v2
40+
with:
41+
version: 8
42+
43+
## 安装Node环境
4644
- name: Install Node.js
4745
uses: actions/setup-node@v3
4846
with:
4947
node-version: 18.18.0
5048
## 淘宝镜像加速
5149
registry-url: 'https://registry.npmmirror.com'
50+
## 缓存
51+
cache: 'pnpm'
5252

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

107107
steps:

.github/workflows/CI.yaml

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
name: CI
66
## 触发条件
77
on:
8+
# 提PR到next分支触发CI
89
pull_request:
910
branches:
10-
- 'master'
11-
- 'next'
12-
- '!pages/**'
11+
- next
1312
push:
1413
branches:
15-
- master
1614
- next
15+
1716
# 手动触发部署
1817
workflow_dispatch:
1918

@@ -27,10 +26,10 @@ env:
2726
UserName: 142vip
2827

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

46-
# ## 依赖下载完成后,或执行思维导图编译
47-
# - name: PNPM Install
48-
# uses: pnpm/action-setup@v2
49-
# with:
50-
# version: 7
51-
# run_install: |
52-
# args: [--frozen-lockfile, --registry=https://registry.npmmirror.com]
53-
# 安装Node环境
45+
## 安装PNPM
46+
- name: PNPM Install
47+
uses: pnpm/action-setup@v2
48+
with:
49+
version: 8
50+
51+
## 安装Node环境
5452
- name: Install Node.js
5553
uses: actions/setup-node@v3
5654
with:
5755
node-version: 18.18.0
5856
## 淘宝镜像加速
5957
registry-url: 'https://registry.npmmirror.com'
58+
## 缓存
59+
cache: 'pnpm'
6060

61+
## 下载依赖,并执行初始化脚本:钩子函数、思维导图构建
6162
- name: Install Dependencies
6263
run: |
6364
./scripts/ci
6465
65-
- name: Cache Dependencies
66-
uses: actions/cache@v3
67-
with:
68-
path: node_modules
69-
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
70-
71-
Base-Build:
72-
name: "基础编译校验"
73-
runs-on: ubuntu-latest
74-
if: github.repository == '142vip/JavaScriptCollection'
75-
needs:
76-
- install-init
77-
steps:
78-
- name: Checkout Code
79-
uses: actions/checkout@v4
80-
with:
81-
persist-credentials: false
82-
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
83-
fetch-depth: 0
84-
85-
- name: Restore Dependencies From Cache
86-
uses: actions/cache@v3
87-
with:
88-
path: node_modules
89-
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
90-
9166
- name: Code LintFix
9267
run: |
9368
./scripts/lint --fix
@@ -100,12 +75,11 @@ jobs:
10075
run: |
10176
./scripts/bundle build_proxy
10277
78+
10379
Build-Docker-Image:
10480
name: "构建Docker镜像"
10581
## macos不支持docker的使用
10682
runs-on: ubuntu-latest
107-
needs:
108-
- install-init
10983
## 主库master、next且执行release更新时执行
11084
if: github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')
11185
permissions:
@@ -119,7 +93,10 @@ jobs:
11993
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
12094
fetch-depth: 0
12195

122-
- name: Set up Docker
96+
- name: Set up QEMU
97+
uses: docker/setup-qemu-action@v3
98+
99+
- name: Set up Docker Buildx
123100
uses: docker/setup-buildx-action@v3
124101

125102
- name: Login Docker
@@ -131,19 +108,17 @@ jobs:
131108
--password=${{ secrets.DOCKER_PASSWORD }} \
132109
${{env.REGISTRY}}
133110
134-
- name: Restore Dependencies From Cache
135-
uses: actions/cache@v3
136-
with:
137-
path: node_modules
138-
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.yaml') }}
139111
112+
- name: Install Dependencies
113+
run: |
114+
./scripts/ci
140115
141116
## 构建,支持domain
142117
- name: Build To Dist
143118
run: |
144-
./scripts/bundle build_proxy
119+
./scripts/bundle build
145120
146121
## 快速构建并推送
147122
- name: Push Docker Image
148123
run: |
149-
./scripts/bundle image_faster
124+
./scripts/bundle image_faster

scripts/ci

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
#!/bin/bash
2+
##
3+
## 依赖安装脚本
4+
## 使用:
5+
## ./scripts/ci
6+
##
7+
8+
# 期望的 pnpm 大版本号
9+
majorVersionRequired="8"
10+
11+
# 检测 pnpm 是否已安装并且大版本号符合要求
12+
checkPNPMVersion() {
13+
local pnpmVersionInstalled=$(pnpm --version 2>/dev/null) # 获取已安装的 pnpm 版本
14+
if [[ $pnpmVersionInstalled =~ ^$majorVersionRequired ]]; then
15+
echo "已安装的 pnpm 版本:$pnpmVersionInstalled"
16+
echo "已安装的 pnpm 大版本号符合要求."
17+
return 0
18+
else
19+
echo "未安装 pnpm 或 pnpm 大版本号不符合要求."
20+
return 1
21+
fi
22+
}
23+
24+
# 安装pnpm
25+
installRequiredPNPM(){
26+
npm i pnpm@$majorVersionRequired -g
27+
}
28+
29+
30+
## 判断是PNPM安装且版本符合要求
31+
if command -v pnpm &> /dev/null && checkPNPMVersion; then
32+
echo "无需安装 pnpm@@$majorVersionRequired"
33+
else
34+
echo "安装 pnpm@$majorVersionRequired..."
35+
installRequiredPNPM;
36+
fi
37+
38+
# 安装项目依赖
39+
pnpm i --frozen-lockfile --registry https://registry.npmmirror.com
240

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

0 commit comments

Comments
 (0)