-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump-version.sh
executable file
·71 lines (61 loc) · 1.86 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
#!/usr/bin/env bash
# Most part taken from https://github.com/nouchka/faas-shell-semver/blob/master/increment_version.sh
set -e
# Find the current version
INIT_VERSION=$(cat wpforms-epfl-payonline.php | grep '* Version:' | awk '{print $3}')
# Parse the version number
VERSION_ARRAY=( ${INIT_VERSION//./ } )
if [ ${#VERSION_ARRAY[@]} -ne 3 ]
then
echo "Please check the version number"
exit 1
fi
# Check if the version get any special, e.g. -alpha or -rc
VERSION_SPECIAL=(${VERSION_ARRAY[2]//-/ })
if [ ! -z ${VERSION_SPECIAL[1]} ]
then
echo "This script does not handle special, '-${VERSION_SPECIAL[1]}' will be removed"
VERSION_ARRAY[2]=${VERSION_SPECIAL[0]}
fi
# Upgrade the version, according to args
while getopts ":Mmp" OPTIONS
do
case $OPTIONS in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done
# Increment version numbers as requested.
if [ ! -z $major ]
then
((++VERSION_ARRAY[0]))
VERSION_ARRAY[1]=0
VERSION_ARRAY[2]=0
fi
if [ ! -z $minor ]
then
((++VERSION_ARRAY[1]))
VERSION_ARRAY[2]=0
fi
if [ ! -z $patch ]
then
((++VERSION_ARRAY[2]))
fi
NEWVERSION="${VERSION_ARRAY[0]}.${VERSION_ARRAY[1]}.${VERSION_ARRAY[2]}"
echo -e "You are about to change the version from \e[34m$INIT_VERSION\e[39m to \033[1m\e[93m$NEWVERSION\e[39m\033[0m"
read -p "Are you sure? [Yy]: " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Find the line in the WordPress header
LINE=$(cat wpforms-epfl-payonline.php | grep '* Version:')
# Replace the version in the specified line
sed -i.bak "/$LINE/ s/$INIT_VERSION/$NEWVERSION/g" wpforms-epfl-payonline.php
# Find the line in the file
LINE=$(cat wpforms-epfl-payonline.php | grep 'WPFORMS_EPFL_PAYONLINE_VERSION')
# Replace the version in the specified line
sed -i.bak "/$LINE/ s/$INIT_VERSION/$NEWVERSION/g" wpforms-epfl-payonline.php
else
echo "Aborted"
fi