forked from jupyter-server/enterprise_gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·297 lines (241 loc) · 9.27 KB
/
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/env bash
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
function exit_with_usage {
cat << EOF
release - Creates build distributions from a git commit hash or from HEAD.
SYNOPSIS
usage: release.sh [--release-prepare | --release-publish]
DESCRIPTION
Perform necessary tasks for a Jupyter Enterprise Gateway release
release-prepare: This form creates a release tag and builds the release distribution artifacts.
--release-prepare --currentVersion="2.0.0.dev0" --releaseVersion="2.0.0" --developmentVersion="2.1.0.dev1" --previousVersion="2.0.0rc2" [--tag="v2.0.0"] [--gitCommitHash="a874b73"]
release-publish: Publish the release distribution artifacts to PyPI.
--release-publish --tag="v2.0.0"
OPTIONS
--currentVersion - Current development version
--releaseVersion - Release identifier used when publishing
--developmentVersion - Release identifier used for next development cycle
--previousVersion - Release identifier left in download links from previous release
--tag - Release Tag identifier used when taging the release, default 'v$releaseVersion'
--gitCommitHash - Release tag or commit to build from, default master HEAD
--dryRun - Dry run only, mostly used for testing.
EXAMPLES
release.sh --release-prepare --currentVersion="2.0.0.dev0" --releaseVersion="2.0.0" --developmentVersion="2.1.0.dev1" --previousVersion="2.0.0rc2"
release.sh --release-prepare --currentVersion="2.0.0.dev0" --releaseVersion="2.0.0" --developmentVersion="2.1.0.dev1" --previousVersion="2.0.0rc2" --tag="v2.0.0" --dryRun
release.sh --release-publish --gitTag="v2.0.0"
EOF
exit 1
}
set -e
if [ $# -eq 0 ]; then
exit_with_usage
fi
# Process each provided argument configuration
while [ "${1+defined}" ]; do
IFS="=" read -ra PARTS <<< "$1"
case "${PARTS[0]}" in
--release-prepare)
GOAL="release-prepare"
RELEASE_PREPARE=true
shift
;;
--release-publish)
GOAL="release-publish"
RELEASE_PUBLISH=true
shift
;;
--release-snapshot)
GOAL="release-snapshot"
RELEASE_SNAPSHOT=true
shift
;;
--gitCommitHash)
GIT_REF="${PARTS[1]}"
shift
;;
--gitTag)
GIT_TAG="${PARTS[1]}"
shift
;;
--currentVersion)
CURRENT_VERSION="${PARTS[1]}"
shift
;;
--releaseVersion)
RELEASE_VERSION="${PARTS[1]}"
shift
;;
--developmentVersion)
DEVELOPMENT_VERSION="${PARTS[1]}"
shift
;;
--previousVersion)
PREVIOUS_VERSION="${PARTS[1]}"
shift
;;
--tag)
RELEASE_TAG="${PARTS[1]}"
shift
;;
--dryRun)
DRY_RUN="-DdryRun=true"
shift
;;
*help* | -h)
exit_with_usage
exit 0
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
if [[ "$RELEASE_PREPARE" == "true" && -z "$RELEASE_VERSION" ]]; then
echo "ERROR: --releaseVersion must be passed as an argument to run this script"
exit_with_usage
fi
if [[ "$RELEASE_PREPARE" == "true" && -z "$DEVELOPMENT_VERSION" ]]; then
echo "ERROR: --developmentVersion must be passed as an argument to run this script"
exit_with_usage
fi
if [[ "$RELEASE_PREPARE" == "true" && -z "$PREVIOUS_VERSION" ]]; then
echo "ERROR: --previousVersion must be passed as an argument to run this script"
exit_with_usage
fi
if [[ "$RELEASE_PUBLISH" == "true" ]]; then
if [[ "$GIT_REF" && "$GIT_TAG" ]]; then
echo "ERROR: Only one argumented permitted when publishing : --gitCommitHash or --gitTag"
exit_with_usage
fi
if [[ -z "$GIT_REF" && -z "$GIT_TAG" ]]; then
echo "ERROR: --gitCommitHash OR --gitTag must be passed as an argument to run this script"
exit_with_usage
fi
fi
if [[ "$RELEASE_PUBLISH" == "true" && "$DRY_RUN" ]]; then
echo "ERROR: --dryRun not supported for --release-publish"
exit_with_usage
fi
# Commit ref to checkout when building
GIT_REF=${GIT_REF:-HEAD}
if [[ "$RELEASE_PUBLISH" == "true" && "$GIT_TAG" ]]; then
GIT_REF="tags/$GIT_TAG"
fi
BASE_DIR=$(pwd)
WORK_DIR=$(pwd)/build/release
SOURCE_DIR=$(pwd)/build/release/enterprise_gateway
if [ -z "$RELEASE_TAG" ]; then
RELEASE_TAG="v$RELEASE_VERSION"
fi
echo " "
echo "Base directory: $BASE_DIR"
echo "Work directory: $WORK_DIR"
echo "Source directory: $SOURCE_DIR"
echo " "
echo "-------------------------------------------------------------"
echo "------- Release preparation with the following parameters ---"
echo "-------------------------------------------------------------"
echo "Executing ==> $GOAL"
echo "Git reference ==> $GIT_REF"
echo "Release version ==> $RELEASE_VERSION"
echo "Development version ==> $DEVELOPMENT_VERSION"
echo "Tag ==> $RELEASE_TAG"
if [ "$DRY_RUN" ]; then
echo "dry run ? ==> true"
fi
set -o xtrace
function checkout_code {
rm -rf $WORK_DIR
mkdir -p $WORK_DIR
cd $WORK_DIR
# Checkout code
git clone git@github.com:jupyter/enterprise_gateway.git
cd enterprise_gateway
git checkout $GIT_REF
git_hash=`git rev-parse --short HEAD`
echo "Checked out Jupyter Enterprise Gateway git hash $git_hash"
}
function update_version_to_release {
cd $SOURCE_DIR
# Update Python _version.py
sed -i .bak "s@^__version__.*@__version__ = '$RELEASE_VERSION'@g" enterprise_gateway/_version.py
# Update Makefile
sed -i .bak "s@$CURRENT_VERSION@$RELEASE_VERSION@g" Makefile
# Update Kubernetes deployment descriptor
sed -i .bak "s@elyra/enterprise-gateway:dev@elyra/enterprise-gateway:$RELEASE_VERSION@g" etc/kubernetes/enterprise-gateway.yaml
sed -i .bak "s@elyra/kernel-image-puller:dev@elyra/kernel-image-puller:$RELEASE_VERSION@g" etc/kubernetes/enterprise-gateway.yaml
# Update Kubernetes Helm chart and values files
sed -i .bak "s@version: [0-9,\.,a-z]*@version: $RELEASE_VERSION@g" etc/kubernetes/helm/enterprise-gateway/Chart.yaml
sed -i .bak "s@elyra/enterprise-gateway:dev@elyra/enterprise-gateway:$RELEASE_VERSION@g" etc/kubernetes/helm/enterprise-gateway/values.yaml
sed -i .bak "s@elyra/kernel-image-puller:dev@elyra/kernel-image-puller:$RELEASE_VERSION@g" etc/kubernetes/helm/enterprise-gateway/values.yaml
# Update Docker compose version
sed -i .bak "s@elyra/enterprise-gateway:dev@elyra/enterprise-gateway:$RELEASE_VERSION@g" etc/docker/docker-compose.yml
sed -i .bak "s@elyra/kernel-image-puller:dev@elyra/kernel-image-puller:$RELEASE_VERSION@g" etc/docker/docker-compose.yml
# Update documentation - this is a one-way change since links will not be valid in dev "releases".
find docs/source/*.md -type f -exec sed -i .bak "s@$PREVIOUS_VERSION@$RELEASE_VERSION@g" {} \;
}
function update_version_to_development {
cd $SOURCE_DIR
# Update Python _version.py
sed -i .bak "s@^__version__.*@__version__ = '$DEVELOPMENT_VERSION'@g" enterprise_gateway/_version.py
# Update Makefile
sed -i .bak "s@$RELEASE_VERSION@$DEVELOPMENT_VERSION@g" Makefile
# Update Kubernetes deployment descriptor
sed -i .bak "s@elyra/enterprise-gateway:$RELEASE_VERSION@elyra/enterprise-gateway:dev@g" etc/kubernetes/enterprise-gateway.yaml
sed -i .bak "s@elyra/kernel-image-puller:$RELEASE_VERSION@elyra/kernel-image-puller:dev@g" etc/kubernetes/enterprise-gateway.yaml
# Update Kubernetes Helm chart and values files
sed -i .bak "s@version: [0-9,\.,a-z]*@version: $DEVELOPMENT_VERSION@g" etc/kubernetes/helm/enterprise-gateway/Chart.yaml
sed -i .bak "s@elyra/enterprise-gateway:$RELEASE_VERSION@elyra/enterprise-gateway:dev@g" etc/kubernetes/helm/enterprise-gateway/values.yaml
sed -i .bak "s@elyra/kernel-image-puller:$RELEASE_VERSION@elyra/kernel-image-puller:dev@g" etc/kubernetes/helm/enterprise-gateway/values.yaml
# Update Docker compose version
sed -i .bak "s@elyra/enterprise-gateway:$RELEASE_VERSION@elyra/enterprise-gateway:dev@g" etc/docker/docker-compose.yml
sed -i .bak "s@elyra/kernel-image-puller:$RELEASE_VERSION@elyra/kernel-image-puller:dev@g" etc/docker/docker-compose.yml
}
if [[ "$RELEASE_PREPARE" == "true" ]]; then
echo "Preparing release $RELEASE_VERSION ($RELEASE_VERSION)"
# Checkout code
checkout_code
update_version_to_release
cd $SOURCE_DIR
if [ -z "$DRY_RUN" ]; then
make clean dist release docs
else
make clean dist docs
fi
mkdir -p $WORK_DIR/$RELEASE_TAG
cp $SOURCE_DIR/dist/jupyter_enterprise_gateway* $WORK_DIR/$RELEASE_TAG
# Build and prepare the release
git commit -a -m "Prepare release $RELEASE_VERSION"
git tag $RELEASE_TAG
update_version_to_development
cd $SOURCE_DIR
make clean dist docs
# Build next development iteraction
git commit -a -m"Prepare for next development interaction $DEVELOPMENT_VERSION"
if [ -z "$DRY_RUN" ]; then
git push
git push --tags
fi
cd "$BASE_DIR" #exit target
exit 0
fi
if [[ "$RELEASE_PUBLISH" == "true" ]]; then
echo "Publishing release $RELEASE_VERSION"
# Checkout code
checkout_code
cd $SOURCE_DIR
git checkout $RELEASE_TAG
git clean -d -f -x
make clean dist docs
cd "$BASE_DIR" #exit target
exit 0
fi
cd "$BASE_DIR" #return to base dir
rm -rf target
echo "ERROR: wrong execution goals"
exit_with_usage