-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake-release.sh
140 lines (108 loc) · 2.92 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
#!/bin/bash
#
# Copyright (c) 2024 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
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#
set -e
usage ()
{ echo "Usage: ./make-release.sh -v <version>"
exit
}
init() {
unset VERSION
while [[ "$#" -gt 0 ]]; do
case $1 in
'-v'|'--version') VERSION="$2"; shift 1;;
'--help'|'-h') usage;;
esac
shift 1
done
[[ -z ${VERSION} ]] && { echo "[ERROR] Release version is not defined"; usage; }
X_BRANCH=$(echo "${VERSION}" | sed 's/.$/x/')
NEXT_BRANCH="pr-main-to-${VERSION}-next"
NEXT_VERSION="${VERSION}-next"
}
resetChanges() {
local branch="$1"
echo "[INFO] Reset changes in ${branch} branch"
git reset --hard
git checkout "${branch}"
git fetch origin --prune
git pull origin "${branch}"
}
checkoutToXBranch() {
echo "[INFO] Check out to ${X_BRANCH} branch."
if [[ $(git ls-remote -q --heads | grep -c "${X_BRANCH}") == 1 ]]; then
echo "[INFO] ${X_BRANCH} exists."
resetChanges "${X_BRANCH}"
else
echo "[INFO] ${X_BRANCH} does not exist. Will be created a new one from main."
resetChanges "main"
git push origin main:"${X_BRANCH}"
git checkout "${X_BRANCH}"
fi
}
checkoutToNextBranch() {
echo "[INFO] Will be created a new ${NEXT_BRANCH} branch from main."
resetChanges main
git push origin main:"${NEXT_BRANCH}"
git checkout "${NEXT_BRANCH}"
}
tagRelease() {
git tag "${VERSION}"
git push origin "${VERSION}"
}
createPR() {
local base=$1
local branch=$2
local message=$3
echo "[INFO] Create PR with base = ${base} and head = ${branch}"
hub pull-request --base "${base}" --head "${branch}" -m "${message}"
}
updatePackageVersionAndCommitChanges() {
local version=$1
local branch=$2
local message=$3
echo "[INFO] Set ${version} in package.json"
npm --no-git-tag-version version --allow-same-version --prefix status-app ${NEXT_VERSION}
# jq '.version |= "'${version}'"' status-app/package.json > status-app/package.json.update
# mv -f status-app/package.json.update status-app/package.json
echo "[INFO] Push changes to ${branch} branch"
git add status-app/package.json status-app/package-lock.json
git commit -s -m "${message}"
git push origin "${branch}"
}
updateXBranch() {
checkoutToXBranch
COMMIT_MSG="ci: bump ${VERSION} in ${X_BRANCH}"
updatePackageVersionAndCommitChanges \
"${VERSION}" \
"${X_BRANCH}" \
"${COMMIT_MSG}"
tagRelease
}
updateMainBrain() {
checkoutToNextBranch
COMMIT_MSG="ci: bump ${NEXT_VERSION} in main"
updatePackageVersionAndCommitChanges \
"${NEXT_VERSION}" \
"${NEXT_BRANCH}" \
"${COMMIT_MSG}"
createPR \
"main" \
"${NEXT_BRANCH}" \
"${COMMIT_MSG}"
}
run() {
updateXBranch
updateMainBrain
}
init "$@"
run