Skip to content

Commit 4a7f33f

Browse files
committed
build(tools): improve the release script
1 parent e077d29 commit 4a7f33f

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

tools/release

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# and production branch.
99
#
1010
#
11-
# Usage: run on main branch or the patch branch
11+
# Usage: run on the default, release or the patch branch
1212
#
1313
# Requires: Git, NPM and RubyGems
1414

@@ -18,8 +18,7 @@ opt_pre=false # preview mode option
1818

1919
working_branch="$(git branch --show-current)"
2020

21-
# AKA the default branch, main/master branch
22-
STAGING_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
21+
DEFAULT_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
2322

2423
PROD_BRANCH="production"
2524

@@ -65,15 +64,16 @@ _check_cli() {
6564
}
6665

6766
_check_git() {
68-
# ensure nothing is uncommitted
67+
# ensure that changes have been committed
6968
if [[ -n $(git status . -s) ]]; then
7069
echo "> Abort: Commit the staged files first, and then run this tool again."
7170
exit 1
7271
fi
7372

74-
# ensure the working branch is the default/patch branch
75-
if [[ $working_branch != "$STAGING_BRANCH" && $working_branch != hotfix/* ]]; then
76-
echo "> Abort: Please run on the $STAGING_BRANCH branch or a patch branche."
73+
if [[ $working_branch != "$DEFAULT_BRANCH" &&
74+
$working_branch != hotfix/* &&
75+
$working_branch != "$PROD_BRANCH" ]]; then
76+
echo "> Abort: Please run on the default, release or patch branch."
7777
exit 1
7878
fi
7979
}
@@ -101,14 +101,16 @@ check() {
101101
_check_node_packages
102102
}
103103

104-
# auto-generate a new version number to the file 'package.json' and
104+
# Auto-generate a new version number to the file 'package.json'
105105
bump_node() {
106+
bump="standard-version -i $CHANGE_LOG"
107+
106108
if $opt_pre; then
107-
standard-version -i "$CHANGE_LOG" -p rc
108-
else
109-
standard-version -i "$CHANGE_LOG"
109+
bump="$bump -p rc"
110110
fi
111111

112+
eval "$bump"
113+
112114
# Change heading of Patch version to heading level 2 (a bug from `standard-version`)
113115
sed -i "s/^### \[/## \[/g" "$CHANGE_LOG"
114116
# Replace multiple empty lines with a single empty line
@@ -117,29 +119,34 @@ bump_node() {
117119

118120
## Bump new version to gem config file
119121
bump_gem() {
120-
sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$1/" "$GEM_SPEC"
122+
_ver="$1"
123+
124+
if $opt_pre; then
125+
_ver="${1/-/.}"
126+
fi
127+
128+
sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$_ver/" "$GEM_SPEC"
121129
}
122130

123-
# Update the git branches, create a new tag, and then build the gem package.
124-
release() {
131+
# Creates a new tag on the production branch with the given version number.
132+
# Also commits the changes and merges the production branch into the default branch.
133+
branch() {
125134
_version="$1" # X.Y.Z
126-
_latest_commit="$(git rev-parse HEAD)"
135+
136+
git add .
137+
git commit -m "chore(release): $_version"
127138

128139
# Create a new tag on production branch
129140
echo -e "> Create tag v$_version\n"
130141
git tag "v$_version"
131142

132-
git checkout "$STAGING_BRANCH"
143+
git checkout "$DEFAULT_BRANCH"
144+
git merge --no-ff --no-edit "$PROD_BRANCH"
133145

134146
if [[ $working_branch == hotfix/* ]]; then
135-
git merge --no-ff --no-edit "$working_branch"
136147
# delete the patch branch
137148
git branch -D "$working_branch"
138149
fi
139-
140-
# cherry-pick the latest commit from production branch to default branch
141-
git cherry-pick "$_latest_commit"
142-
143150
}
144151

145152
## Build a gem package
@@ -164,7 +171,7 @@ build_gem() {
164171
main() {
165172
check
166173

167-
if [[ $opt_pre = false ]]; then
174+
if [[ $opt_pre = false && $working_branch != "$PROD_BRANCH" ]]; then
168175
git checkout "$PROD_BRANCH"
169176
git merge --no-ff --no-edit "$working_branch"
170177
fi
@@ -175,16 +182,12 @@ main() {
175182

176183
bump_gem "$_version"
177184

178-
echo -e "> Build the gem package for v$_version\n"
179-
180185
if [[ $opt_pre = false ]]; then
181-
echo -e "> Bumped version number to $_version\n"
182-
git add .
183-
git commit -m "chore(release): $_version"
184-
185-
release "$_version"
186+
branch "$_version"
186187
fi
187188

189+
echo -e "> Build the gem package for v$_version\n"
190+
188191
build_gem
189192
}
190193

0 commit comments

Comments
 (0)