-
Notifications
You must be signed in to change notification settings - Fork 4
/
github-release.sh
executable file
·161 lines (133 loc) · 4.79 KB
/
github-release.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env -S bash -e
function usage() {
echo "Usage:"
echo
echo " $0 [options] <project> <release_version>"
echo
echo " <project> One of [search,validator,ogm,orm,reactive]"
echo " <release_version> The version to release (e.g. 6.0.1)"
echo
echo " Options"
echo
echo " -h Show this help and exit."
echo " -d Dry run; do not push, deploy or publish anything."
}
#--------------------------------------------
# Option parsing
function exec_or_dry_run() {
"${@}"
}
PUSH_CHANGES=true
while getopts 'dhb:' opt; do
case "$opt" in
h)
usage
exit 0
;;
d)
# Dry run
echo "DRY RUN: will not push/deploy/publish anything."
PUSH_CHANGES=false
function exec_or_dry_run() {
echo "DRY RUN; would have executed:" "${@}"
}
;;
\?)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
SCRIPTS_DIR="$(readlink -f ${BASH_SOURCE[0]} | xargs dirname)"
PROJECT=$1
RELEASE_VERSION=$2
if [ -z "$PROJECT" ]; then
echo "ERROR: Project not supplied"
usage
exit 1
fi
if [ -z "$RELEASE_VERSION" ]; then
echo "ERROR: Release version argument not supplied"
usage
exit 1
fi
if [ "$PROJECT" == "search" ]; then
JIRA_KEY="HSEARCH"
PROJECT_NAME="Search"
STRIPPED_SUFFIX_FOR_TAG=""
elif [ "$PROJECT" == "validator" ]; then
JIRA_KEY="HV"
PROJECT_NAME="Validator"
STRIPPED_SUFFIX_FOR_TAG=""
elif [ "$PROJECT" == "ogm" ]; then
JIRA_KEY="OGM"
PROJECT_NAME="OGM"
STRIPPED_SUFFIX_FOR_TAG=""
elif [ "$PROJECT" == "orm" ]; then
JIRA_KEY="HHH"
PROJECT_NAME="ORM"
STRIPPED_SUFFIX_FOR_TAG=".Final"
elif [ "$PROJECT" == "reactive" ]; then
JIRA_KEY="HREACT"
PROJECT_NAME="Reactive"
STRIPPED_SUFFIX_FOR_TAG=".Final"
else
echo "ERROR: Unknown project name $PROJECT"
usage
exit 1
fi
RELEASE_VERSION_FAMILY=$(echo "$RELEASE_VERSION" | sed -E 's/^([0-9]+\.[0-9]+).*/\1/')
RELEASE_VERSION_BASIS=$(echo "$RELEASE_VERSION" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
RELEASE_SUFFIX=$(echo "$RELEASE_VERSION" | sed -E 's/^[0-9]+\.[0-9]+\.[0-9]+(.*)/\1/')
if [ -n "$STRIPPED_SUFFIX_FOR_TAG" -a "$RELEASE_SUFFIX" == "$STRIPPED_SUFFIX_FOR_TAG" ]; then
TAG_NAME=$RELEASE_VERSION_BASIS
else
TAG_NAME=$RELEASE_VERSION
fi
if [ "$PUSH_CHANGES" == 'true' ] && [ -z "$GITHUB_API_TOKEN" ]; then
echo "ERROR: Environment variable GITHUB_API_TOKEN must not be empty"
exit 1
fi
docsUrl="https://docs.jboss.org/hibernate/orm/${RELEASE_VERSION_FAMILY}"
javadocsUrl="${docsUrl}/javadocs"
migrationGuideUrl="${docsUrl}/migration-guide/migration-guide.html"
introGuideUrl="${docsUrl}/introduction/html_single/Hibernate_Introduction.html"
userGuideUrl="${docsUrl}/userguide/html_single/Hibernate_User_Guide.html"
releaseName="Hibernate ${PROJECT_NAME} ${RELEASE_VERSION}"
releaseBody="""\
# Hibernate ${PROJECT_NAME} ${RELEASE_VERSION} released
Today, we published a new maintenance release of Hibernate ${PROJECT_NAME} ${RELEASE_VERSION_FAMILY}: ${RELEASE_VERSION}.
## What's new
This release introduces a few minor improvements as well as bug fixes.
You can find the full list of ${RELEASE_VERSION} changes [here](https://hibernate.atlassian.net/issues/?jql=project%20%3D%20${JIRA_KEY}%20AND%20fixVersion%20%3D%20${TAG_NAME}).
## Conclusion
For additional details, see:
- the [release page](https://hibernate.org/orm/releases/${RELEASE_VERSION_FAMILY}/)
- the [Migration Guide](${migrationGuideUrl})
- the [Introduction Guide](${introGuideUrl})
- the [User Guide](${userGuideUrl})
See also the following resources related to supported APIs:
- the [compatibility policy](https://hibernate.org/community/compatibility-policy/)
- the [incubating API report](${docsUrl}/incubating/incubating.txt) (\`@Incubating\`)
- the [deprecated API report](${docsUrl}/deprecated/deprecated.txt) (\`@Deprecated\` + \`@Remove\`)
- the [internal API report](${docsUrl}/internals/internal.txt) (internal packages, \`@Internal\`)
Visit the [website](https://hibernate.org/community/) for details on getting in touch with us."""
response=$(exec_or_dry_run curl -L -s -w "\n%{http_code}" \
-X POST \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
-H "Authorization: Bearer $GITHUB_API_TOKEN" \
-d "{\"tag_name\":\"${TAG_NAME}\",\"name\":\"${releaseName}\",\"make_latest\":\"legacy\",\"body\":\"${releaseBody//$'\n'/\\n}\"}" \
'https://api.github.com/repos/hibernate/hibernate-orm/releases')
if [ "$PUSH_CHANGES" == true ]; then
githubCreateReleaseResponseCode=$(tail -n1 <<< "$response") # get the last line
githubCreateReleaseResponse=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
if [ "$githubCreateReleaseResponseCode" != 201 ]; then
echo "$githubCreateReleaseResponse"
echo "ERROR: Release failed because GitHub release could not be created"
exit 1
fi
else
echo $response
fi