Skip to content

Commit 5f31fbc

Browse files
committed
Enhance versioning tools
1 parent 4986db1 commit 5f31fbc

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

tools/bump.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,22 @@ main() {
8585

8686
echo "Input a version number (hint: latest version is ${_latest_tag:1})"
8787

88-
read _version
88+
read -p "> " _version
8989

90-
if [[ $_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]$ ]]; then
90+
[[ $_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]$ ]] ||
91+
(
92+
echo "Error: Illegal version number: '$_version'"
93+
exit 1
94+
)
9195

92-
if git tag --list | egrep -q "^v$_version$"; then
93-
echo "Error: version '$_version' already exists"
94-
exit -1
95-
fi
96-
97-
echo -e "Bump version to $_version\n"
98-
bump "$_version"
99-
100-
else
101-
102-
echo "Error: Illegal version number: '$_version'"
96+
if git tag --list | egrep -q "^v$_version$"; then
97+
echo "Error: version '$_version' already exists"
98+
exit 1
10399
fi
104100

101+
echo -e "Bump version to $_version\n"
102+
bump "$_version"
103+
105104
}
106105

107106
main

tools/release.sh

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ set -eu
1616

1717
GEM_SPEC="jekyll-theme-chirpy.gemspec"
1818

19+
opt_pre=false
20+
21+
help() {
22+
echo "A tool to release new version Chirpy gem"
23+
echo
24+
echo "Usage:"
25+
echo
26+
echo " bash ./tools/release.sh [options]"
27+
echo
28+
echo "Options:"
29+
echo " -p, --preview Enable preview mode, only pakcage, and will not modify the branches"
30+
echo " -h, --help Print this information."
31+
}
32+
1933
check() {
2034
if [[ -n $(git status . -s) ]]; then
2135
echo "Error: Commit unstaged files first, and then run this tool againt."
@@ -43,19 +57,22 @@ release() {
4357
_version="$(grep "spec.version" jekyll-theme-chirpy.gemspec | sed 's/.*= "//;s/".*//')" # X.Y.Z
4458
_release_branch="release/${_version%.*}"
4559

46-
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
47-
# create a new release branch
48-
git checkout -b "$_release_branch"
49-
else
50-
# cherry-pick the latest commit from default branch to release branch
51-
_last_commit="$(git rev-parse "$_default_branch")"
52-
git checkout "$_release_branch"
53-
git cherry-pick "$_last_commit" -m 1
54-
fi
60+
if [[ $opt_pre = "false" ]]; then
61+
# Modify the GitLab release branches
62+
if [[ -z $(git branch -v | grep "$_release_branch") ]]; then
63+
# create a new release branch
64+
git checkout -b "$_release_branch"
65+
else
66+
# cherry-pick the latest commit from default branch to release branch
67+
_last_commit="$(git rev-parse "$_default_branch")"
68+
git checkout "$_release_branch"
69+
git cherry-pick "$_last_commit" -m 1
70+
fi
5571

56-
# create new tag
57-
echo -e "Create tag v$_version\n"
58-
git tag "v$_version"
72+
# Create a new tag
73+
echo -e "Create tag v$_version\n"
74+
git tag "v$_version"
75+
fi
5976

6077
# build a gem package
6178
echo -e "Build the gem pakcage for v$_version\n"
@@ -70,4 +87,23 @@ main() {
7087
release
7188
}
7289

90+
while (($#)); do
91+
opt="$1"
92+
case $opt in
93+
-p | --preview)
94+
opt_pre=true
95+
shift
96+
;;
97+
-h | --help)
98+
help
99+
exit 0
100+
;;
101+
*)
102+
# unknown option
103+
help
104+
exit 1
105+
;;
106+
esac
107+
done
108+
73109
main

0 commit comments

Comments
 (0)