@@ -4,3 +4,158 @@ permalink: /manuscripts/develop-skill/code-manager/ci-cd.html
44---
55
66# 持续集成、持续交付
7+
8+ ## 最佳实践
9+
10+ ### 持续集成
11+
12+ ``` yaml
13+ # # 代码CI快速集成流水线,lint、fix、build
14+ # # 注意: 只在142vip/JavaScriptCollection时执行
15+
16+ name : CI
17+ # # 触发条件
18+ on :
19+ # 提PR到next分支触发CI
20+ pull_request :
21+ branches :
22+ - next
23+ push :
24+ branches :
25+ - next
26+
27+ # 手动触发部署
28+ workflow_dispatch :
29+
30+ schedule :
31+ - cron : " 0 0 1 * *"
32+
33+ jobs :
34+ Base-Build :
35+ name : " 基础编译构建"
36+ runs-on : ubuntu-latest
37+ if : github.repository == '142vip/JavaScriptCollection' && github.event_name == 'pull_request'
38+ permissions :
39+ actions : read
40+ pull-requests : read
41+
42+ steps :
43+ - name : Checkout Code
44+ uses : actions/checkout@v4
45+ with :
46+ persist-credentials : false
47+ # “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
48+ fetch-depth : 0
49+
50+ # # 安装PNPM
51+ - name : PNPM Install
52+ uses : pnpm/action-setup@v2
53+ with :
54+ version : 8
55+
56+ # # 安装Node环境
57+ - name : Install Node.js
58+ uses : actions/setup-node@v3
59+ with :
60+ node-version : 18.18.0
61+ # # 淘宝镜像加速
62+ registry-url : ' https://registry.npmmirror.com'
63+ # # 缓存
64+ cache : ' pnpm'
65+
66+ # # 下载依赖,并执行初始化脚本:钩子函数、思维导图构建
67+ - name : Install Dependencies
68+ run : |
69+ ./scripts/ci
70+
71+ - name : Code LintFix
72+ run : |
73+ ./scripts/lint
74+
75+ - name : Build Site
76+ run : |
77+ ./scripts/bundle build
78+
79+ - name : Build Site With Proxy
80+ run : |
81+ ./scripts/bundle build_proxy
82+
83+ ` ` `
84+
85+ ### 持续交付
86+
87+ ` ` ` yaml
88+
89+ # # CD交付流水线
90+ # # - 部署到Github Pages
91+ # # - 部署到Vercel托管平台
92+ # # - 发布新的Github Release
93+ # # 参考资料:https://v2.vuepress.vuejs.org/zh/guide/deployment.html#github-pages
94+
95+ name : CD
96+ on :
97+ push :
98+ branches :
99+ - next
100+ workflow_dispatch :
101+
102+ jobs :
103+ # # 版本发布
104+ release :
105+ name : " 创建Github发布"
106+ runs-on : ubuntu-latest
107+ # # 主库next且执行release更新时执行
108+ if : github.repository == '142vip/JavaScriptCollection' && startsWith(github.event.head_commit.message, 'chore(release):')
109+
110+ steps :
111+ - name : Checkout Code
112+ uses : actions/checkout@v4
113+ with :
114+ persist-credentials : false
115+ # “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
116+ fetch-depth : 0
117+
118+ # ## 打成压缩包
119+ - name : Create Zip Package
120+ run : |
121+ zip -r JavaScriptCollection.zip . \
122+ -x "node_modules/*" \
123+ -x ".git/*"
124+
125+ # 提取版本号
126+ - name : Get New Version Number
127+ id : releaseVersion
128+ run : |
129+ echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
130+
131+ # 创建发布版本
132+ - name : Create New Release
133+ id : createRelease
134+ uses : actions/create-release@latest
135+ env :
136+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
137+ with :
138+ tag_name : v${{ steps.releaseVersion.outputs.version }}
139+ release_name : v${{ steps.releaseVersion.outputs.version }}
140+ body : |
141+ Release ${{ steps.releaseVersion.outputs.version }}
142+
143+ ### Features
144+
145+ ### Bug Fixes
146+
147+ # # 更新资源
148+ - name : Upload Resource Assets
149+ uses : actions/upload-release-asset@latest
150+ env :
151+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
152+ with :
153+ upload_url : ${{ steps.createRelease.outputs.upload_url }}
154+ asset_path : ./JavaScriptCollection.zip
155+ asset_name : JavaScriptCollection.zip
156+ asset_content_type : application/zip
157+
158+
159+ ```
160+
161+ ## 参考资料
0 commit comments