Egg.js Organizations 下目前有 154 个 Repository 需要维护,除去 Demo 项目,按照功能主要分为两类:
- 核心仓库(需要人工验证并发布)
- egg
- egg-core
- egg-cluster
- 一般类库(无需人工干预,CI 通过即可自动发布)
- egg-ci
- egg-doctools
针对上述两类包,我们借助 Github Actions 执行发布流程。
Github Actions:Github 提供的 Workflow 工具,基于 Events 提供了一个容器运行环境。
发布流程
主仓发布
Github Config
.github/main.workflow
## workflow
workflow "Push" {
on = "push"
resolves = ["workman release"]
}
workflow "Pull Request" {
on = "pull_request"
resolves = ["workman check"]
}
## actions
action "npm install" {
uses = "docker://thonatos/github-actions-nodejs"
args = "npm install"
}
action "npm ci" {
uses = "docker://thonatos/github-actions-nodejs"
needs = ["npm install"]
env = {
YUQUE_GROUP = "eggjs-dev"
YUQUE_ENDPOINT = "https://www.yuque.com/api/v2/"
}
secrets = [
"YUQUE_TOKEN"
]
args = "npm run ci"
}
action "npm build" {
uses = "docker://thonatos/github-actions-nodejs"
needs = ["npm ci"]
args = "npm run build"
}
## target
action "workman check" {
uses = "thonatos/github-actions-workman@1.6.0-Marketplace"
needs = ["npm ci"]
args = "workman check"
secrets = [
"GITHUB_TOKEN",
"NPM_TOKEN"
]
}
action "workman release" {
uses = "thonatos/github-actions-workman@1.6.0-Marketplace"
needs = ["npm build"]
args = "workman release --releaseBranch master"
secrets = [
"GITHUB_TOKEN",
"NPM_TOKEN"
]
}
Pull Request
- 创建分支
- 修改 History.md
- 修改 package.json
- 推送分支
- 创建 PR
- 标题:Release 1.0.0
- Actions
- Check Release Proposal
- 通过:设置 Label
- 不通过:跳过/忽略
- 管理员
- 合并 PR
提交示例

检测完成并添加 label

Push
当管理员合并 PR 后触发发布流程。
Actions 执行过程

版本发布

一般类库发布
Github Config
.github/main.workflow
# workflow
workflow "Push" {
on = "push"
resolves = ["auto release"]
}
# actions
action "npm install" {
uses = "docker://thonatos/github-actions-nodejs"
args = "npm install -g npminstall && npminstall"
}
action "npm ci" {
uses = "docker://thonatos/github-actions-nodejs"
needs = ["npm install"]
args = "npm run ci"
}
# target
action "auto release" {
uses = "docker://thonatos/github-actions-nodejs"
needs = ["filter master", "npm ci"]
args = "npm run semantic-release"
secrets = ["GITHUB_TOKEN", "NPM_TOKEN"]
}
# filter
action "filter master" {
uses = "actions/bin/filter@3c0b4f0e63ea54ea5df2914b4fabf383368cd0da"
secrets = ["GITHUB_TOKEN"]
args = "branch master"
}
Package Config
package.json
// package.json
{
// CI 发布命令
"scripts": {
"semantic-release": "semantic-release"
},
// 开发环境依赖
"devDependencies": {
"semantic-release": "^15.13.18"
},
// semantic-release 配置
"release": {
"branche": "master",
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github"
]
}
}
全局配置
secrets
如 NPM_TOKEN 等设计安全的信息,可配置在 secrets 中防止信息泄露。
settings

参考链接
参考文档
示例地址
上方示例演示了自动发布与人工验证(Actions 校验,管理员合并)两种发布流程。