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