-
Notifications
You must be signed in to change notification settings - Fork 148
/
release_notes.sh
executable file
·134 lines (103 loc) · 3.61 KB
/
release_notes.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
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
#!/bin/bash
source ./_common.sh
function check_usage {
if [ ! -n "${1}" ] ||
[[ ("${1}" != "commit") &&
("${1}" != "display") &&
("${1}" != "fail-on-change") &&
("${1}" != "get-version") ]]
then
echo "Usage: ${0} <command>"
echo ""
echo "This script requires the first parameter to be set to one of these options:"
echo ""
echo " commit: Write and commit the necessary version change with the change log"
echo " display: Display the required version number change"
echo " fail-on-change: The script will return an error code if there was a version number changing commit since the last release notes change"
echo " get-version: Return the current version number"
exit 1
fi
check_utils git sed sort tr
}
function generate_release_notes {
if [ ! -n "${RELEASE_NOTES_CHANGE_LOG}" ]
then
return
fi
echo "Bump version from ${RELEASE_NOTES_LATEST_VERSION} to ${RELEASE_NOTES_NEW_VERSION}."
if [ "${1}" == "commit" ]
then
(
echo ""
echo "#"
echo "# Liferay Docker Image Version ${RELEASE_NOTES_NEW_VERSION}"
echo "#"
echo ""
echo "docker.image.change.log-${RELEASE_NOTES_NEW_VERSION}=${RELEASE_NOTES_CHANGE_LOG}"
echo "docker.image.git.id-${RELEASE_NOTES_NEW_VERSION}=${RELEASE_NOTES_CURRENT_SHA}"
) >> .releng/docker-image.changelog
git add .releng/docker-image.changelog
git commit -m "${RELEASE_NOTES_NEW_VERSION} change log"
fi
}
function get_change_log {
RELEASE_NOTES_CURRENT_SHA=$(git log -1 --pretty=%H)
RELEASE_NOTES_CHANGE_LOG=$(git log --grep "^DOCKER-" --pretty=%s "${RELEASE_NOTES_LATEST_SHA}..${RELEASE_NOTES_CURRENT_SHA}" | sed -e "s/\ .*/ /" | uniq | tr -d "\n" | tr -d "\r" | sed -e "s/ $//")
if [ "${1}" == "fail-on-change" ] && [ -n "${RELEASE_NOTES_CHANGE_LOG}" ]
then
echo "There was a change in the repository which requires regenerating the release notes."
echo ""
echo "Run \"./release_notes.sh commit\" to commit the updated change log."
exit 1
fi
}
function get_latest_version {
local git_line=$(grep 'docker.image.git.id' .releng/docker-image.changelog | tail -n1)
RELEASE_NOTES_LATEST_SHA=${git_line#*=}
RELEASE_NOTES_LATEST_VERSION=${git_line#*-}
RELEASE_NOTES_LATEST_VERSION=${RELEASE_NOTES_LATEST_VERSION%=*}
RELEASE_NOTES_VERSION_MAJOR=${RELEASE_NOTES_LATEST_VERSION%%.*}
RELEASE_NOTES_VERSION_MINOR=${RELEASE_NOTES_LATEST_VERSION#*.}
RELEASE_NOTES_VERSION_MINOR=${RELEASE_NOTES_VERSION_MINOR%.*}
RELEASE_NOTES_VERSION_MICRO=${RELEASE_NOTES_LATEST_VERSION##*.}
}
function get_new_version {
if [ ! -n "${RELEASE_NOTES_CHANGE_LOG}" ]
then
return
fi
if (git log --pretty=%s "${RELEASE_NOTES_LATEST_SHA}..${RELEASE_NOTES_CURRENT_SHA}" | grep "#majorchange" > /dev/null)
then
RELEASE_NOTES_VERSION_MAJOR=$((RELEASE_NOTES_VERSION_MAJOR+1))
RELEASE_NOTES_VERSION_MINOR=0
RELEASE_NOTES_VERSION_MICRO=0
elif (git log --pretty=%s "${RELEASE_NOTES_LATEST_SHA}..${RELEASE_NOTES_CURRENT_SHA}" | grep "#minorchange" > /dev/null)
then
RELEASE_NOTES_VERSION_MINOR=$((RELEASE_NOTES_VERSION_MINOR+1))
RELEASE_NOTES_VERSION_MICRO=0
else
RELEASE_NOTES_VERSION_MICRO=$((RELEASE_NOTES_VERSION_MICRO+1))
fi
RELEASE_NOTES_NEW_VERSION="${RELEASE_NOTES_VERSION_MAJOR}.${RELEASE_NOTES_VERSION_MINOR}.${RELEASE_NOTES_VERSION_MICRO}"
}
function main {
check_usage "${@}"
get_latest_version "${@}"
get_change_log "${@}"
get_new_version "${@}"
print_version "${@}"
generate_release_notes "${@}"
}
function print_version {
if [ "${1}" == "get-version" ]
then
if [ -n "${RELEASE_NOTES_CHANGE_LOG}" ]
then
echo "${RELEASE_NOTES_NEW_VERSION}-snapshot"
else
echo "${RELEASE_NOTES_LATEST_VERSION}"
fi
exit
fi
}
main "${@}"