-
Notifications
You must be signed in to change notification settings - Fork 394
/
build-changelog.sh
executable file
·147 lines (115 loc) · 4.35 KB
/
build-changelog.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
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function fail {
echo "$1"
exit 1
}
function getProjectVersionFromPom {
cat << EOF | xmllint --noent --shell pom.xml | grep content | cut -f2 -d=
setns pom=http://maven.apache.org/POM/4.0.0
xpath /pom:project/pom:version/text()
EOF
}
if [ "$1" = "--help" ] ; then
echo "
Usage: $0 [--help] [version]
Retrieves the release notes for the next release of Apache Wicket,
and merges this into the CHANGELOG file.
version
optional version number to retrieve the release notes for
--help
shows this help
"
exit 0
fi
if [ ! -z "$1" ] ; then
current_version="$1"
major_version=$(expr $current_version : '\(.*\)\..*\..*\-.*')
minor_version=$(expr $current_version : '.*\.\(.*\)\..*\-.*')
bugfix_version=$(expr $current_version : '.*\..*\.\(.*\)-.*')
version="$1"
previous_version="$major_version.$(expr $minor_version - 1).0"
else
current_version=$(getProjectVersionFromPom)
major_version=$(expr $current_version : '\(.*\)\..*\..*\-.*')
minor_version=$(expr $current_version : '.*\.\(.*\)\..*\-.*')
bugfix_version=$(expr $current_version : '.*\..*\.\(.*\)-.*')
version="$major_version.$minor_version.0"
previous_version="$major_version.$(expr $minor_version - 1).0"
fi
echo "
Apache Wicket release notes generator
=====================================
This tool retrieves the release notes for the upcoming release from JIRA
and merges this with the existing CHANGELOG in a text format.
Version to retrieve the release notes from: $version
Press <enter> to continue \c"
read
git status --porcelain CHANGELOG-$major_version.x | grep -q "CHANGELOG-$major_version.x"
if [ $? -eq 0 ] ; then
fail "You already have changes in the CHANGELOG-$major_version.x
"
fi
grep -q "$version\$" CHANGELOG-$major_version.x
if [ $? -eq 0 ] ; then
fail "You already have added release notes for this version to the changelog.
"
fi
echo "
Extracting JIRA Release notes -- making web requests"
echo " - determining JIRA version id for $version: \c"
jira_project_id=12310561
jira_version_id=$( \
curl -s https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=$jira_project_id \
| xmllint --noout --noblanks --html --xpath "string(//select[@id=\"version_select\"]/option[translate(normalize-space(text()), ' ', '')=\"$version\"]/@value)" - 2>/dev/null \
)
re='^[0-9]+$'
if ! [[ $jira_version_id =~ $re ]] ; then
echo "ERROR"
echo "
Unable to retrieve the version ID from JIRA: received '$jira_version_id'" >&2
exit 1
fi
echo "$jira_version_id"
echo " - retrieving text release notes: \c"
curl -s "https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=$jira_project_id&version=$jira_version_id&styleName=Text&Create=Create" \
| xmllint --noout --noblanks --html --xpath "string(//textarea)" - 2>/dev/null | cat -s | awk '{ if ($0 ~ /^\*\* / ) {
printf( "%s\n\n", $0);
} else {
printf( "%s\n", $0 );
}
}' > /tmp/release-notes-$version.txt
echo "done"
echo " - merging release notes into changelog: \c"
echo "This file contains all changes done in releases for Apache Wicket $major_version.x.
=======================================================================
$(cat /tmp/release-notes-$version.txt)
=======================================================================
$(tail -n +4 CHANGELOG-$major_version.x)
" > /tmp/changelog-$version.txt
cp /tmp/changelog-$version.txt CHANGELOG-$major_version.x
echo "done
"
git diff
echo ""
git add CHANGELOG-$major_version.x
git commit -m "Added CHANGELOG for release $version"
echo "
The CHANGELOG-$major_version.x file has been updated and committed.
To revert the changes to the CHANGELOG:
git reset HEAD^ --hard
Have fun!
"