From 5f31fbcf723869f9fcd0c193e7173068928daa0a Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 14 Feb 2022 23:59:17 +0800 Subject: [PATCH] Enhance versioning tools --- tools/bump.sh | 25 ++++++++++---------- tools/release.sh | 60 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/tools/bump.sh b/tools/bump.sh index 8d2b6f6..0824bc8 100755 --- a/tools/bump.sh +++ b/tools/bump.sh @@ -85,23 +85,22 @@ main() { echo "Input a version number (hint: latest version is ${_latest_tag:1})" - read _version + read -p "> " _version - if [[ $_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]$ ]]; then + [[ $_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]$ ]] || + ( + echo "Error: Illegal version number: '$_version'" + exit 1 + ) - if git tag --list | egrep -q "^v$_version$"; then - echo "Error: version '$_version' already exists" - exit -1 - fi - - echo -e "Bump version to $_version\n" - bump "$_version" - - else - - echo "Error: Illegal version number: '$_version'" + if git tag --list | egrep -q "^v$_version$"; then + echo "Error: version '$_version' already exists" + exit 1 fi + echo -e "Bump version to $_version\n" + bump "$_version" + } main diff --git a/tools/release.sh b/tools/release.sh index 00a363a..a067141 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -16,6 +16,20 @@ set -eu GEM_SPEC="jekyll-theme-chirpy.gemspec" +opt_pre=false + +help() { + echo "A tool to release new version Chirpy gem" + echo + echo "Usage:" + echo + echo " bash ./tools/release.sh [options]" + echo + echo "Options:" + echo " -p, --preview Enable preview mode, only pakcage, and will not modify the branches" + echo " -h, --help Print this information." +} + check() { if [[ -n $(git status . -s) ]]; then echo "Error: Commit unstaged files first, and then run this tool againt." @@ -43,19 +57,22 @@ release() { _version="$(grep "spec.version" jekyll-theme-chirpy.gemspec | sed 's/.*= "//;s/".*//')" # X.Y.Z _release_branch="release/${_version%.*}" - if [[ -z $(git branch -v | grep "$_release_branch") ]]; then - # create a new release branch - git checkout -b "$_release_branch" - else - # cherry-pick the latest commit from default branch to release branch - _last_commit="$(git rev-parse "$_default_branch")" - git checkout "$_release_branch" - git cherry-pick "$_last_commit" -m 1 - fi + if [[ $opt_pre = "false" ]]; then + # Modify the GitLab release branches + if [[ -z $(git branch -v | grep "$_release_branch") ]]; then + # create a new release branch + git checkout -b "$_release_branch" + else + # cherry-pick the latest commit from default branch to release branch + _last_commit="$(git rev-parse "$_default_branch")" + git checkout "$_release_branch" + git cherry-pick "$_last_commit" -m 1 + fi - # create new tag - echo -e "Create tag v$_version\n" - git tag "v$_version" + # Create a new tag + echo -e "Create tag v$_version\n" + git tag "v$_version" + fi # build a gem package echo -e "Build the gem pakcage for v$_version\n" @@ -70,4 +87,23 @@ main() { release } +while (($#)); do + opt="$1" + case $opt in + -p | --preview) + opt_pre=true + shift + ;; + -h | --help) + help + exit 0 + ;; + *) + # unknown option + help + exit 1 + ;; + esac +done + main