# 2.5 Deployment && CI

> 原文地址： <https://juejin.cn/post/6971054455139598366/>

本文将介绍项目的发布部署、持续集成。

## 🚀 发布部署

执行命令 `npm run pub` 实现发布部署流程：

* 本地代码检查合并，push 到远程分支；
* 组件构建发布(npm pulish)；
* 官网发布部署。

接下来详细介绍各 `shell` 脚本功能。

### build/git-release.sh

检查本地代码 `dev` 分支是否与线上分支存在冲突。

![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/b7c724b7007f49078ba370566bbe42c0~tplv-k3u1fbpfcp-watermark.image)

### build/release.sh

主要作用代码分支合并 push 远程分支、版本号确认更新、组件主题发布(npm pulish)。

1. 合并 dev 分支到 master
2. 通过 `select-version-cli` 确认发布版本号。
3. 执行命令 `npm run dist` 打包构建组件。
4. 运行 ssr 测试 `node test/ssr/require.test.js`。
5. 发布主题，更新版本号，与组件库保持一致。
6. 提交代码并更新 package.json 中的版本号 。
7. master 和 dev 分支 push 到远程分支。
8. 发布组件。

![carbon (92).png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/59550d03381d46e8ba5841bf6bc5da2c~tplv-k3u1fbpfcp-watermark.image)

`select-version-cli` 提供选择发布版本选择。

![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4feea1adb27445b082e11842e06884ce~tplv-k3u1fbpfcp-watermark.image)

选择确认后，继续执行 `release.sh` 执行发布部署流程。

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6c1797177ab347db9385a94bab55b9cd~tplv-k3u1fbpfcp-watermark.image)

### 🚧 build/deploy-faas.sh

网站发布部署， 用于`faas deploy` 配置。在 2.15 版本之后移除了`pub`命令 `sh build/deploy-faas.sh`调用，集成至 CI，详见`build/deploy-ci.sh`。

![carbon (93).png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f7a7413a978c41a4b48e43dfacf2434d~tplv-k3u1fbpfcp-watermark.image)

## 持续集成

持续集成（Continuous Integration，简称 CI）指的是只要代码有变更，就自动运行构建和测试，反馈运行结果。确保符合预期以后，再将新代码"集成"到主干。持续集成的好处在于，每次代码的小幅变更，就能看到运行结果，从而不断累积小的变更，而不是在开发周期结束时，一下子合并一大块代码。

### .travis.yml

使用 Travis CI 提供的是持续集成服务，项目的根目录下面必须有一个.travis.yml 文件。这是配置文件，指定了 Travis 的行为。该文件必须保存在 Github 仓库里面，一旦代码仓库有新的 Commit，Travis 就会去找这个文件，执行里面的命令(执行测试、构建、部署等操作)。

![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6cba5805cc37418d80f99c6e11f50137~tplv-k3u1fbpfcp-watermark.image)

### build/deploy-ci.sh

主要作用构建发行版本和开发版本内容。

1. git config 定义 user.name 和 user.email。
2. 发行版本构建(组件库、主题`theme-chalk`、项目网站)、打新标签。
3. 开发分支的 主题`theme-chalk`、项目网构建提交到 master 分支。

![carbon (43).png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8cd2483135e64096b50956e6e1e4983c~tplv-k3u1fbpfcp-watermark.image)

## makefile

`makefile`带来的好处就是**自动化构建**，一旦写好，只需要一个`make`命令，整个工程完全自动化，极大的提高了软件开发的效率。

> 在软件开发中，`make` 是一个工具程序（Utility software），经由读取叫做 `makefile` 的文件，自动化建构软件。它是一种转化文件形式的工具，转换的目标称为 `target` ；与此同时，它也检查文件的依赖关系，如果需要的话，它会调用一些外部软件来完成任务。它使用叫做 `makefile` 的文件来确定一个 `target` 文件的依赖关系，然后把生成这个 `target` 的相关命令传给 `shell` 去执行。

mac/linux 中直接可以执行 make 命令的(terminal bash)。 Windows 下载 make 的 GUN 工具[Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm)

> **配置环境变量 Win**
>
> 右键`我的电脑`->`属性`->`高级`->`环境变量`->`系统变量`->`变量path`,然后在`path`中新建环境变量，目录定位到`make for windows`安装目录(默认路径 C:\Program Files (x86)\GnuWin32\bin\ )即可。

若目录下没有 `makefile`,执行显示“没有指明目标并且找不到 makefile ”，终止命令。

![image.png](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/674486e5d7664c2482f60e29efdc1083~tplv-k3u1fbpfcp-watermark.image)

执行 `make` 命令可以看到详细的使用说明。

![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/915ae59a64a64132a29145c7e14843f0~tplv-k3u1fbpfcp-watermark.image)

执行 `make target` 命令后，找到 `target` 对应的 `commonds`并执行。 查看源文件,每个`commonds`都是 npm script，具体功能详见前文。(make help 输出文本存在转义字符，win 系统无法支持)

![carbon (44).png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/797f044c9b834682827409b7633a9a14~tplv-k3u1fbpfcp-watermark.image)

## 关联阅读

点击以下链接，可以快速查看本系列其他文章：\
[专栏/Element 2.X 源码学习](https://juejin.cn/column/6961321064110489631)

👇 项目工程化系列文章链接如下，推荐按照顺序阅读文章 👇。

1️⃣ [源码剖析之工程化：项目概览、package.json、npm script](https://juejin.cn/post/6969258163136626725)\
2️⃣ [源码剖析之工程化：项目构建、MD 解析](https://juejin.cn/post/6969933702759940133)\
3️⃣ [源码剖析之工程化：打包配置](https://juejin.cn/post/6970691644114862111/)\
4️⃣ [源码剖析之工程化：发布部署、持续集成](https://juejin.cn/post/6971054455139598366/)\
5️⃣ [源码剖析之工程化：主题构建、自动化测试、代码质量检查、类型声明](https://juejin.cn/post/6971434343516340238)\
6️⃣ [源码剖析之工程化：项目网站](https://juejin.cn/post/6972180649625157645)\
7️⃣ [源码剖析之工程化：命令之图解](https://juejin.cn/post/6991347082552573965)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anduril.gitbook.io/learning-element/chapter02_fee/2.5-deployment-and-and-ci.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
