-
Notifications
You must be signed in to change notification settings - Fork 1
180 lines (152 loc) · 4.62 KB
/
CD.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# CD持续交付
# - 部署到Github Pages
# - 发布新的Github Release
# 参考
# - https://vitepress.dev/zh/guide/deploy#github-pages
#
name: CD
on:
push:
branches:
- next
workflow_dispatch:
# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write
jobs:
# 版本发布
github-release:
name: 创建Github发布
runs-on: ubuntu-latest
# 主库next且执行release更新时执行
if: github.repository == '142vip/core-x' && startsWith(github.event.head_commit.message, 'chore(release):')
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
# 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v4
with:
version: 9.6.0
# 安装Node环境
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.12.2
# 缓存
cache: pnpm
# 基于国内镜像源下载依赖,并执行初始化脚本:钩子函数、思维导图构建
- name: Install Dependencies
run: |
./scripts/ci
- name: Build All Packages
run: |
pnpm build:packages
# Github发布版本,并更新Release信息
- name: Release New Version
run: npx changelog
env:
GITHUB_TOKEN: ${{secrets.TOKEN}}
npm-release:
name: 创建npm发布
runs-on: ubuntu-latest
# 主库next且执行release更新时执行
if: github.repository == '142vip/core-x' && startsWith(github.event.head_commit.message, 'release(@142vip/')
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
# 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v4
with:
version: 9.6.0
# 安装Node环境
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.12.2
# npm包上传地址,用于注册,参考:https://github.com/actions/setup-node
registry-url: 'https://registry.npmjs.org'
# 缓存
cache: pnpm
# 下载依赖,并执行初始化脚本:钩子函数、思维导图构建
- name: Install Dependencies
run: |
./scripts/ci
- name: Build All Packages
run: |
pnpm build:packages
- name: Get Package Name By Commit Scope
id: getPkgName
# 这里使用正则截取scope,获取包名
run: |
SCOPE=$(echo "${{ github.event.head_commit.message }}" | grep -o '@[^):]*')
echo "name=$SCOPE" >> $GITHUB_OUTPUT
- name: Use Package Name
run: |
echo "The pkgName is: ${{ steps.getPkgName.outputs.name }}"
# Npm 版本发布 注意:只发布packages中的模块
- name: Publish New Npm Version
run: |
pnpm publish --filter "${{ steps.getPkgName.outputs.name }}"
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
# 构建并部署Dist
deploy-dist:
name: 部署到Github Pages
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# todo 确定这里的触发条件
if: github.repository == '142vip/core-x'
steps:
# 拉取代码
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要
# 安装pnpm
- name: PNPM Install
uses: pnpm/action-setup@v4
with:
version: 9.6.0
# 安装Node
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.12.2
cache: pnpm
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Install dependencies
run: |
./scripts/ci
# 编译公共模块
- name: Build All Packages
run: |
pnpm build:packages
# 编译 打包成dist,支持代理
- name: Build with VitePress
run: |
pnpm build:docs-proxy
# 上传dist文件
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: dist
# 部署
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4