-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.sh
executable file
·329 lines (282 loc) · 12.6 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
#!/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
DOCKER_COMPOSE="${PROJECT_ROOT_DIRECTORY}/docker/docker-files/docker-compose.yml"
#########################################
#### Cleaning functions #################
#########################################
function clean_docker {
echo "===> Stop arlas-persistence-server stack"
docker-compose -f ${DOCKER_COMPOSE} --project-name arlas 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
git checkout -- arlas-persistence-core/pom.xml
git checkout -- arlas-persistence-rest/pom.xml
git checkout -- arlas-persistence-server/pom.xml
git checkout -- arlas-persistence-tests/pom.xml
sed -i.bak 's/\"'${FULL_API_VERSION}'\"/\"API_VERSION\"/' arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.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 [--no-tests] [--skip-api]"
echo " -api-major|--api-version release arlas-persistence-server API major version"
echo " -api-minor|--api-minor-version release arlas-persistence-server API minor version"
echo " -api-patch|--api-patch-version release arlas-persistence-server API patch version"
echo " -rel|--arlas-release release arlas-server version"
echo " -dev|--arlas-dev development arlas-persistence-server 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_persistence_VERSION="${API_MAJOR_VERSION}.0.${ARLAS_REL}"
ARLAS_DEV_VERSION="${API_MAJOR_VERSION}.0.${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_persistence_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_persistence_VERSION}
sed -i.bak 's/\"API_VERSION\"/\"'${FULL_API_VERSION}'\"/' arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java
if [ "$RELEASE" == "YES" ]; then
export DOCKERFILE="${PROJECT_ROOT_DIRECTORY}/docker/docker-files/Dockerfile"
else
echo "=> Build arlas-persistence-server"
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 \
--rm \
gisaia/maven-3.5-jdk8-alpine \
clean install
fi
#########################################
#### Generate swagger definiton of the API #######
#########################################
echo "=> Start arlas-persistence-server stack"
docker-compose -f ${DOCKER_COMPOSE} --project-name arlas up -d --build
DOCKER_IP=$(docker-machine ip || echo "localhost")
echo "=> Wait for arlas-persistence-server up and running"
i=1; until nc -w 2 ${DOCKER_IP} 19997; do if [ $i -lt 30 ]; 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}:19997/arlas_persistence_server/swagger.json -o target/tmp/swagger.json; do if [ $i -lt 60 ]; then sleep 1; else break; fi; i=$(($i + 1)); done
i=1; until curl -XGET http://${DOCKER_IP}:19997/arlas_persistence_server/swagger.yaml -o target/tmp/swagger.yaml; do if [ $i -lt 60 ]; then sleep 1; else break; fi; i=$(($i + 1)); done
echo "=> Stop arlas-persistence-server stack"
docker-compose -f ${DOCKER_COMPOSE} --project-name arlas down -v
echo "=> Generate API documentation"
mvn "-Dswagger.output=docs/api" swagger2markup:convertSwagger2markup
itests() {
echo "=> Run integration tests"
./scripts/tests-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/swagger.json",type=bind,ro \
--mount dst=/output,src="$PWD/target/tmp/typescript-fetch",type=bind \
gisaia/swagger-codegen-2.3.1 \
-l typescript-fetch --additional-properties modelPropertyNaming=snake_case
mkdir -p target/tmp/python-api
docker run --rm \
-e GROUP_ID="$(id -g)" \
-e USER_ID="$(id -u)" \
--mount dst=/input/api.json,src="$PWD/target/tmp/swagger.json",type=bind,ro \
--mount dst=/input/config.json,src="$PROJECT_ROOT_DIRECTORY/conf/swagger/python-config.json",type=bind,ro \
--mount dst=/output,src="$PWD/target/tmp/python-api",type=bind \
gisaia/swagger-codegen-2.2.3 \
-l python --type-mappings GeoJsonObject=object
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
echo "=> Build Python API "${FULL_API_VERSION}
cd ${BASEDIR}/target/tmp/python-api/
cp ${BASEDIR}/conf/python/setup.py setup.py
sed -i.bak 's/\"api_persistence_version\"/\"'${FULL_API_VERSION}'\"/' setup.py
docker run \
-e GROUP_ID="$(id -g)" \
-e USER_ID="$(id -u)" \
--mount dst=/opt/python,src="$PWD",type=bind \
--rm \
gisaia/python-3-alpine \
setup.py sdist bdist_wheel
echo "=> Publish Python API "
if [ "$RELEASE" == "YES" ]; then
docker run --rm \
-w /opt/python \
-v $PWD:/opt/python \
python:3 \
/bin/bash -c "pip install twine ; twine upload dist/* -u ${PIP_LOGIN} -p ${PIP_PASSWORD}"
### At this stage username and password of Pypi repository should be set
else echo "=> Skip python api publish"; fi
fi
cd ${BASEDIR}
if [ "$RELEASE" == "YES" ]; then
echo "=> Tag arlas-persistence-server docker image"
docker tag gisaia/arlas-persistence-server:latest gisaia/arlas-persistence-server:${ARLAS_persistence_VERSION}
echo "=> Push arlas-persistence-server docker image"
docker push gisaia/arlas-persistence-server:${ARLAS_persistence_VERSION}
docker push gisaia/arlas-persistence-server:latest
else echo "=> Skip docker push image"; fi
if [ "$RELEASE" == "YES" ]; then
echo "=> Generate CHANGELOG.md"
git tag v${ARLAS_persistence_VERSION}
git push origin v${ARLAS_persistence_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-persistence --token 479b4f9b9390acca5c931dd34e3b7efb21cbf6d0 \
--no-pr-wo-labels --no-issues-wo-labels --no-unreleased --issue-line-labels API,OGC,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 tag -d v${ARLAS_persistence_VERSION}
git push origin :v${ARLAS_persistence_VERSION}
echo "=> Commit release version"
git add docs/api
git commit -a -m "release version ${ARLAS_persistence_VERSION}"
git tag v${ARLAS_persistence_VERSION}
git push origin v${ARLAS_persistence_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\"/' arlas-persistence-rest/src/main/java/io/arlas/persistence/rest/PersistenceRestService.java
if [ "$RELEASE" == "YES" ]; then
git commit -a -m "development version ${ARLAS_DEV_VERSION}-SNAPSHOT"
git push origin develop
else echo "=> Skip git push develop"; fi