forked from codestates/pacman-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.sh
executable file
·158 lines (126 loc) · 3.74 KB
/
bump_version.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
#region globalvars
option=$1
abort=false
currentVersion=''
newVersion=''
currentDateTime=$(date +"%Y-%m-%d %T")
currentDate=$(date +"%Y-%m-%d")
#region functions
function showHelp {
echo 'Parameter invalid / missing.'
echo ''
echo 'usage:'
echo ''
echo ' bump_version [patch|minor|major]'
echo ''
}
function checkParameters {
# check if parameter provided
if [ -z $option ];
then
showHelp
abort=true
else
case $option in
patch)
# echo "patch"
;;
minor)
# echo "minor"
;;
major)
# echo "major"
;;
*)
showHelp
abort=true
return
;;
esac
echo "bump ${option} version"
fi
}
# use package.json as the source of truth
function read_current_version {
currentVersion=$(echo "$var1" | (grep version package.json | sed 's/.*"version": "\(.*\)".*/\1/'))
echo "currentVersion=${currentVersion}"
}
function get_new_version {
local currentMajor=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $1}'))
local currentMinor=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $2}'))
local currentPatch=$(echo "$var1" | (echo "${currentVersion}" | awk -F'.' '{print $3}'))
echo "${currentMajor} ${currentMinor} ${currentPatch}"
case $option in
patch)
let "newPatch = $currentPatch + 1"
newVersion="${currentMajor}.${currentMinor}.${newPatch}"
echo "newVersion=${newVersion}"
;;
minor)
let "newMinor = $currentMinor + 1"
newVersion="${currentMajor}.${newMinor}.0"
echo "newVersion=${newVersion}"
;;
major)
let "newMajor = $currentMajor + 1"
newVersion="${newMajor}.0.0"
echo "newVersion=${newVersion}"
;;
esac
}
function search_replace_in_file {
local file=$1
local search=$2
local replace=$3
sed -i "" "s/${search}/${replace}/g" $file
}
function write_new_version {
echo ""
echo "Update files to ${newVersion} (${currentDateTime}):"
echo " package.json"
local line="\"version\": \".*\""
local rep="\"version\": \"${newVersion}\""
sed -i "" "s/${line}/${rep}/g" package.json
# in package-lock.json we only want to replace the very first occurence
echo " package-lock.json"
sed -e "/${line}/{s//${rep}/;:a" -e '$!N;$!ba' -e '}' package-lock.json > tmp && mv tmp package-lock.json
# TODO: update last_update
echo " web-app-manifest.json"
sed -i "" "s/${line}/${rep}/g" web-app-manifest.json
# TODO: update last_update
echo " manifest.json"
sed -i "" "s/${line}/${rep}/g" manifest.json
# TODO: update last_update
echo " pacman-canvas.webapp"
sed -i "" "s/${line}/${rep}/g" pacman-canvas.webapp
echo " cache.manifest"
local line="# Pacman .*"
local rep="# Pacman ${newVersion} ${currentDateTime}"
sed -i "" "s/${line}/${rep}/g" cache.manifest
echo " index.htm"
local line="<span class=\"app-version\">.*<\/span>"
local rep="<span class=\"app-version\">${newVersion} (${currentDate})<\/span>"
sed -i "" "s/${line}/${rep}/g" index.htm
echo ""
echo "All files up to date. New Version ${newVersion} (${currentDateTime})."
echo "Don't forget to update README.md and to set the git tag."
}
function run {
# local option="${1}"
echo "run ${option}"
checkParameters
if [[ ${abort} == true ]];
then
return
fi
echo "bump version $option"
read_current_version
get_new_version
# TODO: user confirmation
write_new_version
}
#endregion
#region main
run
#endregion