Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编写优雅的 commit message 并自动生成 changelog #26

Open
yinxin630 opened this issue Oct 10, 2019 · 0 comments
Open

编写优雅的 commit message 并自动生成 changelog #26

yinxin630 opened this issue Oct 10, 2019 · 0 comments
Labels

Comments

@yinxin630
Copy link
Owner

yinxin630 commented Oct 10, 2019

commit message 规范

http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html

自动校验 commit message

参考: https://github.com/conventional-changelog/commitlint

  1. 安装依赖 npm install -D @commitlint/{config-conventional,cli} husky
  2. 在 package.json 添加 commitlint 配置和 git hook
"husky": {
  "hooks": {
    "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
  }
},
"commitlint": {
  "extends": [
    "@commitlint/config-conventional"
  ]
}
  1. 提交 commit 触发校验

通过交互界面生成符合规范的 commit message

  1. 安装依赖 npm install -D commitizen cz-conventional-changelog
  2. 在 package.json 中新增一条 script
"scripts": {
  ...
  "commit": "git-cz"
}
  1. 在 package.json 添加 commitizen 配置
"config": {
  "commitizen": {
    "path": "node_modules/cz-conventional-changelog"
  }
}
  1. 执行 git add .npm run commit

image

自动生成 changelog

参考: https://github.com/CookPete/auto-changelog

  1. 安装依赖 npm install -D auto-changelog
  2. 创建配置文件 .auto-changelog
{
  "template": "CHANGELOG.template",
  "unreleased": true,
  "commitLimit": false
}
  1. 创建自定义 changelog 模板 CHANGELOG.template. 注意替换组名和仓库名
# Changelog

{{#each releases}}
  ## [{{title}}]

  {{#commit-list commits heading='### Breaking Change' message='\[break\]'}}
    - {{subject}} [{{shorthash}}]({{href}})
  {{/commit-list}}

  {{#commit-list commits heading='### New Feature' message='feat: ' exclude='\[break\]'}}
    - {{subject}} [{{shorthash}}]({{href}})
  {{/commit-list}}

  {{#commit-list commits heading='### Bug Fix' message='fix: ' exclude='\[break\]'}}
    - {{subject}} [{{shorthash}}]({{href}})
  {{/commit-list}}
{{/each}}

  1. 在 package.json 中新增 script
"scripts": {
  ...
  "changelog": "auto-changelog",
  "version": "auto-changelog -p && git add CHANGELOG.md"
}
  1. 执行 npm run changelog

执行 npm version 时会自动生成带所发布版本号的 changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant