1. 程式人生 > >Git 專案自動 release 生成版本並提交遠端

Git 專案自動 release 生成版本並提交遠端

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',
        }
      },
    });
    

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
    

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 版本升級