Git 项目自动 release 生成版本并提交远程

本文介绍了如何通过Grunt配置和使用grunt-bump、grunt-conventional-changelog来自动化生成Git项目的版本更新和release,包括安装、配置及执行步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. grunt 配置

1.1. grunt

  1. 全局安装 grunt-cli

    npm install -g grunt-cli

  2. 安装 grunt

    npm install –save-dev grunt

  3. 配置 gruntfile.js

    module.exports = function (grunt) {
    
      // Project configuration
      grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
    
        // Grunt-plugins config ...
      });
    
      // Load tasks
      [
        'grunt-bump',
        'grunt-conventional-changelog'
      ].forEach(function (task) {
        grunt.loadNpmTasks(task);
      });
    
      // Regist tasks
      grunt.registerTask(
        'release', 
        'Build, bump and publish to Git.',
        function (type) {
          grunt.task.run([
            'bump:' +(type || 'patch') + ':bump-only',
            'conventionalChangelog',
            'bump-commit'
          ]);
        }
      );
    };

1.2. grunt-bump

  1. 安装 grunt-bump

    npm install --save-dev grunt-bump
    
  2. 配置 gruntfile.js:

    grunt.initConfig({
      bump: {
        options: {
          updateConfigs: ['pkg'],
          commitFiles: [
            'package.json',
            'CHANGELOG.md'
          ],
          commitMessage: 'chore: release v%VERSION%',
          prereleaseName: 'rc',
          pushTo: 'upstream',
        }
      },
    });
    
  3. 参考

1.3. grunt-conventional-changelog

  1. 安装 grunt-conventional-changelog:

    npm install --save-dev grunt-conventional-changelog
    
  2. 配置 gruntfile.js:

    grunt.initConfig({
      conventionalChangelog: {
        release: {
          options: {
            changelogOpts: {
              preset: 'angular'
            }
          },
          src: 'CHANGELOG.md'
        }
      }
    });
    
  3. 命令

    conventional-changelog -p angular -i CHANGELOG.md -s -r 0
    
  4. 参考

1.4. 执行

  • grunt release euqals grunt release:patch
  • grunt release:minor
  • grunt release:major
  • grunt release:git git head 版本后缀
  • grunt release:prepatch
  • grunt release:preminor
  • grunt release:premajor
  • grunt release:prerelease rc 版本升级
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值