This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
update-version.sh
79 lines (60 loc) · 2.26 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
#!/bin/bash
BASE_VERSION=$1
BRANCH_NAME=$2
TYPE_VERSION=$3
# compare last commit of distribution repo
if [ -f 'VERSION.txt' ]; then
LAST_COMMIT=`cat VERSION.txt | sed -n 2p`
LAST_VERSION_BLOCK=`cat VERSION.txt | sed -n 1p | cut -d "." -f3`
else
LAST_COMMIT='I used to be an adventurer just like you, but then I took an arrow in the knee'
if [ ! -z "${TYPE_VERSION}" ]; then
LAST_VERSION_BLOCK="0-${TYPE_VERSION}0"
else
LAST_VERSION_BLOCK=0
fi
fi
echo "Last minor version: ${LAST_VERSION_BLOCK}"
CURRENT_COMMIT=`git rev-parse HEAD`
if [ "${CURRENT_COMMIT}" = "${LAST_COMMIT}" ]; then
echo "Nothing to update, already at the latest version"
exit 0
fi
LAST_MINOR_VERSION=`echo "${LAST_VERSION_BLOCK}" | cut -d "-" -f1`
if [ ! -z "${TYPE_VERSION}" ]; then
LAST_RELEASE_VERSION=`echo "${LAST_VERSION_BLOCK}" | grep -oP "(?<=${TYPE_VERSION}).*"`
LAST_RELEASE_VERSION=$((LAST_RELEASE_VERSION + 1))
CURRENT_VERSION_BLOCK="${LAST_MINOR_VERSION}-${TYPE_VERSION}${LAST_RELEASE_VERSION}"
else
CURRENT_VERSION_BLOCK=$((LAST_MINOR_VERSION + 1))
fi
FULL_VERSION="${BASE_VERSION}.${CURRENT_VERSION_BLOCK}"
echo "Current minor version: ${FULL_VERSION}"
# create the VERSION.txt file
{
echo $FULL_VERSION
echo `git rev-parse HEAD`
echo $BRANCH_NAME
} > VERSION.txt
# building log file
LOGS=`git log ${LAST_COMMIT}..${CURRENT_COMMIT} --oneline`
COMMITS="$( cut -d " " -f -1 <<< "$LOGS" )"
COMMITNAMES="$( cut -d " " -f 2- <<< "$LOGS" )"
COMMITS=$(tr " " "\n" <<< "$COMMITS")
mapfile -t COMMITNAMES <<< "$COMMITNAMES"
COMMITSTRING=''
MERGESTRING=''
i=0
printf "# Version $FULL_VERSION "$'\n'$'\n' >> changelogs/${BRANCH_NAME}-${BASE_VERSION}.x.md
for COMMIT in $COMMITS
do
if [[ ${COMMITNAMES[$i]} == *"Merge"* ]]; then
#we don't log them yet, but jenkins already do that
MERGESTRING="${MERGESTRING}\nclaroline/distribution@${COMMIT} - ${COMMITNAMES[$i]}"
else
NAMELINKS=`echo ${COMMITNAMES[$i]} | sed -r 's/\(#([^)]*)\).*/[#\1]\(https:\/\/github.com\/claroline\/Distribution\/pull\/\1\)/'`
printf "[${COMMIT}](https://github.com/claroline/Distribution/commit/${COMMIT}) - ${NAMELINKS} "$'\n' >> changelogs/${BRANCH_NAME}-${BASE_VERSION}.x.md
fi
i=$((i + 1))
done
printf $'\n' >> changelogs/${BRANCH_NAME}-${BASE_VERSION}.x.md