-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate-changelog.sh
executable file
·119 lines (108 loc) · 3.88 KB
/
update-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
#!/usr/bin/env -S bash -e
########################################################################################################################
# The purpose of this tool is to update the changelog.txt using JIRA's REST API to get the required information
########################################################################################################################
PROJECT=$1
RELEASE_VERSION=$2
CHANGELOG=$3
if [ -z "$PROJECT" ]; then
echo "ERROR: Project argument not supplied"
exit 1
fi
if [ -z "$RELEASE_VERSION" ]; then
echo "ERROR: Release version argument not supplied"
exit 1
fi
if [ -z "$CHANGELOG" ]; then
echo "ERROR: changelog path not supplied"
exit 1
fi
if ! [ -w "$CHANGELOG" ]; then
echo "ERROR: '$CHANGELOG' is not a valid file"
exit 1
fi
case "$PROJECT" in
'validator')
JIRA_KEY="HV"
;;
'search')
JIRA_KEY="HSEARCH"
;;
'ogm')
JIRA_KEY="OGM"
;;
*)
echo "ERROR: Unknown project: $project"
exit 1
;;
esac
########################################################################################################################
# Fetches the JIRA version information.
# We are dealing with something like this
#
# ...,
# {
# "self": "https://hibernate.atlassian.net/rest/api/latest/version/18754",
# "id": "18754",
# "description": "Bugfixes for MongoDB, Neo4j and CouchDB backends",
# "name": "4.1.2.Final",
# "archived": false,
# "released": true,
# "releaseDate": "2015-02-27",
# "userReleaseDate": "27/Feb/2015",
# "projectId": 10160
# },
# ...
function jira_version() {
# REST URL used to retrieve all release versions of the project - https://docs.atlassian.com/jira/REST/latest/#d2e4023
jira_versions_url="https://hibernate.atlassian.net/rest/api/latest/project/${JIRA_KEY}/versions"
curl "$jira_versions_url" | jq ".[] | select(.name | . == \"${RELEASE_VERSION}\")"
}
#######################################################################################################################
# Creates the required update for changelog.txt. It creates the following:
#
# <version> (<date>)
# -------------------------
#
# ** <issue-type-1>
# * PROJECT-<key> - <summary>
# ...
#
# ** <issue-type-2>
# * PROJECT-<key> - <summary>
# ...
#
function create_changelog_update() {
# REST URL used for getting all issues of given release - see https://docs.atlassian.com/jira/REST/latest/#d2e2450
jira_issues_url="https://hibernate.atlassian.net/rest/api/2/search/?jql=project%20%3D%20${JIRA_KEY}%20AND%20fixVersion%20%3D%20${RELEASE_VERSION}%20ORDER%20BY%20issuetype%20ASC&fields=issuetype,summary&maxResults=200"
echo "$RELEASE_VERSION ($(date +%Y-%m-%d))"
echo "-------------------------"
curl "$jira_issues_url" | jq -r '.issues[] | (.fields.issuetype.name + "\t" + .key + "\t" + .fields.summary)' |
while IFS=$'\t' read -r issuetype key summary; do
if [ "$previous_issuetype" != "$issuetype" ]; then
previous_issuetype="$issuetype"
echo ""
echo "** $issuetype"
fi
echo " * $key $summary"
done
echo ""
}
########################################################################################################################
# Putting it all together
########################################################################################################################
JIRA_VERSION="$(jira_version)"
if [ -z "$JIRA_VERSION" ]; then
echo "ERROR: Version $RELEASE_VERSION does not exist in JIRA"
exit 1
fi
if [ "true" != "$(echo "$JIRA_VERSION" | jq '.released' )" ]; then
echo "ERROR: Version $RELEASE_VERSION is not yet released in JIRA"
exit 1
fi
changelog_update_file="$(mktemp)"
trap "rm -f $changelog_update_file" EXIT
create_changelog_update > "$changelog_update_file"
sed -i "3r$changelog_update_file" "$CHANGELOG"
git add "$CHANGELOG"
git commit -m "[Jenkins release job] changelog.txt updated by release build ${RELEASE_VERSION}"