0.0.19 • Published 3 years ago

general-release v0.0.19

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

General Release

Appveyor Travis Version Downloads

Automatic Release Tool for Git repository using bash shell

Features

  • Release version
    • Analyze the release/pre-release version from the commits after the last git-tag
    • Specifies the release/pre-release version number
    • Increment the release/pre-release version at the specified level based on the last git-tag
  • Generate release note
    • Generate the release note from the commits after the last git-tag
  • Generate changelog
  • Git commit, tag, push
  • CI support
    • Appveyor
    • Travis
    • CircleCI
    • GitlabCI
    • Jenkins
  • Archive files (use gzip plugin)
  • Create release at GitHub (use github plugin)
  • Create release at NPM (use npm plugin)
  • Create release at Yum (use yum plugin)
  • Create release at Maven (use maven plugin)
  • Update appveyor build details (use appveyor plugin)
  • Custom plugin
  • Validate the commit message
  • Tools: commit template and commit linter

Dependencies

  • Bash Shell
  • Git (>=1.17.0)

Commit Message Format

Each commit message consists of one or more headers and bodies. The header has a special format that includes a type, a scope and a subject:

<type>(<scope>): <subject>
<body>

<type>(<scope>): <subject>
<body>

The header is mandatory and the scope of the header is optional.

Release Rule Configuration (yml)

  • The Config Fields
Field NameField TypeDescription
tag_repostringGit repository URL, default: [auto] Get the url with command: git config --get remote.origin.url
tag_prefixstringPrefix of the Git tag , default: v
release_notestringRelease Note, default: [auto] Analyze the commits after the last Git tag by the rules defined in the configuration
changelogstringGenerante the changelog file, default: CHANGELOG.md
commitstring[]Git commit files, default: CHANGELOG.md
commit_messagestringCommit message template, default: chore(release): {tag} [skip ci], the format variables: - version: Release version - channel: Release channel - prerelease: Pre-release id - tag: Release Git tag
commit_notebooleanCommit with release note, default: true
pluginsstring[]Plugins - github [--file, --token] [options] - npm [--registry, --access, --token] [options] - appveyor [options] - constum.sh [options]
branchsobject[]The branch config
    branchs[].patternregexprequired: Pattern of the release branch name
    branchs[].channelstringPublish channel
    branchs[].prereleasestringPre-release id
rulesobject[]Rules for release version analyzer and release note generator
    rules[].typeregexprequired: Pattern of the commit type
    rules[].scoperegexpPattern of the commit scope
    rules[].releasestringThe Release type:major, minor, patch, none, default none
    rules[].prereleasestringThe Pre-release type: major, minor, patch, prerelease, none, default: prerelease
    rules[].notestringTitle of the release note
    rules[].bodybooleanInclude the commit body to release note
  • general-release looks the config file at .release.yml
  • Use --config or -c to use another path
  • The default configuration: release.yml

Usage

Shell

  • Download general-release

    # download
    curl -L -s https://github.com/billowz/general-release/releases/download/$(curl -L -s -H 'Accept: application/json' https://github.com/billowz/general-release/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')/general-release.zip -o general-release.zip
    unzip -o general-release.zip -d general-release
    rm -f general-release.zip
  • Release

    # deploy with github plugin
    general-release/bin/bin.sh -c .release.yml -p "github -f release.zip" --debug
    # or
    general-release/bin/bin.sh deploy -c .release.yml -p "github -f release.zip" --debug
    
    # dry-run mode
    general-release/bin/bin.sh -c .release.yml -p "github -f release.zip" --debug --dry-run
  • Preview Release

    general-release/bin/bin.sh preview -c .release.yml --debug
    # or
    general-release/bin/bin.sh --no-deploy -c .release.yml --debug
  • Release with the specialed version

    # release with specified version: 1.0.0
    general-release/bin/bin.sh -v 1.0.0
    
    # release with specified version on the specified channel
    general-release/bin/bin.sh -v 1.0.0@next
    
    # release with specified pre-release version
    general-release/bin/bin.sh -v 1.0.0-alpha
    
    # release with specified pre-release version on the specified channel
    general-release/bin/bin.sh -v 1.0.0-alpha@next
    
    # increment the version by the specified level from the last git-tag
    general-release/bin/bin.sh -v minor
    
    # increment the version by the specified level on the specified channel from the last git-tag
    general-release/bin/bin.sh -v minor@next
    
    # increment the pre-release version by the specified level from the last git-tag
    general-release/bin/bin.sh -v pre-alpha
    
    # increment the pre-release version by the specified level on the specified channel from the last git-tag
    general-release/bin/bin.sh -v pre-alpha@next
  • Validate the commit message

    general-release/bin/bin.sh validate -c .release.yml "feat: test"
  • Install the Tools: commit-linter, commit-template

    # install commit template and commit linter
    general-release/bin/bin.sh install -c .release.yml
    # of
    general-release/bin/bin.sh install -c .release.yml --commit-lint --commit-template
    
    # install commit template
    general-release/bin/bin.sh install -c .release.yml --commit-template
    
    # install commit template on the specified file
    general-release/bin/bin.sh install -c .release.yml --template ./commit-template
  • Uninstall the Tools: commit-linter, commit-template

    # uninstall commit template and commit linter
    general-release/bin/bin.sh uninstall
    # of
    general-release/bin/bin.sh uninstall --commit-lint --commit-template
    
    # uninstall commit template
    general-release/bin/bin.sh uninstall --commit-template
  • Print Usage

    general-release/bin/bin.sh -h
    general-release/bin/bin.sh deploy -h
    general-release/bin/bin.sh preview -h
    general-release/bin/bin.sh validate -h
    general-release/bin/bin.sh install -h
    general-release/bin/bin.sh uninstall -h

NodeJS

  • Set the default options in package.json with releaseConfig property
PropertyProperty TypeDescription
releaseConfig.configstringThe config file, default: .release.yml or node_modules/general-release/src/release.yml
releaseConfig.commitTemplatestringThe path of generated commit template file, default: .gitmessage
releaseConfig.toolsboolean, string, string[]Auto install/uninstall the tools: commit-template, commit-lint, default: true - true: Install/Uninstall all tools on install/uninstall general-release - false: Not install/uninstall any tools on install/uninstall general-release - string, string[]: Install/Uninstall the specified tools on install/uninstall general-release
  • e.g.

    {
      "releaseConfig": {
        "config": "config/release.yml",
        "commitTemplate": "config/commit_template",
        "tools": true
      }
    }
  • Install general-release

    npm install -g general-release
    # or
    npm install -D general-release
  • Release

    # deploy with github and npm plugin
    npx general-release -c .release.yml -p "github -f release.zip" -p npm --debug
    # or
    npx general-release deploy -c .release.yml -p "github -f release.zip" -p npm --debug
    
    # dry-run mode
    npx general-release -c .release.yml -p "github -f release.zip" -p npm --debug --dry-run
  • Preview Release

    npx general-release preview -c .release.yml --debug
    # or
    npx general-release --no-deploy -c .release.yml --debug
  • Release with the specialed version

    # release with specified version: 1.0.0
    npx general-release -v 1.0.0
    
    # release with specified version on the specified channel
    npx general-release -v 1.0.0@next
    
    # release with specified pre-release version
    npx general-release -v 1.0.0-alpha
    
    # release with specified pre-release version on the specified channel
    npx general-release -v 1.0.0-alpha@next
    
    # increment the version by the specified level from the last git-tag
    npx general-release -v minor
    
    # increment the version by the specified level on the specified channel from the last git-tag
    npx general-release -v minor@next
    
    # increment the pre-release version by the specified level from the last git-tag
    npx general-release -v pre-alpha
    
    # increment the pre-release version by the specified level on the specified channel from the last git-tag
    npx general-release -v pre-alpha@next
  • Validate the commit message

    npx general-release validate -c .release.yml "feat: test"
  • Install the Tools: commit-linter, commit-template

    # install commit template and commit linter
    npx general-release install -c .release.yml
    # of
    npx general-release install -c .release.yml --commit-lint --commit-template
    
    # install commit template
    npx general-release install -c .release.yml --commit-template
    
    # install commit template on the specified file
    npx general-release install -c .release.yml --template ./commit-template
  • Uninstall the Tools: commit-linter, commit-template

    # uninstall commit template and commit linter
    npx general-release uninstall
    # of
    npx general-release uninstall --commit-lint --commit-template
    
    # uninstall commit template
    npx general-release uninstall --commit-template
  • Print Usage

    npx general-release -h
    npx general-release deploy -h
    npx general-release preview -h
    npx general-release validate -h
    npx general-release install -h
    npx general-release uninstall -h

Plugin API

  • Usage

    general-release/bin/bin.sh -p "github -f general-release.zip --debug" -p "npm --debug" -p "coustom.sh --debug"
  • ./src/plugin.sh

    • Methods
NameTypeDescription
bootstrapfunction(...)Running the plugin, bootstrap "$@"
plugin_statefunction()Print running state of the plugin
print_usagefunction()Print usage
plugin_debugfunction(msg, ...)Print debug
plugin_infofunction(msg, ...)Print info
plugin_warnfunction(msg, ...)Print warn
plugin_errorfunction(msg, ...)Print error
plugin_exit_errorfunction(int exit_code?, msg, ...)Exit and print error
plugin_exit_erronfunction(int condition?,int exit_code?, msg, ...)Exit and print error on condition != 0
  • Extensions
NameTypeDescription
plugin_namestringThe plugin name
plugin_argfunction(opt_name, opt_value)Option parser of the plugin
plugin_initfunction(hook)Initial callback of the plugin, called before execute hook
plugin_{hook}stringCommand of the plugin hook
plugin_usagefunction()Print usage message
plugin_optionsfunction()Print plugin options
  • Plugin Context
NameTypeDescription
hookstringThe plugin hook
env_filefile pathOutput the release variables(branch, rp) on load hook
git_repostringGit repository url
branchstringBranch name
tag_prefixstringPrefix of the git-tag
prev_tagstringThe last release git-tag
tagstringRelease git-tag
versionstringRelease version
channelstringRelease channel
prereleasestringPre-release id
release_notestringRelease note
dry_run"true"Is dry run
DEBUG"true"Is debug mode
COLOR_LOG"true"Is color log mode

Plugin Hooks

Hook NameDescription
loadOn release loading, output the release variables(branch, rp) to $env_file
versionCalled after release version analyzed
before_deployCalled before deploy
deployCalled on deploy
after-deployCalled after deploy
deploy-failedCalled after deploy

How to write a custom plugin ?

#!/bin/bash

# include plugin libary
source $(dirname $BASH_SOURCE)/../lib/plugin.sh

# the plugin name
plugin_name="plugin name"

# command of the plugin hooks

plugin_load="hook_load"
plugin_version="hook_version"
plugin_before_deploy="print_state && hook_before_deploy"
plugin_deploy="hook_deploy"

# the option parser

test_option1=
test_option2=
function plugin_arg() {
	case "$1" in
	--test1)
		test_option1="$2"
		# eat 2 argument
		return 2
		;;
	--test)
		test_option2="true"
		# eat 1 argument
		return 1
		;;
	esac
	# unkown option
	return 0
}

# print the options
function plugin_options(){
  color_log "<g>  --test1                       [string] Test string option
  --test2                       [enable] Test enable option"
}

# print the plugin state
function print_state() {
	plugin_debug "Options:<g>
  test_option1                  <y>%s</>
  test_option2                  <y>%s</>" \
		"$test_option1" \
		"$test_option2"
	plugin_state
}

# initial plugin before execute hook
function plugin_init(){
	# do something ...
}

# example hook[load]
function hook_load() {
	# do something ...

	# out variables
	echo "rp=" > $env_file
}

# example hook[version]
function hook_version() {
	if [[ $version ]]; fi
		plugin_debug "the release version is $version"
	else
		plugin_debug "no release version"
	fi
	# do something ...
}

# example hook[before-deploy]
function hook_before_deploy() {
	if [[ ! $dry_run ]]; then
		# do something ...
	else
		# do something ...
	fi
}

# example hook[deploy]
function hook_deploy() {
	if [[ ! $dry_run ]]; then
		# do something ...
	else
		# do something ...
	fi
}

# bootstrap the plugin
bootstrap "$@"

Plugins

Gzip Plugin

Archive files by tar

  • Usage

    Usage
      gzip [<options>] [<path>...]
    Plugin Options
      -o,--output                   [string] Write the archive to this file(.tar.gz)
      -d,--dry-run                  [enable] Skip publishing, default: false
      --debug                       [enable] Enable debug logging, default: false
      --no-color                    [enable] Disable the color output, default: false
      -h,--help                     Print usage

NPM Plugin

Publish a npm package

  • Usage

    Usage
      npm [<options>]
    Plugin Options
      -r,--registry                 [string] NPM registry URL, default: https://registry.npmjs.org/
      -a,--access                   [string] Package access, default: public
      -t,--token                    [string] NPM auth token, default: ENV:NPM_TOKEN
      -d,--dry-run                  [enable] Skip publishing, default: false
      --debug                       [enable] Enable debug logging, default: false
      --no-color                    [enable] Disable the color output, default: false
      -h,--help                     Print usage

GitHub Plugin

Create a release at gitHub

  • Usage

    Usage
      github [<options>]
    Plugin Options
      -f,--file                     [string] Add a publish file
      -t,--token                    [string] GitHub auth token, default: ENV:GITHUB_TOKEN
      -d,--dry-run                  [enable] Skip publishing, default: false
      --debug                       [enable] Enable debug logging, default: false
      --no-color                    [enable] Disable the color output, default: false
      -h,--help                     Print usage

Appveyor Plugin

Write Build Details on Appveyor

  • Usage

    Usage
      appveyor [<options>]
    Plugin Options
      -d,--dry-run                  [enable] Skip publishing, default: false
      --debug                       [enable] Enable debug logging, default: false
      --no-color                    [enable] Disable the color output, default: false
      -h,--help                     Print usage

License

MIT

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago