-
Notifications
You must be signed in to change notification settings - Fork 30
/
update_version.sh
executable file
·104 lines (91 loc) · 3.3 KB
/
update_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
#!/bin/bash -e
# Use this script to automate updating jss version.
#
# Usage: ./update_version.sh <major> <minor> <update> <phase> # (phase is optional)
#
# Explanation:
# - change_spec_version
# - Updates the spec version to the new version provided
# - commit_version_change
# - Commits that change
# - create_tag
# - Creates a tag based on the new version provided
# - create_source_tarball
# - Creates a source tarball based on the new version provided
NEXT_MAJOR=$1
NEXT_MINOR=$2
NEXT_UPDATE=$3
NEXT_PHASE=$4
if [ -z "$NEXT_PHASE" ] ; then
NEXT_VERSION=$NEXT_MAJOR.$NEXT_MINOR.$NEXT_UPDATE
else
NEXT_VERSION=$NEXT_MAJOR.$NEXT_MINOR.$NEXT_UPDATE-$NEXT_PHASE
fi
echo "New version is $NEXT_VERSION"
verify_phase() {
if [[ "$NEXT_PHASE" =~ ^(alpha|beta)[0-9]+$ ]] ; then
echo "$NEXT_PHASE is a valid phase"
elif [ -z "$NEXT_PHASE" ] ; then
echo "Empty phase"
else
echo "$NEXT_PHASE is an invalid phase, aborting"
exit 1
fi
}
change_spec_version() {
CURRENT_PHASE=$(grep "phase " jss.spec | grep -E 'alpha|beta' | awk '{print $(NF)}')
CURRENT_RELEASE_NUMBER=$(grep "release_number " jss.spec | grep -Eo '[0-9]+(\.[0-9]+)?$')
echo "Update major version to $NEXT_MAJOR"
sed -i "/major_version /c\%global major_version $NEXT_MAJOR" jss.spec
echo "Update minor version to $NEXT_MINOR"
sed -i "/minor_version /c\%global minor_version $NEXT_MINOR" jss.spec
echo "Update update version to $NEXT_UPDATE"
sed -i "/update_version /c\%global update_version $NEXT_UPDATE" jss.spec
if [[ "$CURRENT_PHASE" != "$NEXT_PHASE" ]] ; then
if [ -z "$NEXT_PHASE" ] ; then
echo "Remove phase"
sed -i "/phase /c\#global phase" jss.spec
echo "Update release_number"
sed -i "/release_number /c\%global release_number 1" jss.spec
elif [ -z "$CURRENT_PHASE" ] ; then
echo "Add phase, set to $NEXT_PHASE"
sed -i "/#global phase/c\%global phase $NEXT_PHASE" jss.spec
echo "Update release_number"
sed -i "/release_number /c\%global release_number 0.1" jss.spec
else
echo "Update phase to $NEXT_PHASE"
sed -i "/phase /c\%global phase $NEXT_PHASE" jss.spec
echo "Update release_number"
IFS='.' read -ra CRL <<< "$CURRENT_RELEASE_NUMBER"
(( CRL[1]++ ))
sed -i "/release_number /c\%global release_number ${CRL[0]}.${CRL[1]}" jss.spec
fi
fi
}
change_jss_config_version() {
if [ "$NEXT_PHASE" ] ; then
IS_BETA="1"
else
IS_BETA="0"
fi
JSS_CONFIG_VERSION="$NEXT_MAJOR $NEXT_MINOR $NEXT_UPDATE $IS_BETA"
echo "Updating jss_config_version to $JSS_CONFIG_VERSION"
sed -i "/ jss_config_version/c\ jss_config_version($JSS_CONFIG_VERSION)" cmake/JSSConfig.cmake
}
commit_version_change() {
git add jss.spec cmake/JSSConfig.cmake
git commit -m "Updating version to v$NEXT_VERSION"
}
create_tag() {
git tag v"$NEXT_VERSION"
}
create_source_tarball() {
./build.sh --source-tag=v"$NEXT_VERSION" src
}
### Perform operations
verify_phase
change_spec_version
change_jss_config_version
commit_version_change
create_tag
create_source_tarball