Automated deployment Tools for Git repository implemented with bash shell


Keywords
release, deploy, publish, package, version, tag, changelog, automation, ci, npm, github, appveyor, commit, commitlint
License
MIT
Install
npm install release.sh@1.0.19

Documentation

release.sh

Build Version Downloads

Automated deployment Tools for Git repository implemented with bash shell

Features

  • Release version
    • Analyze the release/pre-release version from the commits after last tag
    • Specify the release/pre-release version number (tag)
  • Generate release note
  • Generate changelog
  • Git commit, tag, push
  • Create release at GitHub (use github plugin)
  • Update package.json and publish to npm registry (use npm plugin)
  • Load CI variables from appveyor (use appveyor plugin)
  • Update appveyor build details (use appveyor plugin)
  • Custom plugin
  • Validate the commit message
  • Tools: commit template and commit linter

Git Commit Message

Each commit message consists of a header and a body. The header has a special format that includes a type, a scope and a subject:

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

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

Release Rule Configuration (yml)

tag_repo           - string:   Git repository URL, default: [auto]
                               get repository url with `git config --get remote.origin.url`
tag_prefix         - string:   Git tag prefix, default: "v"
release_note       - string:   Release Note, default: [auto]
                               analyze the commits after the last tag with the note rules defined in the configuration
changelog          - string:   Generante the changelog file, default: CHANGELOG.md
commit             - string[]: Git commit files, default: CHANGELOG.md
commit_message     - string:   Commit message, default: "chore(release): {tag} [skip ci]", format keys:
                                  version: release version
                                  channel: release channel
                               prerelease: prerelease prefix
                                      tag: git tag name
commit_note        - boolean:  Commit with release note, default: true
plugins:           - string[]: Plugins:
                               appveyor [options]
                               github [options]
                               npm [options]
                               constum.sh [options]
- branchs[]        - object[]: branch config
  - pattern        - regexp:   required, the pattern of the release branch name
  - channel        - string:   publish channel
  - prerelease     - string:   pre-release suffix
- rules[]          - object[]: release/note rules
  - type           - regexp:   required, type pattern
  - scope          - regexp:   scope pattern
  - release        - string:   release type: major | minor | patch | none, default "none"
  - note           - string:   title of the release note
  - body           - boolean:  include commit body to release note
  • The default configuration

    branchs:
      - { pattern: "^master$", channel: "latest" }
      - { pattern: "^([1-9][0-9]*)\\.(x|[1-9][0-9]*)\\.x$" }
      - { pattern: "^alpha$", channel: "alpha", prerelease: "alpha" }
    
    rules:
      - { type: "breaking", release: "major", note: "Breaking Changes" }
      - { type: "feat", release: "minor", note: "Features" }
      - { type: "fix", release: "patch", note: "Bug Fixes" }
      - { type: "security", release: "patch", note: "Security" }
      - { type: "perf", release: "patch", note: "Performance Improvements" }
      - { type: "refactor", release: "patch", note: "Code Refactoring" }
      - { type: "revert", release: "patch", note: "Reverts" }
      - { type: "docs" }
      - { type: "chore" }
      - { type: "test" }
      - { type: "style" }
      - { type: "build" }
      - { type: "ci" }
  • You can use --config or -c if you want to use another path

Usage

  • shell

    # download
    curl -L -s https://github.com/tao-zeng/release.sh/releases/download/$(curl -L -s -H 'Accept: application/json' https://github.com/tao-zeng/release.sh/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')/release-sh.zip -o release-sh.zip
    unzip -o release-sh.zip -d release-sh
    rm -f release-sh.zip
    
    # install commit template and commit linter
    sh release-sh/bin/bin.sh install
    
    # deploy
    sh release-sh/bin/bin.sh deploy -p "github -f release.zip" --debug
    # or
    sh release-sh/bin/bin.sh -p "github -f release.zip" --debug
    
    # preview release
    sh release-sh/bin/bin.sh preview -p "github -f release.zip" --debug
    # or
    sh release-sh/bin/bin.sh --no-deploy -p "github -f release.zip" --debug
    
    # validate message
    sh release-sh/bin/bin.sh validate -m "feat: test"
    
    # uninstall commit template and commit linter
    sh release-sh/bin/bin.sh uninstall
    
    # useage
    sh release-sh/bin/bin.sh -h
    sh release-sh/bin/bin.sh deploy -h
    sh release-sh/bin/bin.sh preview -h
    sh release-sh/bin/bin.sh validate -h
    sh release-sh/bin/bin.sh install -h
    sh release-sh/bin/bin.sh uninstall -h
  • nodejs

    • set the default configuration in package.json with:
    {
      "releaseConfig": {
        "config": ".release.yml", // [string] the config file, default: .release.yml, node_modules/release.sh/src/release.yml
        "tools": true, // [boolean | string | string[]] auto install/uninstall the tools: commit-template, commit-lint
        "commitTemplate": ".commit_template" // the path of generated commit template file
      }
    }
    npm install -g release.sh
    
    # install commit template and commit linter
    npx release.sh install
    
    # deploy
    npx release.sh deploy -a package.json -a CHANGELOG.md -p "github -f release.zip" -p npm —debug
    # or
    npx release.sh -a package.json -a CHANGELOG.md -p "github -f release.zip" -p npm —debug
    
    # preview release
    npx release.sh preview -a package.json -a CHANGELOG.md -p "github -f release.zip" -p npm —debug
    # or
    npx release.sh —no-deploy -a package.json -a CHANGELOG.md -p "github -f release.zip" -p npm —debug
    
    # validate message
    npx release.sh validate -m "feat: test"
    
    # uninstall commit template and commit linter
    npx release.sh uninstall
    
    # useage
    npx release.sh -h
    npx release.sh deploy -h
    npx release.sh preview -h
    npx release.sh validate -h
    npx release.sh install -h
    npx release.sh uninstall -h

Plugin API

  • useage

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

    • Methods
      • bootstrap "$@": running the plugin
    • Extensions
      • plugin_name: [string] the plugin name
      • plugin_usage: [function()] usage message of the plugin
      • plugin_arg: [function(opt_name, opt_value)] option parser of the plugin
      • plugin_init: [function(hook)] plugin initial callback
      • plugin_{hook}: [string] command of the plugin hook
    • Plugin Context
      • hook: plugin hook: load | version | before_deploy | deploy
      • env_file: out variables, on load hook
      • git_repo: get repository url
      • branch: branch name
      • tag_prefix: tag prefix
      • prev_tag: last release tag
      • tag: release tag
      • version: release version
      • channel: release channel
      • prerelease: pre-release suffix
      • release_note: release note
      • dry_run: is dry run
      • DEBUG: is debug mode
      • COLOR_LOG: is color log mode

Plugin Hooks

  • load: load release config, out variables to $env_file
  • version: called after analyzed release version
  • before_deploy: called before deploy
  • deploy: called on deploy

How to write a custom plugin ?

#!/bin/bash

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

# plugin name
plugin_name="plugin name"

# command of the plugin hook[version]

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

# command of the plugin hook

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
}

function plugin_usage(){
  color_log "<g>
  --test1                       [string] Test string option
  --test2                       [enable] Test enable option"
}

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

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[version]
function hook_before_deploy() {
	if [[ ! $dry_run ]]; then
		# do something ...
	else
		# do something ...
	fi
}

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

# bootstrap the plugin
bootstrap "$@"

Plugins

NPM Plugin

Publish Npm Package

  • Useage

    Useage
      plugins/npm.sh [<options>]
    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 useage
    

GitHub Plugin

Create release at GitHub

  • Useage

    Useage
      plugins/github.sh [<options>]
    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 useage
    

Appveyor Plugin

  • Load the environment variables on Appveyor

    • APPVEYOR_PULL_REQUEST_NUMBER
    • APPVEYOR_REPO_BRANCH
  • Write Build Details on Appveyor

  • Useage

    Useage
      plugins/appveyor.sh [<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 useage
    

License

MIT