forked from disorderedmaterials/dissolve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangeversion
executable file
·274 lines (240 loc) · 8.41 KB
/
changeversion
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#!/usr/bin/env bash
# Change the version of the source code to the supplied value
# Day Suffix Function
DaySuffix() {
case $(date +%-d) in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
# Retrieve the authoritative code version from src/main/version.cpp
GetAuthoritativeVersion() {
echo $(grep '#define DISSOLVEVERSION' src/main/version.cpp | sed -e 's/#define DISSOLVEVERSION "\([0-9a-z\.]\+\).*"/\1/g')
}
# Set versions in build files
SetCodeVersion() {
# Must have new version string as argument
if [ $# == 0 ]
then
echo "Must pass version string as argument to SetWebReleaseInfo()."
exit 1
fi
# Program (main/version.h)
sed -i -e "s/#define DISSOLVEVERSION \"[0-9\.]\+\(.*\)\"/#define DISSOLVEVERSION \"$1\"\1/g" src/main/version.cpp
# Flake (flake.nix)
sed -i -e "s/version = \".*\"/version = \"$1\"/" flake.nix
# Root ./CMakeLists.txt
PARTS=($(echo $1 | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
sed -i -e "s/set(VERSION_MAJOR \"\([0-9\.]\+\)\")/set(VERSION_MAJOR \"$MAJOR\")/g" -e "s/set(VERSION_MINOR \"\([0-9a-z\.]\+\)\")/set(VERSION_MINOR \"$MINOR\")/g" -e "s/set(VERSION_PATCH \"\([0-9a-z\.]\+\)\")/set(VERSION_PATCH \"$PATCH\")/g" CMakeLists.txt
}
# Get / check code versions in build files
GetCodeVersion() {
# Program (main/version.h)
MAIN_VERSION=$(grep '#define DISSOLVEVERSION' src/main/version.cpp | sed -e 's/#define DISSOLVEVERSION "\([0-9a-z\.]\+\).*"/\1/g')
echo " version.cpp : ${MAIN_VERSION}"
if [[ ! "${MAIN_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "!!! Malformed version (or no version at all) found in version.cpp."
return 1
fi
# Flake (flake.nix)
FLAKE_VERSION=$(grep " version =" flake.nix | sed -e "s/\W*version = \"\(.*\)\";/\1/")
echo " flake.nix : ${FLAKE_VERSION}"
# Root ./CMakeLists.txt
CMAKE_MAJOR=$(grep 'set(VERSION_MAJOR' ./CMakeLists.txt | sed -e 's/set(VERSION_MAJOR \"\([0-9a-z\.]\+\)\")/\1/g')
CMAKE_MINOR=$(grep 'set(VERSION_MINOR' ./CMakeLists.txt | sed -e 's/set(VERSION_MINOR \"\([0-9a-z\.]\+\)\")/\1/g')
CMAKE_PATCH=$(grep 'set(VERSION_PATCH' ./CMakeLists.txt | sed -e 's/set(VERSION_PATCH \"\([0-9a-z\.]\+\)\")/\1/g')
CMAKE_VERSION="${CMAKE_MAJOR}.${CMAKE_MINOR}.${CMAKE_PATCH}"
echo " ./CMakeLists.txt : ${CMAKE_VERSION}"
# Check Version?
if [ $# == 1 ]
then
if [ ${MAIN_VERSION} != "$1" ]
then
echo "!!! Version mismatch in version.cpp: ${MAIN_VERSION} != $1"
return 1
fi
if [ ${FLAKE_VERSION} != "$1" ]
then
echo "!!! Version mismatch in flake.nix: ${FLAKE_VERSION} != $1"
return 1
fi
if [ ${CMAKE_VERSION} != "$1" ]
then
echo "!!! Version mismatch in CMakeLists.cpp: ${CMAKE_VERSION} != $1"
return 1
fi
fi
return 0
}
# Set web release version and date
SetWebReleaseInfo() {
# Must have new version string as argument
if [ $# == 0 ]
then
echo "Must pass version string as argument to SetWebReleaseInfo()."
exit 1
fi
# Get today's date, nicely formatted
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%A %-d${DAYSUFFIX} %B %Y")
# Set releaseVersion and releaseDat on Website (web/main.toml)
sed -i -e "s/releaseVersion = \"[0-9\.]*\"/releaseVersion = \"$1\"/g" web/main.toml
sed -i -e "s/releaseDate = \".*\"/releaseDate = \"${TODAY}\"/g" web/main.toml
}
# Get web release version and date
GetWebReleaseInfo() {
# Release version on Website (web/main.toml)
WEB_VERSION=$(grep 'releaseVersion' web/main.toml | sed -e 's/releaseVersion = "\([0-9\.]*\)"/\1/g')
WEB_DATE=$(grep 'releaseDate' web/main.toml | sed -e 's/releaseDate = "\(.*\)"/\1/g')
echo " main.toml (Version) : ${WEB_VERSION}"
echo " main.toml (Date) : ${WEB_DATE}"
# Did we get a sensible version out of the file?
if [[ ! "${WEB_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "!!! Malformed version (or no version at all) found in main.toml."
return 1
fi
# Check Version?
if [ $# == 1 ] && [ ${WEB_VERSION} != "$1" ]
then
echo "!!! Version mismatch in web/main.toml: ${WEB_VERSION} != $1"
return 1
fi
return 0
}
# Set README.md version and date
SetReadMeInfo() {
# Must have new version string as argument
if [ $# == 0 ]
then
echo "Must pass version string as argument to SetReadMeInfo()."
exit 1
fi
# Get today's date, nicely formatted
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%A %-d${DAYSUFFIX} %B %Y")
# Set the Last Release in the repository's root README.md
sed -i -e "s/Last Release: [0-9\.]*, \(.*\)_/Last Release: $1, ${TODAY}_/g" README.md
}
# Get README.md version and date
GetReadMeInfo() {
# Last Release in the repository's root README.md
README_VERSION=$(grep 'Last Release:' README.md | sed -e 's/.*Release: \([0-9\.]*\),.*/\1/g')
README_DATE=$(grep 'Last Release:' README.md | sed -e "s/.*Release: .*, \(.*\)_/\1/g")
echo " README.md (Version) : ${README_VERSION}"
echo " README.md (Date) : ${README_DATE}"
# Check Version?
if [ $# == 1 ] && [ ${README_VERSION} != "$1" ]
then
echo "!!! Version mismatch in web/main.toml: ${WEB_VERSION} != $1"
return 1
fi
return 0
}
ConsistencyCheck() {
RETURN=0
# Get authoritative source code version
SRC_VERSION=$(GetAuthoritativeVersion)
if ! GetWebReleaseInfo ${SRC_VERSION}; then RETURN=1; fi
if ! GetCodeVersion ${SRC_VERSION}; then RETURN=1; fi
exit $(( RETURN ))
}
PrintUsage() {
echo "Usage: $0 [-v] [-k] [-t] [-q] [-r X.Y.Z] [-s X.Y.Z]"
echo " -r Explicitly set release version and date in README.md"
echo " -s Set version explicitly to X.Y.Z"
echo " -v Get authoritative code version (from src/main/version.cpp)"
echo " -x Get authoritative code version (from src/main/version.cpp) with patch version set to a literal 'X'"
echo " -k Check consistency of other files with current authoritative version"
echo " -q Determine bumped version using git-cliff"
echo " -t Determine type (major, minor, patch, or none) of bumped version using git-cliff"
echo " -b Determine bumped version using git-cliff and set new authoritative version"
echo " -l Generate ChangeLog.md containing unreleased changes since last major/minor/patch release"
echo " -L Generate ChangeLog.md over the current branch history"
}
# Check for no args provided
if [ $# == 0 ]
then
PrintUsage
exit 1
fi
while getopts "r:s:vkqblLxt" opt
do
case $opt in
s) PARTS=($(echo $OPTARG | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
echo "Code and web version will be set explicitly to MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
SetCodeVersion $OPTARG
SetWebReleaseInfo $OPTARG
ConsistencyCheck
;;
r) PARTS=($(echo $OPTARG | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
echo "Release version will be set explicitly to MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
SetReadMeInfo $OPTARG
GetReadMeInfo
;;
q) git cliff --bumped-version
;;
b) CURRENT=$(GetAuthoritativeVersion)
BUMPED=$(git cliff --bumped-version)
if [ "${BUMPED}x" == "x" ]
then
echo "Error: Failed to auto-bump version."
exit 1
fi
SetCodeVersion ${BUMPED}
SetWebReleaseInfo ${BUMPED}
echo "Version auto-bumped to ${BUMPED} (from ${CURRENT})"
;;
l) git cliff --bump -u
;;
L) git cliff --bump
;;
v) GetAuthoritativeVersion
exit 0
;;
x) CURRENT=$(GetAuthoritativeVersion)
PARTS=($(echo $CURRENT | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
echo "${MAJOR}.${MINOR}.X"
exit 0
;;
k) ConsistencyCheck
;;
t) CURRENT=$(GetAuthoritativeVersion)
CURRENT_PARTS=($(echo $CURRENT | tr "." " "))
BUMPED=$(git cliff --bumped-version)
BUMPED_PARTS=($(echo $BUMPED | tr "." " "))
if [ "${CURRENT_PARTS[0]}" != "${BUMPED_PARTS[0]}" ]
then
echo "major"
elif [ "${CURRENT_PARTS[1]}" != "${BUMPED_PARTS[1]}" ]
then
echo "minor"
elif [ "${CURRENT_PARTS[2]}" != "${BUMPED_PARTS[2]}" ]
then
echo "patch"
else
echo "none"
fi
exit 0
;;
\?) PrintUsage
exit 1
;;
*) echo "Error: Extra operands given."
PrintUsage
exit 1
;;
esac
done