forked from cinchapi/concourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.sh
executable file
·65 lines (61 loc) · 1.82 KB
/
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
#!/usr/bin/env bash
#################################################
### Script to get or set the current version ###
#################################################
BASE_VERSION_FILE=".version"
JENKINS_HOME="/opt/jenkins"
if [ -w $JENKINS_HOME ]; then
COUNTER_FILE="$JENKINS_HOME/.counter"
else
COUNTER_FILE=".counter"
fi
if [ -z "$1" ] ; then
VERSION=`cat $BASE_VERSION_FILE`
BRANCH=`git rev-parse --abbrev-ref HEAD`
COMMIT=`git rev-parse HEAD | cut -c1-10`
# Get counter value
if [ ! -f $COUNTER_FILE ] ; then
echo 0 > $COUNTER_FILE
fi
COUNTER=`cat $COUNTER_FILE`
((COUNTER++))
echo $COUNTER > $COUNTER_FILE
VERSION=$VERSION.$COUNTER
case $BRANCH in
develop )
EXTRA="-SNAPSHOT"
;;
feature* )
IFS='/'
PARTS=( $BRANCH )
EXTRA="-${PARTS[1]}"
EXTRA=`echo $EXTRA | tr '[:lower:]' '[:upper:]'`
;;
release* )
EXTRA=""
;;
* )
# At this point we do not need to refer
# to any commit hash since we'll have a
# tag that represents the overall release
EXTRA=""
;;
esac
echo $VERSION$EXTRA
else
NEW_VERSION=$1
if [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]$ ]] ; then
echo $NEW_VERSION > $BASE_VERSION_FILE
rm $COUNTER_FILE
sed -i '' -E "s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" README.md
sed -i '' -E "s/[0-9]+\.[0-9]+\.[0-9]+/$NEW_VERSION/g" concourse-driver-java/README.md
sed -i '' -E "s/pom.version = '[0-9]+\.[0-9]+\.[0-9]'+/pom.version = '$NEW_VERSION'/g" concourse-driver-java/build.gradle
sed -i '' -E "s/pom.version = '[0-9]+\.[0-9]+\.[0-9]-SNAPSHOT'+/pom.version = '$NEW_VERSION-SNAPSHOT'/g" concourse-driver-java/build.gradle
sed -i '' -E "s/version='[0-9]+\.[0-9]+\.[0-9]'+/version='$NEW_VERSION'/g" concourse-driver-python/setup.py
echo "The version has been set to $NEW_VERSION"
else
echo "Please specify a valid version <major>.<minor>.<patch>"
exit 1
fi
fi
exit 0