-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·354 lines (301 loc) · 14 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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
set -o errexit -o pipefail
SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
PROJECT_ROOT_DIRECTORY="$SCRIPT_DIRECTORY"
#########################################
#### Variables intialisation ############
#########################################
TEST="YES"
RELEASE="NO"
SKIP_API="NO"
BASEDIR=$PWD
#########################################
#### Cleaning functions #################
#########################################
function clean_docker {
echo "===> Stop arlas-subscriptions stack"
docker compose --project-name arlas-subscriptions down -v
}
function clean_exit {
ARG=$?
echo "=> Exit status = $ARG"
rm -rf pom.xml.versionsBackup
rm -rf target/tmp || echo "target/tmp already removed"
clean_docker
if [ "$RELEASE" == "YES" ]; then
git checkout -- .
mvn clean
else
echo "=> Skip discard changes";
git checkout -- pom.xml
sed -i.bak 's/\"'${FULL_API_VERSION}'\"/\"API_VERSION\"/' subscriptions-manager/src/main/java/io/arlas/subscriptions/rest/UserSubscriptionManagerAbstractController.java
fi
exit $ARG
}
trap clean_exit EXIT
#########################################
#### Available arguments ################
#########################################
usage(){
echo "Usage: ./release.sh -api-major=X -api-minor=Y -api-patch=U -rel=Z -dev=Z+1 -es=Y [--no-tests] [--skip-api]"
echo " -api-major|--api-version release arlas-subscriptions API major version"
echo " -api-minor|--api-minor-version release arlas-subscriptions API minor version"
echo " -api-patch|--api-patch-version release arlas-subscriptions API patch version"
echo " -rel|--arlas-release release arlas-server version"
echo " -dev|--arlas-dev development arlas-subscriptions version (-SNAPSHOT qualifier will be automatically added)"
echo " --no-tests do not run integration tests"
echo " --release publish artifacts and git push local branches"
echo " --skip-api do not generate clients APIs"
exit 1
}
#########################################
#### Parsing arguments ##################
#########################################
for i in "$@"
do
case $i in
-rel=*|--arlas-release=*)
ARLAS_REL="${i#*=}"
shift # past argument=value
;;
-dev=*|--arlas-dev=*)
ARLAS_DEV="${i#*=}"
shift # past argument=value
;;
-api-major=*|--api-major-version=*)
API_MAJOR_VERSION="${i#*=}"
shift # past argument=value
;;
-api-minor=*|--api-minor-version=*)
API_MINOR_VERSION="${i#*=}"
shift # past argument=value
;;
-api-patch=*|--api-patch-version=*)
API_PATCH_VERSION="${i#*=}"
shift # past argument=value
;;
--no-tests)
TESTS="NO"
shift # past argument with no value
;;
--release)
RELEASE="YES"
shift # past argument with no value
;;
--skip-api)
SKIP_API="YES"
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
#########################################
#### Recap of chosen arguments ##########
#########################################
if [ -z ${API_MAJOR_VERSION+x} ]; then usage; else echo "API MAJOR version : ${API_MAJOR_VERSION}"; fi
if [ -z ${API_MINOR_VERSION+x} ]; then usage; else echo "API MINOR version : ${API_MINOR_VERSION}"; fi
if [ -z ${API_PATCH_VERSION+x} ]; then usage; else echo "API PATCH version : ${API_PATCH_VERSION}"; fi
if [ -z ${ARLAS_REL+x} ]; then usage; else echo "Release version : ${ARLAS_REL}"; fi
if [ -z ${ARLAS_DEV+x} ]; then usage; else echo "Next development version : ${ARLAS_DEV}"; fi
echo "Running tests : ${TESTS}"
echo "Release : ${RELEASE}"
#########################################
#### Check if you're logged on to repos ###########
#########################################
if [ "$RELEASE" == "YES" -a "$SKIP_API" == "NO" ]; then
export npmlogin=`npm whoami`
if [ -z "$npmlogin" ] ; then echo "Your are not logged on to npm"; exit -1; else echo "logged as "$npmlogin ; fi
if [ -z "$PIP_LOGIN" ] ; then echo "Please set PIP_LOGIN environment variable"; exit -1; fi
if [ -z "$PIP_PASSWORD" ] ; then echo "Please set PIP_PASSWORD environment variable"; exit -1; fi
fi
#########################################
#### Setting versions ###################
#########################################
export ARLAS_SUBSCRIPTIONS_VERSION="${API_MAJOR_VERSION}.${API_MINOR_VERSION}.${ARLAS_REL}"
ARLAS_DEV_VERSION="${API_MAJOR_VERSION}.${API_MINOR_VERSION}.${ARLAS_DEV}"
FULL_API_VERSION=${API_MAJOR_VERSION}"."${API_MINOR_VERSION}"."${API_PATCH_VERSION}
API_DEV_VERSION=${API_MAJOR_VERSION}"."${API_MINOR_VERSION}"."${ARLAS_DEV}
echo "Release : ${ARLAS_SUBSCRIPTIONS_VERSION}"
echo "API : ${FULL_API_VERSION}"
echo "Dev : ${ARLAS_DEV_VERSION}"
#########################################
#### Ongoing release process ############
#########################################
echo "=> Get develop branch"
if [ "$RELEASE" == "YES" ]; then
git checkout develop
git pull origin develop
else echo "=> Skip develop checkout"; fi
echo "=> Update project version"
mvn clean
mvn versions:set -DnewVersion=${ARLAS_SUBSCRIPTIONS_VERSION}
sed -i.bak 's/\"API_VERSION\"/\"'${FULL_API_VERSION}'\"/' subscriptions-manager/src/main/java/io/arlas/subscriptions/rest/UserSubscriptionManagerAbstractController.java
# Helm chart: Update version
sed -i.bak "s/^appVersion: .*\$/appVersion: \"${ARLAS_SUBSCRIPTIONS_VERSION}\"/" helm/arlas-subscriptions/Chart.yaml
sed -i.bak 's/^version: .*$/version: '${ARLAS_SUBSCRIPTIONS_VERSION}'/' helm/arlas-subscriptions/Chart.yaml
# Helm chart: Update docker images' versions
# Using `ruamel` to preserve comments & format
mv helm/arlas-subscriptions/values.yaml helm/arlas-subscriptions/values.yaml.old
docker run \
--entrypoint bash \
--env ARLAS_SUBSCRIPTIONS_VERSION \
--mount dst=/mnt/input.yaml,src="$PWD/helm/arlas-subscriptions/values.yaml.old",type=bind,readonly \
python:3.7-slim-buster -c "
pip install --upgrade pip >/dev/null 2>/dev/null
pip install ruamel.yaml==0.17.21 >/dev/null 2>/dev/null
python -c '
import pathlib
import sys
import ruamel.yaml
yaml = ruamel.yaml.YAML()
helm_values = yaml.load(pathlib.Path(\"/mnt/input.yaml\"))
helm_values[\"manager\"][\"image\"][\"tag\"] = \"$ARLAS_SUBSCRIPTIONS_VERSION\"
helm_values[\"matcher\"][\"image\"][\"tag\"] = \"$ARLAS_SUBSCRIPTIONS_VERSION\"
yaml.dump(helm_values, sys.stdout)
'
" > helm/arlas-subscriptions/values.yaml
rm -f helm/arlas-subscriptions/values.yaml.old
echo "=> Build arlas-subscriptions"
docker run \
-e GROUP_ID="$(id -g)" \
-e USER_ID="$(id -u)" \
--mount dst=/mnt/.m2,src="$HOME/.m2/",type=bind \
--mount dst=/opt/maven,src="$PWD",type=bind \
-w /opt/maven \
--rm \
maven:3.8.5-openjdk-17 \
mvn clean install
##################################################
#### Generate swagger definiton of the API #######
##################################################
echo "=> Start arlas-subscriptions-manager stack"
export ARLAS_SUB_TRIG_SCHEM_PATH="/opt/app/trigger.schema.json"
export ARLAS_SUB_TRIG_SCHEM_PATH_LOCAL="./subscriptions-tests/src/test/resources/trigger.schema.json"
docker compose --project-name arlas-subscriptions up -d --build elasticsearch mongodb mongo2 mongo3
DOCKER_IP=$(docker-machine ip || echo "localhost")
sleep 10
echo "===> configure replica set on mongodb"
docker exec mongodb /scripts/rs-init.sh
docker run --net arlas-subscriptions_default --rm busybox sh -c 'i=1; until nc -w 2 elasticsearch 9200; do if [ $i -lt 100 ]; then sleep 1; else break; fi; i=$(($i + 1)); done'
curl -X PUT "${DOCKER_IP}:9200/subs" -H 'Content-Type: application/json' -d'{}'
curl -X PUT "${DOCKER_IP}:9200/subs/_mapping/sub_type" -H 'Content-Type: application/json' -d @"./subscriptions-tests/src/test/resources/arlas.subtest.mapping.json"
docker compose --project-name arlas-subscriptions up -d --build arlas-subscriptions-manager arlas-subscriptions-matcher
echo "===> wait for arlas-subscriptions-manager up and running"
docker run --net arlas-subscriptions_default --rm busybox sh -c 'i=1; until nc -w 2 arlas-subscriptions-manager 9998; do if [ $i -lt 100 ]; then sleep 1; else break; fi; i=$(($i + 1)); done'
echo "=> Get swagger documentation"
mkdir -p target/tmp || echo "target/tmp exists"
i=1; until curl -XGET http://${DOCKER_IP}:9998/arlas-subscriptions-manager/openapi.json -o target/tmp/openapi.json; do if [ $i -lt 60 ]; then sleep 1; else break; fi; i=$(($i + 1)); done
i=1; until curl -XGET http://${DOCKER_IP}:9998/arlas-subscriptions-manager/openapi.yaml -o target/tmp/openapi.yaml; do if [ $i -lt 60 ]; then sleep 1; else break; fi; i=$(($i + 1)); done
mkdir -p openapi
cp target/tmp/openapi.yaml openapi
cp target/tmp/openapi.json openapi
echo "=> Stop arlas-subscriptions-manager stack"
docker compose --project-name arlas-subscriptions down -v
echo "=> Generate API documentation"
mkdir -p docs/api
cd subscriptions-manager/
docker run --rm \
--mount dst=/input/api.json,src="$PWD/../openapi/openapi.json",type=bind,ro \
--mount dst=/input/env.json,src="$PWD/../conf/doc/widdershins.json",type=bind,ro \
--mount dst=/output,src="$PWD/../docs/api",type=bind \
gisaia/widdershins:4.0.1
cd ..
itests() {
echo "=> Run integration tests"
./scripts/test-integration.sh
}
if [ "$TESTS" == "YES" ]; then itests; else echo "=> Skip integration tests"; fi
#########################################
#### Generate API clients ###############
#########################################
if [ "$SKIP_API" == "YES" ]; then
echo "=> Skipping generation of API clients"
else
echo "=> Generate API clients"
ls target/tmp/
mkdir -p target/tmp/typescript-fetch
docker run --rm \
-e GROUP_ID="$(id -g)" \
-e USER_ID="$(id -u)" \
--mount dst=/input/api.json,src="$PWD/target/tmp/openapi.json",type=bind,ro \
--mount dst=/output,src="$PWD/target/tmp/typescript-fetch",type=bind \
gisaia/swagger-codegen-3.0.42 \
-l typescript-fetch --additional-properties modelPropertyNaming=snake_case
echo "=> Build Typescript API "${FULL_API_VERSION}
cd ${BASEDIR}/target/tmp/typescript-fetch/
cp ${BASEDIR}/conf/npm/package-build.json package.json
cp ${BASEDIR}/conf/npm/tsconfig-build.json .
npm version --no-git-tag-version ${FULL_API_VERSION}
npm install
npm run build-release
npm run postbuild
cd ${BASEDIR}
echo "=> Publish Typescript API "
cp ${BASEDIR}/conf/npm/package-publish.json ${BASEDIR}/target/tmp/typescript-fetch/dist/package.json
cd ${BASEDIR}/target/tmp/typescript-fetch/dist
npm version --no-git-tag-version ${FULL_API_VERSION}
if [ "$RELEASE" == "YES" ]; then
npm publish || echo "Publishing on npm failed ... continue ..."
else echo "=> Skip npm api publish"; fi
fi
cd ${BASEDIR}
if [ "$RELEASE" == "YES" ]; then
echo "=> Tag arlas-subscriptions-manager docker image"
docker tag gisaia/arlas-subscriptions-manager:${ARLAS_SUBSCRIPTIONS_VERSION} gisaia/arlas-subscriptions-manager:latest
echo "=> Tag arlas-subscriptions-matcher docker image"
docker tag gisaia/arlas-subscriptions-matcher:${ARLAS_SUBSCRIPTIONS_VERSION} gisaia/arlas-subscriptions-matcher:latest
echo "=> Push arlas-subscriptions-manager docker image"
docker push gisaia/arlas-subscriptions-manager:${ARLAS_SUBSCRIPTIONS_VERSION}
docker push gisaia/arlas-subscriptions-manager:latest
echo "=> Push arlas-subscriptions-matcher docker image"
docker push gisaia/arlas-subscriptions-matcher:${ARLAS_SUBSCRIPTIONS_VERSION}
docker push gisaia/arlas-subscriptions-matcher:latest
else echo "=> Skip docker push image"; fi
if [ "$RELEASE" == "YES" ]; then
echo "=> Generate CHANGELOG.md"
git tag v${ARLAS_SUBSCRIPTIONS_VERSION}
git push origin v${ARLAS_SUBSCRIPTIONS_VERSION}
#@see scripts/build-github-changelog-generator.sh in ARLAS-server project if you need a fresher version of this tool
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app gisaia/github-changelog-generator:latest github_changelog_generator \
-u gisaia -p ARLAS-subscriptions --token ${GITHUB_CHANGELOG_TOKEN} \
--no-pr-wo-labels --no-issues-wo-labels --no-unreleased --issue-line-labels API,conf,security,documentation \
--exclude-labels type:duplicate,type:question,type:wontfix,type:invalid \
--bug-labels type:bug \
--enhancement-labels type:enhancement \
--breaking-labels type:breaking \
--enhancement-label "**New stuff:**" --issues-label "**Miscellaneous:**" --since-tag v0.0.1
git add CHANGELOG.md
git tag -d v${ARLAS_SUBSCRIPTIONS_VERSION}
git push origin :v${ARLAS_SUBSCRIPTIONS_VERSION}
echo "=> Commit release version"
git add openapi/openapi.json
git add openapi/openapi.yaml
git add docs/api
git commit -a -m "release version ${ARLAS_SUBSCRIPTIONS_VERSION}"
git tag v${ARLAS_SUBSCRIPTIONS_VERSION}
git push origin v${ARLAS_SUBSCRIPTIONS_VERSION}
git push origin develop
echo "=> Merge develop into master"
git checkout master
git pull origin master
git merge origin/develop
git push origin master
echo "=> Rebase develop"
git checkout develop
git pull origin develop
git rebase origin/master
else echo "=> Skip git push master"; fi
echo "=> Update project version for develop"
mvn versions:set -DnewVersion=${ARLAS_DEV_VERSION}-SNAPSHOT
echo "=> Update REST API version in JAVA source code"
sed -i.bak 's/\"'${FULL_API_VERSION}'\"/\"API_VERSION\"/' subscriptions-manager/src/main/java/io/arlas/subscriptions/rest/UserSubscriptionManagerAbstractController.java
if [ "$RELEASE" == "YES" ]; then
sed -i.bak 's/\"'${FULL_API_VERSION}'\"/\"'${API_DEV_VERSION}-SNAPSHOT'\"/' openapi/openapi.yaml
sed -i.bak 's/\"'${FULL_API_VERSION}'\"/\"'${API_DEV_VERSION}-SNAPSHOT'\"/' openapi/openapi.json
git add openapi/openapi.json
git add openapi/openapi.yaml
git commit -a -m "development version ${ARLAS_DEV_VERSION}-SNAPSHOT"
git push origin develop
else echo "=> Skip git push develop"; fi