conventional commits实践:配合GitHub Tag Action实现自动化版本管理

发布时间:2026/7/28 23:15:15
conventional commits实践:配合GitHub Tag Action实现自动化版本管理 conventional commits实践配合GitHub Tag Action实现自动化版本管理【免费下载链接】github-tag-actionA Github Action to automatically bump and tag master, on merge, with the latest SemVer formatted version. Works on any platform.项目地址: https://gitcode.com/gh_mirrors/git/github-tag-actionGitHub Tag Action是一款强大的工具能在代码合并时自动为master分支生成符合SemVer规范的标签实现自动化版本管理。本文将详细介绍如何结合Conventional Commits规范与GitHub Tag Action轻松搞定项目版本管理。什么是Conventional Commits规范Conventional Commits规范是一种基于提交消息的轻量级约定。它规定了提交消息的格式使得自动化工具能够据此确定版本号变更和生成变更日志。遵循该规范的提交消息通常包含类型、作用域和描述等部分例如feat(pencil): add graphiteWidth option。GitHub Tag Action简介GitHub Tag Action是一个GitHub Action可在合并代码到指定分支时自动更新和推送Git标签。它基于SemVer格式化版本号适用于任何平台。该工具通过分析提交消息来确定版本变更类型如major、minor、patch等并生成相应的标签。GitHub Tag Action的主要功能根据提交消息自动确定版本变更类型生成符合SemVer规范的标签支持自定义标签前缀、分支规则等输出变更日志、新旧版本号等信息快速开始GitHub Tag Action的基本使用要在项目中使用GitHub Tag Action只需在工作流文件中添加以下步骤name: Bump version on: push: branches: - master jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkoutv4 - name: Bump version and push tag id: tag_version uses: mathieudutour/github-tag-actionv6.2 with: github_token: ${{ secrets.GITHUB_TOKEN }} - name: Create a GitHub release uses: ncipollo/release-actionv1 with: tag: ${{ steps.tag_version.outputs.new_tag }} name: Release ${{ steps.tag_version.outputs.new_tag }} body: ${{ steps.tag_version.outputs.changelog }}Conventional Commits与GitHub Tag Action的完美结合提交消息格式详解GitHub Tag Action使用semantic-release conventions来解析提交消息默认采用Angular Commit Message Conventions。以下是不同提交消息对应的版本变更类型提交消息示例版本变更类型fix(pencil): stop graphite breaking when too much pressure appliedPatch Releasefeat(pencil): add graphiteWidth optionMinor Releaseperf(pencil): remove graphiteWidth optionBREAKING CHANGE: The graphiteWidth option has been removed.Major Release自定义提交规则如果默认的提交规则不符合项目需求可以通过custom_release_rules参数自定义。例如with: custom_release_rules: hotfix:patch,pre-feat:preminor,bug:patch:Bug Fixes,chore:patch:ChoresGitHub Tag Action的高级配置分支管理GitHub Tag Action允许通过参数指定哪些分支生成正式版本标签哪些生成预发布标签release_branches: 生成正式版本标签的分支默认值为master,mainpre_release_branches: 生成预发布版本标签的分支标签自定义可以通过以下参数自定义生成的标签tag_prefix: 标签前缀默认值为vappend_to_pre_release_tag: 预发布标签后缀默认值为分支名create_annotated_tag: 是否创建带注释的标签默认值为false其他实用配置fetch_all_tags: 是否获取所有标签默认只获取最近100个标签dry_run: 仅计算版本和变更日志不实际创建标签default_bump: 当没有明确的提交消息时使用的默认版本变更类型默认值为patch常见问题与解决方案没有提交指定版本变更时如何处理如果没有提交指定版本变更GitHub Tag Action会输出No commit specifies the version bump. Skipping the tag creation.。此时可以通过设置default_bump参数来指定默认的版本变更类型。如何获取生成的版本信息GitHub Tag Action提供了多个输出参数可以在后续步骤中使用new_tag: 新生成的标签new_version: 新生成的版本号不带前缀previous_tag: 上一个标签release_type: 版本变更类型changelog: 变更日志总结通过Conventional Commits规范与GitHub Tag Action的结合我们可以实现版本管理的自动化减少手动操作提高开发效率。只需遵循简单的提交消息规范GitHub Tag Action就能自动为我们生成版本标签和变更日志让版本管理变得轻松简单。要开始使用GitHub Tag Action只需克隆仓库git clone https://gitcode.com/gh_mirrors/git/github-tag-action然后按照本文介绍的方法进行配置即可。希望本文能帮助你更好地理解和使用Conventional Commits与GitHub Tag Action实现高效的版本管理【免费下载链接】github-tag-actionA Github Action to automatically bump and tag master, on merge, with the latest SemVer formatted version. Works on any platform.项目地址: https://gitcode.com/gh_mirrors/git/github-tag-action创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考