build(tools): improve the release script
This commit is contained in:
parent
e077d2911d
commit
4a7f33f7bb
1 changed files with 32 additions and 29 deletions
|
@ -8,7 +8,7 @@
|
||||||
# and production branch.
|
# and production branch.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Usage: run on main branch or the patch branch
|
# Usage: run on the default, release or the patch branch
|
||||||
#
|
#
|
||||||
# Requires: Git, NPM and RubyGems
|
# Requires: Git, NPM and RubyGems
|
||||||
|
|
||||||
|
@ -18,8 +18,7 @@ opt_pre=false # preview mode option
|
||||||
|
|
||||||
working_branch="$(git branch --show-current)"
|
working_branch="$(git branch --show-current)"
|
||||||
|
|
||||||
# AKA the default branch, main/master branch
|
DEFAULT_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
|
||||||
STAGING_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
|
|
||||||
|
|
||||||
PROD_BRANCH="production"
|
PROD_BRANCH="production"
|
||||||
|
|
||||||
|
@ -65,15 +64,16 @@ _check_cli() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_check_git() {
|
_check_git() {
|
||||||
# ensure nothing is uncommitted
|
# ensure that changes have been committed
|
||||||
if [[ -n $(git status . -s) ]]; then
|
if [[ -n $(git status . -s) ]]; then
|
||||||
echo "> Abort: Commit the staged files first, and then run this tool again."
|
echo "> Abort: Commit the staged files first, and then run this tool again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ensure the working branch is the default/patch branch
|
if [[ $working_branch != "$DEFAULT_BRANCH" &&
|
||||||
if [[ $working_branch != "$STAGING_BRANCH" && $working_branch != hotfix/* ]]; then
|
$working_branch != hotfix/* &&
|
||||||
echo "> Abort: Please run on the $STAGING_BRANCH branch or a patch branche."
|
$working_branch != "$PROD_BRANCH" ]]; then
|
||||||
|
echo "> Abort: Please run on the default, release or patch branch."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -101,14 +101,16 @@ check() {
|
||||||
_check_node_packages
|
_check_node_packages
|
||||||
}
|
}
|
||||||
|
|
||||||
# auto-generate a new version number to the file 'package.json' and
|
# Auto-generate a new version number to the file 'package.json'
|
||||||
bump_node() {
|
bump_node() {
|
||||||
|
bump="standard-version -i $CHANGE_LOG"
|
||||||
|
|
||||||
if $opt_pre; then
|
if $opt_pre; then
|
||||||
standard-version -i "$CHANGE_LOG" -p rc
|
bump="$bump -p rc"
|
||||||
else
|
|
||||||
standard-version -i "$CHANGE_LOG"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
eval "$bump"
|
||||||
|
|
||||||
# Change heading of Patch version to heading level 2 (a bug from `standard-version`)
|
# Change heading of Patch version to heading level 2 (a bug from `standard-version`)
|
||||||
sed -i "s/^### \[/## \[/g" "$CHANGE_LOG"
|
sed -i "s/^### \[/## \[/g" "$CHANGE_LOG"
|
||||||
# Replace multiple empty lines with a single empty line
|
# Replace multiple empty lines with a single empty line
|
||||||
|
@ -117,29 +119,34 @@ bump_node() {
|
||||||
|
|
||||||
## Bump new version to gem config file
|
## Bump new version to gem config file
|
||||||
bump_gem() {
|
bump_gem() {
|
||||||
sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$1/" "$GEM_SPEC"
|
_ver="$1"
|
||||||
|
|
||||||
|
if $opt_pre; then
|
||||||
|
_ver="${1/-/.}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$_ver/" "$GEM_SPEC"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update the git branches, create a new tag, and then build the gem package.
|
# Creates a new tag on the production branch with the given version number.
|
||||||
release() {
|
# Also commits the changes and merges the production branch into the default branch.
|
||||||
|
branch() {
|
||||||
_version="$1" # X.Y.Z
|
_version="$1" # X.Y.Z
|
||||||
_latest_commit="$(git rev-parse HEAD)"
|
|
||||||
|
git add .
|
||||||
|
git commit -m "chore(release): $_version"
|
||||||
|
|
||||||
# Create a new tag on production branch
|
# Create a new tag on production branch
|
||||||
echo -e "> Create tag v$_version\n"
|
echo -e "> Create tag v$_version\n"
|
||||||
git tag "v$_version"
|
git tag "v$_version"
|
||||||
|
|
||||||
git checkout "$STAGING_BRANCH"
|
git checkout "$DEFAULT_BRANCH"
|
||||||
|
git merge --no-ff --no-edit "$PROD_BRANCH"
|
||||||
|
|
||||||
if [[ $working_branch == hotfix/* ]]; then
|
if [[ $working_branch == hotfix/* ]]; then
|
||||||
git merge --no-ff --no-edit "$working_branch"
|
|
||||||
# delete the patch branch
|
# delete the patch branch
|
||||||
git branch -D "$working_branch"
|
git branch -D "$working_branch"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# cherry-pick the latest commit from production branch to default branch
|
|
||||||
git cherry-pick "$_latest_commit"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Build a gem package
|
## Build a gem package
|
||||||
|
@ -164,7 +171,7 @@ build_gem() {
|
||||||
main() {
|
main() {
|
||||||
check
|
check
|
||||||
|
|
||||||
if [[ $opt_pre = false ]]; then
|
if [[ $opt_pre = false && $working_branch != "$PROD_BRANCH" ]]; then
|
||||||
git checkout "$PROD_BRANCH"
|
git checkout "$PROD_BRANCH"
|
||||||
git merge --no-ff --no-edit "$working_branch"
|
git merge --no-ff --no-edit "$working_branch"
|
||||||
fi
|
fi
|
||||||
|
@ -175,16 +182,12 @@ main() {
|
||||||
|
|
||||||
bump_gem "$_version"
|
bump_gem "$_version"
|
||||||
|
|
||||||
echo -e "> Build the gem package for v$_version\n"
|
|
||||||
|
|
||||||
if [[ $opt_pre = false ]]; then
|
if [[ $opt_pre = false ]]; then
|
||||||
echo -e "> Bumped version number to $_version\n"
|
branch "$_version"
|
||||||
git add .
|
|
||||||
git commit -m "chore(release): $_version"
|
|
||||||
|
|
||||||
release "$_version"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -e "> Build the gem package for v$_version\n"
|
||||||
|
|
||||||
build_gem
|
build_gem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue