forked from eclipse-che/che-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-release.sh
executable file
·246 lines (225 loc) · 7.06 KB
/
make-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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/bin/bash
#
# Copyright (c) 2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Release process automation script.
# 0. Verify VERSION is defined as X.Y.Z
# 1. Start from the accurate branch
# * If Z = 0, start from master branch.
# * Else, start from X.Y.x release branch
# 2. Update versions in `antora.yml`:
# * `prod-ver` = version to release
# * Set other `ver` attributes accordingly.
# 3. Run scripts generating doc
# * checluster_docs_gen.sh
# * environment_docs_gen.sh
# 4. Commit and push to the release branch.
# 5. (If defined) Tag the release
# Fail on error
set -e
# set to 1 to actually trigger changes in the release branch
TAG_RELEASE=0
DOCOMMIT=1 # by default DO commit the change
DOPUSH=1 # by default DO push the change
[email protected]:eclipse/che-docs
MAIN_BRANCH="master"
USE_TMP_DIR=0
while [[ "$#" -gt 0 ]]; do
case $1 in
'-t'|'--trigger-release')
TAG_RELEASE=1
DOCOMMIT=1
shift 0
;;
'-v'|'--version')
VERSION="$2"
shift 1
;;
'-n'|'--nocommit')
DOCOMMIT=0
DOPUSH=0
shift 0
;;
'--nopush')
DOPUSH=0
shift 0
;;
'-tmp'|'--use-tmp-dir')
USE_TMP_DIR=1
shift 0
;;
esac
shift 1
done
usage ()
{
echo "
Usage: $0 --version [VERSION TO RELEASE]
Example: $0 --version 7.25.2 -t
Options:
--trigger-release, -t Tag this release
--nocommit, -n Do not commit changes to git branches
--nopush Do not push changes to git remote
-tmp, --use-tmp-dir Use a fresh git clone in a temporary directory
"
}
if [[ ! ${VERSION} ]]; then
usage
exit 1
fi
gitClone() {
if [[ ${USE_TMP_DIR} -eq 1 ]]; then
# Getting a local copy with all ta
cd /tmp/
TMPDIR=tmp-${0##*/}-$VERSION
rm -rf "${TMPDIR}"
git clone $REPO "${TMPDIR}"
cd "/tmp/${TMPDIR}"
git pull
fi
}
gitBranch() {
# Handle the version branch: create it or update it.
# Check if the branch exists, locally or on the remote.
EXISTING_BRANCH=0
git fetch
EXISTING_BRANCH=$(git ls-remote --heads origin "${TARGET_BRANCH}")
case ${EXISTING_BRANCH} in
"") echo "[INFO] Creating new branch: ${TARGET_BRANCH} from branch: ${MAIN_BRANCH}."
git checkout "${MAIN_BRANCH}"
git checkout -b "${TARGET_BRANCH}"
;;
*) echo "[INFO] Updating branch: ${TARGET_BRANCH} from branch: ${MAIN_BRANCH}."
git checkout "${TARGET_BRANCH}"
;;
esac
}
gitCommit() {
if [[ ${DOCOMMIT} -eq 1 ]]; then
git add "antora*.yml" "modules/installation-guide/examples/*"
git commit -s -m "release: Bump version to ${VERSION}"
fi
}
gitPush() {
if [[ ${DOPUSH} -eq 1 ]]; then
git pull origin "${TARGET_BRANCH}" || true
git push origin "${TARGET_BRANCH}"
fi
}
gitPullRequest() {
if [[ ${DOCOMMIT} -eq 1 ]]; then
git pull origin "${TARGET_BRANCH}" || true
git push origin "${TARGET_BRANCH}"
LASTCOMMITCOMMENT="$(git log -1 --pretty=%B)"
hub pull-request --force --message "${LASTCOMMITCOMMENT}" --base "${MAIN_BRANCH}" --head "${TARGET_BRANCH}"
fi
}
gitTag() {
if [[ ${TAG_RELEASE} -eq 1 ]]; then
echo "[INFO] Creating release tag"
git checkout "${TARGET_BRANCH}"
git pull origin "${TARGET_BRANCH}" || true
git tag "${VERSION}"
git push origin "${VERSION}" || true
fi
}
versionFormatIsValid() {
# Validating version format
[[ ${VERSION} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+) ]] && MAJOR="${BASH_REMATCH[1]}" ; MINOR="${BASH_REMATCH[2]}"; PATCH="${BASH_REMATCH[3]}"
case ${MAJOR} in
"") echo "[ERROR] Version ${VERSION} is not in form MAJOR.MINOR.PATCH."
exit 1
;;
esac
case ${MINOR} in
"") echo "[ERROR] Version ${VERSION} is not in form MAJOR.MINOR.PATCH."
exit 1
;;
esac
case ${PATCH} in
"") echo "[ERROR] Version ${VERSION} is not in form MAJOR.MINOR.PATCH."
exit 1
;;
esac
echo "[INFO] Version format for: ${VERSION} is in form MAJOR.MINOR.PATCH."
}
versionIsIncremented() {
# Validation version is incremented, never decremented
OLDVERSION="$(yq -r '.asciidoc.attributes."prod-ver-patch"' "${YAMLFILE}")" # existing prod-ver-patch version 7.yy.z
VERSIONS="${OLDVERSION} ${VERSION}"
VERSIONS_SORTED="$(echo "${VERSIONS}" | tr " " "\n" | sort -V | tr "\n" " ")"
# echo "Compare '${VERSIONS_SORTED}' with '${VERSIONS} '"
if [[ "${VERSIONS_SORTED}" != "${VERSIONS} " ]] || [[ "${OLDVERSION}" == "${VERSION}" ]]; then # note trailing space after VERSIONS is required!
echo "[ERROR] Target version ${VERSION} is smaller than existing version: ${OLDVERSION}. Version should not go backwards, so nothing to do!"
return 1
fi
echo "[INFO] Target version: ${VERSION} is an increment for current version: ${OLDVERSION}."
}
replaceFieldSed()
{
YAMLFILE=$1
YAMLKEY=$2
YAMLVALUE=$3
echo "[INFO] Updating file: ${YAMLFILE} on branch: ${TARGET_BRANCH}: setting attribute: ${YAMLKEY}: ${YAMLVALUE}"
sed -i "${YAMLFILE}" -r -e "s#( ${YAMLKEY}: ).+#\1${YAMLVALUE}#"
}
versionUpdate() {
# Update the version, defined in the antora.yml file, in following keys:
# prod-prev-ver-major: "6" [never changes]
# prod-ver-major: "7" [never changes]
# prod-prev-ver: "7.24" [always prod-ver - 1]
# prod-ver: "7.25"
# prod-ver-patch: "7.25.2"
# Major version upgrade is expected to fail.
YAMLFILE=antora.yml
# prod-ver should never go down, only up
versionIsIncremented
replaceFieldSed "${YAMLFILE}" 'prod-ver-major' "\"${MAJOR}\""
replaceFieldSed "${YAMLFILE}" 'prod-ver' "\"${MAJOR}.${MINOR}\""
replaceFieldSed "${YAMLFILE}" 'prod-ver-patch' "\"${MAJOR}.${MINOR}.${PATCH}\""
replaceFieldSed "${YAMLFILE}" 'prod-prev-ver' "\"${MAJOR}.$((MINOR - 1))\""
# Update the version, defined in the antora-playbook-for-publication.yml file, in following keys:
# branches: 7.32.x
# edit_url: "https://github.com/eclipse/che-docs/edit/7.35.x/{path}"
YAMLFILE=antora-playbook-for-publication.yml
if [ -f "${YAMLFILE}" ]
then
replaceFieldSed "${YAMLFILE}" 'branches' "\"${MAJOR}.${MINOR}.x\""
replaceFieldSed "${YAMLFILE}" 'edit_url' "\"https://github.com/eclipse/che-docs/edit/${MAJOR}.${MINOR}.x/{path}\""
else
echo "[WARNING] Cannot find file: ${YAMLFILE} on branch: ${TARGET_BRANCH}. Skipping."
fi
echo "[INFO] Generating single-sourced docs on branch: ${TARGET_BRANCH}."
./tools/checluster_docs_gen.sh
./tools/environment_docs_gen.sh
echo "[INFO] Finished handling version update on branch: ${TARGET_BRANCH}.."
}
# Validate the version format.
versionFormatIsValid
# Get a working copy if necessary.
gitClone
# Update version in the version branch and in the main branch.
for TARGET_BRANCH in "${MAJOR}.${MINOR}.x" "release-${VERSION}"
do
gitBranch
versionUpdate
gitCommit
gitPush
case ${TARGET_BRANCH} in
"${MAJOR}.${MINOR}.x")
gitTag
;;
"release-${VERSION}")
gitPullRequest
;;
esac
done
echo "[INFO] Project version has been updated"
if [[ ${USE_TMP_DIR} -eq 1 ]]; then
rm -fr "/tmp/${TMPDIR}"
fi