-
Notifications
You must be signed in to change notification settings - Fork 65
/
make-release.sh
executable file
·139 lines (118 loc) · 3.74 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
#!/bin/bash
#
# Copyright (c) 2019-2023 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> -d <devworkspace-operator-version>"
exit
}
if [[ $# -lt 1 ]]; then usage; fi
while [[ "$#" -gt 0 ]]; do
case $1 in
'-v'|'--version') VERSION="$2"; shift 1;;
'-d'|'--devworkspace-operator-version') DWO_VERSION="$2"; shift 1;;
'--help'|'-h') usage;;
esac
shift 1
done
init() {
[[ -z ${VERSION} ]] && { echo "[ERROR] Release version is not defined"; usage; }
[[ -z ${DWO_VERSION} ]] && discoverLatestDevWorkspaceOperatorVersion
BRANCH=$(echo $VERSION | sed 's/.$/x/')
git config pull.rebase true
}
discoverLatestDevWorkspaceOperatorVersion() {
git clone https://github.com/devfile/devworkspace-operator /tmp/dwo
pushd /tmp/dwo
DWO_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))
popd
}
apply_sed() {
SHORT_UNAME=$(uname -s)
if [ "$(uname)" == "Darwin" ]; then
sed -i '' "$1" "$2"
elif [ "${SHORT_UNAME:0:5}" == "Linux" ]; then
sed -i "$1" "$2"
fi
}
resetChanges() {
echo "[INFO] Reset changes in $1 branch"
git reset --hard
git checkout $1
git fetch origin --prune
git pull origin $1
}
checkoutToReleaseBranch() {
createBranch=$1
echo "[INFO] Check out to $BRANCH branch"
local branchExist=$(git ls-remote -q --heads | grep $BRANCH | wc -l)
if [[ $branchExist == 1 ]]; then
echo "[INFO] Branch $BRANCH exists"
resetChanges $BRANCH
else
if [[ $createBranch == "true" ]]; then
echo "[INFO] Branch $BRANCH does not exist"
resetChanges main
git push origin main:$BRANCH
echo "[INFO] Created new branch $BRANCH from main"
else
echo "[WARN] Branch $BRANCH does not exist. Use 'checkoutToReleaseBranch true' to create it"
fi
fi
git checkout -B $VERSION
}
release() {
echo "[INFO] Release a new $VERSION version"
echo "[INFO] Dev Workspace Operator version $DWO_VERSION"
# Create VERSION file
echo "$VERSION" > VERSION
# now replace package.json dependencies
apply_sed "s;github.com/eclipse-che/che-operator#\(.*\)\",;github.com/eclipse-che/che-operator#${VERSION}\",;g" package.json
apply_sed "s;https://github.com/devfile/devworkspace-operator#\(.*\)\",;https://github.com/devfile/devworkspace-operator#${DWO_VERSION}\",;g" package.json
# and update the app version in package.json
jq '.version |= "'$VERSION'"' package.json > package.json_; mv -f package.json_ package.json
if ! grep -q "github.com/eclipse-che/che-operator#${VERSION}" package.json; then
echo "[ERROR] Unable to find Che Operator version ${VERSION} in the package.json"; exit 1
fi
if ! grep -q "https://github.com/devfile/devworkspace-operator#${DWO_VERSION}" package.json; then
echo "[ERROR] Unable to find Dev Workspace Operator version ${DWO_VERSION} in the package.json"; exit 1
fi
# build
yarn
yarn pack
yarn test
}
commitChanges() {
echo "[INFO] Push changes to $VERSION branch"
git add -A
git commit -s -m "chore(release): release version ${VERSION}"
git pull origin $VERSION | true
git push origin $VERSION
}
createReleaseBranch() {
echo "[INFO] Create the release branch based on $VERSION"
git push origin $VERSION:release -f
}
createPR() {
checkoutToReleaseBranch true
echo "[INFO] Create PR with base = ${BRANCH} and head = ${VERSION}"
hub pull-request --base ${BRANCH} --head ${VERSION} -m "Release version ${VERSION}"
}
run() {
checkoutToReleaseBranch
release
commitChanges
createReleaseBranch
createPR
}
init
run