Simplify the gitlab flow history

This commit is contained in:
Cotes Chung 2021-06-24 21:30:05 +08:00
parent 3ecb59deb1
commit 08ec6cd3b5

View file

@ -2,29 +2,32 @@
# #
# How does it work: # How does it work:
# #
# 1. Bump latest version number to files: # 1. Cherry pick the latest commit from default branch
# to the target release branch if the target release branch already existed.
#
# 2. Bump latest version number to the following files:
#
# - _sass/jekyll-theme-chirpy.scss # - _sass/jekyll-theme-chirpy.scss
# - _javascript/copyright # - _javascript/copyright
# - assets/js/dist/*.js (will be built by gulp later) # - assets/js/dist/*.js (will be built by gulp later)
# - jekyll-theme-chirpy.gemspec # - jekyll-theme-chirpy.gemspec
# - package.json # - package.json
# #
# 2. Create a git-tag on release branch # 3. Create a git-tag on release branch
# #
# 3. Build a RubyGems package base on the latest git-tag # 4. Build a RubyGems package base on the latest git-tag
# #
# #
# Usage: # Usage:
# #
# Switch to 'master' branch or 'X-Y-stable' branch with argument '-m', # Run on default branch, if run on other branch requires parameter '-m' (manual mode).
#` and then run this script.
# #
# #
# Requires: Git, Gulp, RubyGems # Requires: Git, Gulp, RubyGems
set -eu set -eu
manual_release=false opt_manual=false
ASSETS=( ASSETS=(
"_sass/jekyll-theme-chirpy.scss" "_sass/jekyll-theme-chirpy.scss"
@ -35,6 +38,10 @@ GEM_SPEC="jekyll-theme-chirpy.gemspec"
NODE_META="package.json" NODE_META="package.json"
DEFAULT_BRANCH="master"
_working_branch="$(git branch --show-current)"
_check_src() { _check_src() {
if [[ ! -f $1 && ! -d $1 ]]; then if [[ ! -f $1 && ! -d $1 ]]; then
echo -e "Error: Missing file \"$1\"!\n" echo -e "Error: Missing file \"$1\"!\n"
@ -48,8 +55,8 @@ check() {
exit -1 exit -1
fi fi
# ensure the current branch is 'master' or running in 'manual' mode # ensure working on default branch or running in 'manual' mode
if [[ "$(git branch --show-current)" != "master" && $manual_release == "false" ]]; then if [[ $_working_branch != $DEFAULT_BRANCH && $opt_manual == "false" ]]; then
echo "Error: This operation must be performed on the 'master' branch or '--manual' mode!" echo "Error: This operation must be performed on the 'master' branch or '--manual' mode!"
exit -1 exit -1
fi fi
@ -100,6 +107,7 @@ release() {
_version="$1" _version="$1"
_major="" _major=""
_minor="" _minor=""
_new_release_branch=false
IFS='.' read -r -a array <<< "$_version" IFS='.' read -r -a array <<< "$_version"
@ -115,7 +123,7 @@ release() {
_release_branch="$_major-$_minor-stable" _release_branch="$_major-$_minor-stable"
if $manual_release; then if $opt_manual; then
echo -e "Bump version to $_version (manual release)\n" echo -e "Bump version to $_version (manual release)\n"
bump "$_version" bump "$_version"
exit 0 exit 0
@ -123,10 +131,11 @@ release() {
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
git checkout -b "$_release_branch" git checkout -b "$_release_branch"
_new_release_branch=true
else else
git checkout "$_release_branch" git checkout "$_release_branch"
# cherry-pick the latest commit from master branch to release branch # cherry-pick the latest commit from master branch to release branch
git cherry-pick "$(git rev-parse master)" git cherry-pick "$(git rev-parse $DEFAULT_BRANCH)"
fi fi
echo -e "Bump version to $_version\n" echo -e "Bump version to $_version\n"
@ -138,10 +147,14 @@ release() {
echo -e "Build the gem pakcage for v$_version\n" echo -e "Build the gem pakcage for v$_version\n"
build_gem build_gem
# head back to master branch # head back to working branch
git checkout master git checkout $_working_branch
# cherry-pick the latest commit from release branch to master branch
git cherry-pick "$_release_branch" -x if [[ $_working_branch == $DEFAULT_BRANCH ]]; then
if $_new_release_branch; then
git merge $_release_branch
fi
fi
} }
@ -185,7 +198,7 @@ while (($#)); do
opt="$1" opt="$1"
case $opt in case $opt in
-m | --manual) -m | --manual)
manual_release=true opt_manual=true
shift shift
;; ;;
-h | --help) -h | --help)