forked from disorderedmaterials/dissolve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeversion
executable file
·212 lines (185 loc) · 7.17 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
#!/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
}
usage() {
echo "Usage: $0 <TARGET> [-r] [-s X.Y.Z]"
echo " -r Calculate new version (only on release branch)"
echo " -s Set version explicitly to X.Y.Z"
echo ""
echo "TARGET is one of: code - change version numbering in code, and installer and packaging scripts"
echo " release - change release version value on web and date in README.md"
echo " develop - change development version value on web"
echo ""
echo "If no options are specified the default behaviour is to print current versions across relevant files."
}
# Check for no args provided
if [ $# == 0 ]
then
usage
exit 1
fi
# Get target type and shift to next option
TYPE=$1
shift
if [ "$TYPE" != "code" ] && [ "$TYPE" != "release" ] && [ "$TYPE" != "develop" ]
then
echo "Invalid target '${TYPE}' given (must be 'code', 'release', 'develop'"
exit 1
fi
# Get current version number from correct target
if [ "$TYPE" == "code" ]
then
CURRENT_VERSION=$(grep '#define DISSOLVEVERSION' src/main/version.cpp | sed -e 's/#define DISSOLVEVERSION "\([0-9a-z\.]\+\).*"/\1/g')
elif [ "$TYPE" == "release" ]
then
CURRENT_VERSION=$(grep 'releaseVersion' web/main.toml | sed -e 's/releaseVersion = "\([0-9\.]*\)"/\1/g')
else
CURRENT_VERSION=$(grep 'devVersion' web/main.toml | sed -e 's/devVersion = "\([0-9\.]*\)"/\1/g')
fi
PARTS=($(echo $CURRENT_VERSION | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
CHECK="true"
echo "Current major version (${TYPE}) is : ${MAJOR}"
echo "Current minor version (${TYPE}) is : ${MINOR}"
echo "Current patch version (${TYPE}) is : ${PATCH}"
while getopts ":rs:" opt
do
case $opt in
s) MAJOR=$(echo $OPTARG | cut -f1 -d.)
MINOR=$(echo $OPTARG | cut -f2 -d.)
PATCH=$(echo $OPTARG | cut -f3 -d.)
CHECK="false"
echo "Version will be set explicitly to MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
;;
r) BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" != "Release" ]
then
echo "Version number can only be auto-calculated on the Release branch"
exit 1
fi
# Get next version number from git-cliff
PARTS=($(git cliff --bumped-version | tr "." " "))
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
echo "Version will calculated to be MAJOR=$MAJOR MINOR=$MINOR PATCH=$PATCH"
# Update Changelog
git cliff --bump v1.3.3..HEAD > ChangeLog.md
;;
\?) usage
exit 1
;;
*) echo "Error: Extra operands given."
usage
exit 1
;;
esac
done
#########################################
# Code / Installer / Packaging Versions #
#########################################
if [ "$TYPE" = "code" ]
then
# Program (main/version.h)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/#define DISSOLVEVERSION \"[0-9\.]\+\(.*\)\"/#define DISSOLVEVERSION \"$MAJOR.$MINOR.$PATCH\"\1/g" src/main/version.cpp
fi
echo -n " version.cpp (Program Version) : "
grep '#define DISSOLVEVERSION' src/main/version.cpp | sed -e 's/#define DISSOLVEVERSION "\([0-9a-z\.]\+\).*"/\1/g'
# Flake (flake.nix)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/version = \".*\"/version = \"$MAJOR.$MINOR.$PATCH\"/" flake.nix
fi
echo -n " flake.nix (Program Version) : "
grep " version =" flake.nix | sed -e "s/\W*version = \"\(.*\)\";/\1/"
# ./CMakeLists.txt
if [ "$CHECK" = "false" ]
then
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
fi
echo -n " ./CMakeLists.txt (Major Version) : "
grep 'set(VERSION_MAJOR' ./CMakeLists.txt | sed -e 's/set(VERSION_MAJOR \"\([0-9a-z\.]\+\)\")/\1/g'
echo -n " (Minor Version) : "
grep 'set(VERSION_MINOR' ./CMakeLists.txt | sed -e 's/set(VERSION_MINOR \"\([0-9a-z\.]\+\)\")/\1/g'
echo -n " (Patch Version) : "
grep 'set(VERSION_PATCH' ./CMakeLists.txt | sed -e 's/set(VERSION_PATCH \"\([0-9a-z\.]\+\)\")/\1/g'
# Windows build files
if [ "$CHECK" = "false" ]
then
sed -i -e "s/#define MyAppVersion \"[0-9\.]*\"/#define MyAppVersion \"$MAJOR.$MINOR.$PATCH\"/g" -e "s/OutputBaseFilename=Dissolve-GUI-[0-9\.]*-Win64/OutputBaseFilename=Dissolve-GUI-$MAJOR.$MINOR.$PATCH-Win64/g" ci/windows/dissolve-gui.iss
fi
echo -n " dissolve-gui.iss (Program Version) : "
grep 'define MyAppVersion' ci/windows/dissolve-gui.iss | sed -e 's/#define MyAppVersion \"\([0-9\.]*\)\"/\1/g'
echo -n " dissolve-gui.iss (Output Filename) : "
grep 'OutputBaseFilename' ci/windows/dissolve-gui.iss | sed -e 's/OutputBaseFilename=Dissolve-GUI-\([0-9\.]*\)-Win64/\1/g'
fi
##########################
# Website Version / Date #
##########################
if [ "$TYPE" = "release" ]
then
# Website (web/main.toml)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/releaseVersion = \"[0-9\.]*\"/releaseVersion = \"$MAJOR.$MINOR.$PATCH\"/g" web/main.toml
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%-d${DAYSUFFIX} %B %Y")
sed -i -e "s/releaseDate = \".*\"/releaseDate = \"${TODAY}\"/g" web/main.toml
fi
echo -n " main.toml (Release Version) : "
grep 'releaseVersion' web/main.toml | sed -e 's/releaseVersion = "\([0-9\.]*\)"/\1/g'
echo -n " main.toml (Release Date) : "
grep 'releaseDate' web/main.toml | sed -e 's/releaseDate = "\(.*\)"/\1/g'
# Website (web/docs.toml)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/releaseVersion = \"[0-9\.]*\"/releaseVersion = \"$MAJOR.$MINOR.$PATCH\"/g" web/docs.toml
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%-d${DAYSUFFIX} %B %Y")
sed -i -e "s/releaseDate = \".*\"/releaseDate = \"${TODAY}\"/g" web/docs.toml
fi
echo -n " docs.toml (Release Version) : "
grep 'releaseVersion' web/docs.toml | sed -e 's/releaseVersion = "\([0-9\.]*\)"/\1/g'
echo -n " docs.toml (Release Date) : "
grep 'releaseDate' web/docs.toml | sed -e 's/releaseDate = "\(.*\)"/\1/g'
fi
if [ "$TYPE" = "develop" ]
then
# Website (web/main.toml)
if [ "$CHECK" = "false" ]
then
sed -i -e "s/devVersion = \"[0-9\.]*\"/devVersion = \"$MAJOR.$MINOR.$PATCH\"/g" web/main.toml
fi
echo -n " main.toml (Develop Version) : "
grep 'devVersion' web/main.toml | sed -e 's/devVersion = "\([0-9\.]*\)"/\1/g'
fi
#############
# README.md #
#############
if [ "$TYPE" = "release" ]
then
# README.md
if [ "$CHECK" = "false" ]
then
DAYSUFFIX=$(DaySuffix)
TODAY=$(date "+%A %-d${DAYSUFFIX} %B %Y")
sed -i -e "s/Last Release: [0-9\.]*, \(.*\)_/Last Release: $MAJOR.$MINOR.$PATCH, ${TODAY}_/g" README.md
fi
echo -n " README.md (Release Version) : "
grep 'Last Release:' README.md | sed -e 's/.*Release: \([0-9\.]*\),.*/\1/g'
echo -n " README.md (Release Date) : "
grep 'Last Release:' README.md | sed -e "s/.*Release: .*, \(.*\)_/\1/g"
fi
exit 0