-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmake-release.sh
More file actions
executable file
·148 lines (126 loc) · 3.88 KB
/
make-release.sh
File metadata and controls
executable file
·148 lines (126 loc) · 3.88 KB
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
#!/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 operatorRepositories refs
jq --arg version "$VERSION" \
--arg dwo_version "$DWO_VERSION" \
'
(.operatorRepositories[] | select(.name == "eclipse-che-operator").ref) = $version |
(.operatorRepositories[] | select(.name == "devworkspace-operator").ref) = $dwo_version |
.version = $version
' package.json > package.json_
mv -f package.json_ package.json
# Validate changes
CHE_REF=$(jq -r '.operatorRepositories[] | select(.name == "eclipse-che-operator").ref' package.json)
DWO_REF=$(jq -r '.operatorRepositories[] | select(.name == "devworkspace-operator").ref' package.json)
if [[ "$CHE_REF" != "$VERSION" ]]; then
echo "[ERROR] Unable to update Che Operator ref to ${VERSION} in package.json (found: $CHE_REF)"; exit 1
fi
if [[ "$DWO_REF" != "$DWO_VERSION" ]]; then
echo "[ERROR] Unable to update Dev Workspace Operator ref to ${DWO_VERSION} in package.json (found: $DWO_REF)"; exit 1
fi
# build
corepack enable
yarn --immutable
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