基于 semantic-release 分析工具制作的自动打 TAG 命令。
semantic-release 使用 @semantic-release/commit-analyzer 插件
来实现自动分析提交信息(commit messages)中的关键字(如 feat:、fix:、perf: 等),
并决定版本升级类型(major、minor 或 patch)。
默认版本升级规则
如果想自定义版本升级规则,可配置 releaseRules 参数。
使用 git-auto-tag 需要团队约定
提交格式,
建议配合 commit-lint 相关插件使用。
生成 tag 时通过 -m 添加的 message,例如:git tag -a v0.0.1 -m "Release v0.0.1"
指定 tag 格式,其中 ${version} 会由生成的 tag 替换。如 tag 为 1.2.3,那么 v${version} 为 v1.2.3。
是否只得到下一个版本号等变量,而非真正的生成 tag。
从指定的文件中读取自定义发布规则,如果没有指定,则使用默认规则,仅 feat 、 fix 、 perf 三种格式的提交注释会生成 tag 。
如需扩充发布规则可自定义 releaseRules 。
规则如何配置详见文档
示例文件 release-rules.json:
[
{ "type": "docs", "scope": "README", "release": "patch" },
{ "type": "refactor", "scope": "core-*", "release": "minor" },
{ "type": "refactor", "release": "patch" },
{ "scope": "no-release", "release": false }
];
指定文件保存执行结果,有如下字段
{
//`Object` with `version`, `gitTag` and `gitHead`
// of the last release.
lastRelease,
//`Object` with `version`, `gitTag`, `gitHead` and `notes`
// of the release being done.
nextRelease,
commits,
releases,
}
自动生成 tag 依据的分支,根据这个分支获取提交日志,根据提交日志生成 tag
git config --list 获取到的 git 配置中的 remote.origin.url 的值目标仓库仓库 https 地址
{
tag, // 生成的 tag
}
# .cnb.yml
main:
push:
- stages:
- name: auto-tag
image: cnbcool/git-auto-tag:latest
settings:
tagFormat: v\${version}
toFile: tag_info.json
dryRun: false
blockWhenFail: false
branch: $CNB_BRANCH
repoUrlHttps: $CNB_REPO_URL_HTTPS
exports:
tag: NEW_TAG
- name: show tag
script: echo $NEW_TAG
- name: show tag res
script: cat tag_info.json