forked from che-incubator/chectl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-release.sh
executable file
·107 lines (91 loc) · 2.59 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
#!/bin/bash
#
# Copyright (c) 2019 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
set -u
init() {
RELEASE="$1"
BRANCH=$(echo $RELEASE | sed 's/.$/x/')
GIT_REMOTE_UPSTREAM="[email protected]:che-incubator/chectl.git"
}
check() {
if [[ $# -lt 1 ]]; then
echo "[ERROR] Wrong number of parameters.\nUsage: ./make-release.sh <version>"
exit 1
fi
}
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 ${GIT_REMOTE_UPSTREAM} --prune
git pull ${GIT_REMOTE_UPSTREAM} $1
}
checkoutToReleaseBranch() {
echo "[INFO] Checking out to $BRANCH branch."
local branchExist=$(git ls-remote -q --heads | grep $BRANCH | wc -l)
if [[ $branchExist == 1 ]]; then
echo "[INFO] $BRANCH exists."
resetChanges $BRANCH
else
echo "[INFO] $BRANCH does not exist. Will be created a new one from master."
resetChanges master
git push origin master:$BRANCH
fi
git checkout -B $RELEASE
}
release() {
echo "[INFO] Releasing a new $RELEASE version"
# Create VERSION file
echo "$RELEASE" > VERSION
# replace nightly versions by release version
apply_sed "s#quay.io/eclipse/che-server:.*#quay.io/eclipse/che-server:${RELEASE}'#g" src/constants.ts
apply_sed "s#quay.io/eclipse/che-operator:.*#quay.io/eclipse/che-operator:${RELEASE}'#g" src/constants.ts
# now replace package.json dependencies
apply_sed "s;github.com/eclipse/che#\(.*\)\",;github.com/eclipse/che#${RELEASE}\",;g" package.json
apply_sed "s;github.com/eclipse/che-operator#\(.*\)\",;github.com/eclipse/che-operator#${RELEASE}\",;g" package.json
# build
yarn
yarn pack
yarn test
}
commitChanges() {
echo "[INFO] Pushing changes to $RELEASE branch"
git add -A
git commit -s -m "chore(release): release version ${RELEASE}"
git push origin $RELEASE
}
createReleaseBranch() {
echo "[INFO] Create the release branch based on $RELEASE"
git push origin $RELEASE:release -f
}
createPR() {
echo "[INFO] Creating a PR"
hub pull-request --base ${BRANCH} --head ${RELEASE} --browse -m "Release version ${RELEASE}"
}
run() {
checkoutToReleaseBranch
release
commitChanges
createReleaseBranch
createPR
}
init $@
check $@
run $@