-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_release_commit.sh
executable file
·134 lines (113 loc) · 3.83 KB
/
make_release_commit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# This script will auto
# 1. upgrading the @liqnft/candy-shop-types in core/sdk and @liqnft/candy-shop-sdk in core/ui if any latest.
# 2. making the commit message with updated versions of relevant packages.
#
# Usages:
# ./make_release_commit.sh
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CORE_UI_PATH=$SCRIPTPATH/core/ui
CORE_SDK_PATH=$SCRIPTPATH/core/sdk
TYPE_PKG_NAME=@liqnft/candy-shop-types
SDK_PKG_NAME=@liqnft/candy-shop-sdk
UI_PKG_NAME=@liqnft/candy-shop
cd $CORE_SDK_PATH
# Install core/type to latest if any update
yarn add $TYPE_PKG_NAME@latest --exact
# Get the core/type package version
type_pkg_info_arr=( $(yarn info $TYPE_PKG_NAME version) )
type_pkg_version=${type_pkg_info_arr[3]}
cd $CORE_UI_PATH
# Install core/sdk to latest if any update
yarn add $SDK_PKG_NAME@latest --exact
# Get the core/sdk package version
sdk_pkg_info_arr=( $(yarn info $SDK_PKG_NAME version) )
sdk_pkg_version=${sdk_pkg_info_arr[3]}
# Get the core/ui package version
ui_pkg_info_arr=( $(yarn info $UI_PKG_NAME version) )
ui_pkg_version=${ui_pkg_info_arr[3]}
echo -e "\033[33mCurrent Installed $TYPE_PKG_NAME version: $type_pkg_version\033[m"
echo -e "\033[33mCurrent Installed $SDK_PKG_NAME version: $sdk_pkg_version\033[m"
echo -e "\033[33mCurrent Installed $UI_PKG_NAME version: $ui_pkg_version\033[m"
git_file_changes_arr=( $(git status --porcelain) )
git_file_changes_arr_len=${#git_file_changes_arr[@]}
# Global variables
type_update=false
sdk_update=false
ui_update=false
make_commit_mgs() {
echo -e "\033[36mcore/type bump: $type_update\033[m"
echo -e "\033[36mcore/sdk bump: $sdk_update\033[m"
echo -e "\033[36mcore/ui bump: $ui_update\033[m"
cd $SCRIPTPATH
git add .
NEWLINE=$'\n'
commit_title="Bump core "
commit_content="${NEWLINE}"
if [[ "$type_update" = true ]]
then
commit_title="${commit_title}[types] "
type_msg="${NEWLINE}$TYPE_PKG_NAME -> $type_pkg_version"
commit_content="${commit_content}${type_msg}"
fi
if [[ "$sdk_update" = true ]]
then
commit_title="${commit_title}[sdk] "
sdk_msg="${NEWLINE}$SDK_PKG_NAME -> $sdk_pkg_version"
commit_content="${commit_content}${sdk_msg}"
fi
if [[ "$ui_update" = true ]]
then
commit_title="${commit_title}[ui] "
ui_msg="${NEWLINE}$UI_PKG_NAME -> $ui_pkg_version"
commit_content="${commit_content}${ui_msg}"
fi
commit_title="${commit_title}version"
git commit -m "${commit_title} ${commit_content}"
# Add tags
if [[ "$ui_update" = true ]]
then
commit_tag="v$ui_pkg_version"
git tag "$commit_tag"
fi
}
# Once @liqnft/candy-shop-sdk updated, core/ui will align the dependency as well.
# But it's not the bump for core/ui, need to differentiate the cases to reflect the truth.
check_ui_bump() {
cd $CORE_UI_PATH
# Check the exact diff from core/ui/package.json
git_diff_ui_arr=( $(git diff --no-ext-diff --unified=0 --exit-code -a --no-prefix package.json) )
for diff in "${git_diff_ui_arr[@]}"
do
if [[ $diff == *"version"* ]]
then
ui_update=true
fi
done
}
if [ $git_file_changes_arr_len -gt 0 ]
then
echo "File changes, making commit"
for file in "${git_file_changes_arr[@]}"
do
# check if file change patch contains target string
if [[ $file == *"core/types"* ]]
then
type_update=true
elif [[ $file == *"core/sdk"* ]]
then
sdk_update=true
elif [[ $file == *"core/ui"* ]]
then
check_ui_bump
fi
done
if [[ "$type_update" = false && "$sdk_update" = false && "$ui_update" = false ]]
then
echo -e "\033[31mUnexpected file changed, abort\033[m"
exit 0
fi
make_commit_mgs
else
echo "Nothing update"
fi