-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrelease.sh
executable file
·236 lines (201 loc) · 7 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
#!/bin/bash
set -e
SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd)"
PROJECT_ROOT_DIRECTORY="$(dirname "$SCRIPT_DIRECTORY")"
if [ -z "$GITHUB_CHANGELOG_TOKEN" ] ; then echo "Please set GITHUB_CHANGELOG_TOKEN environment variable"; exit -1; fi
echo "=> Docker login"
echo "${DOCKER_PASSWORD}" | docker login -u ${DOCKER_USERNAME} --password-stdin
function clean {
ARG=$?
echo "==> Exit status = $ARG"
exit $ARG
}
trap clean EXIT
usage(){
echo "Usage: ./release.sh -version=X"
echo " -version Release ARLAS-wui X version"
echo " --not-latest Doesn't tag the release version as the latest."
echo " -s|--stage Stage of the release : beta | rc | stable. If --stage is 'rc' or 'beta', there is no merge of develop into master (if -ref_branch=develop)"
echo " -i|--stage_iteration=n The released version will be : [x].[y].[z]-beta.[n] OR [x].[y].[z]-rc.[n] according to the given --stage"
echo " -ref_branch|--reference_branch From which branch to start the release."
echo " Add -ref_branch=develop for a new official release"
echo " Add -ref_branch=x.x.x for a maintenance release"
exit 1
}
send_chat_message(){
MESSAGE=$1
if [ -z "$GOOGLE_CHAT_RELEASE_CHANEL" ] ; then
echo "Environement variable GOOGLE_CHAT_RELEASE_CHANEL is not definied ... skipping message publishing"
else
DATA='{"text":"'${MESSAGE}'"}'
echo $DATA
curl -X POST --header "Content-Type:application/json" $GOOGLE_CHAT_RELEASE_CHANEL -d "${DATA}"
fi
}
STAGE="stable"
TESTS="YES"
IS_LATEST_VERSION="YES"
for i in "$@"
do
case $i in
-version=*)
VERSION="${i#*=}"
shift # past argument=value
;;
--not-latest)
IS_LATEST_VERSION="NO"
shift # past argument with no value
;;
-ref_branch=*|--reference_branch=*)
REF_BRANCH="${i#*=}"
shift # past argument=value
;;
-s=*|--stage=*)
STAGE="${i#*=}"
shift # past argument=value
;;
-i=*|--stage_iteration=*)
STAGE_ITERATION="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
if [ -z ${REF_BRANCH+x} ];
then
echo ""
echo "###########"
echo "-ref_branch is missing."
echo " Add -ref_branch=develop for a new official release"
echo " Add -ref_branch=x.x.x for a maintenance release"
echo "###########"
echo ""
usage;
fi
if [ -z ${STAGE+x} ];
then
echo ""
echo "###########"
echo "-s=*|--stage* is missing."
echo " Add --stage=beta|rc|stable to define the release stage"
echo "###########"
echo ""
usage;
fi
if [ "${STAGE}" != "beta" ] && [ "${STAGE}" != "rc" ] && [ "${STAGE}" != "stable" ];
then
echo ""
echo "###########"
echo "Stage ${STAGE} is invalid."
echo " Add --stage=beta|rc|stable to define the release stage"
echo "###########"
echo ""
usage;
fi
if [ "${STAGE}" == "beta" ] || [ "${STAGE}" == "rc" ];
then
if [ -z ${STAGE_ITERATION+x} ];
then
echo ""
echo "###########"
echo "You chose to release this version as ${STAGE}."
echo "--stage_iteration is missing."
echo " Add -i=n|--stage_iteration=n, the released version will be : [x].[y].[z]-${STAGE}.[n]"
echo "###########"
echo ""
usage;
fi
fi
echo "==> Get $REF_BRANCH branch"
git checkout "$REF_BRANCH"
git pull origin "$REF_BRANCH"
if [ "${STAGE}" == "rc" ] || [ "${STAGE}" == "beta" ];
then
VERSION="${VERSION}-${STAGE}.${STAGE_ITERATION}"
fi
echo "==> Set version"
npm --no-git-tag-version version ${VERSION}
npm --no-git-tag-version --prefix src version ${VERSION}
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add package.json
git add src/package.json
echo " -- Create and push tag"
git tag -a v${VERSION} -m "prod automatic release ${VERSION}"
git push origin v${VERSION}
echo "==> Generate CHANGELOG"
docker run --rm -v "$(pwd)":/usr/local/src/your-app gisaia/github-changelog-generator:latest github_changelog_generator \
-u gisaia -p ARLAS-WUI --token ${GITHUB_CHANGELOG_TOKEN} --no-pr-wo-labels --no-issues-wo-labels --no-unreleased \
--issue-line-labels conf,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 v4.0.0
echo " -- Remove tag to add generated CHANGELOG"
git tag -d v${VERSION}
git push origin :v${VERSION}
echo " -- Commit release version"
git commit -a -m "prod automatic release ${VERSION}"
git tag v${VERSION}
git push origin v${VERSION}
git push origin ${REF_BRANCH}
echo "==> Clean local environment"
npm cache clean --force
rm -rf node_modules/
echo "==> Docker"
docker build -f docker/Dockerfile --no-cache --build-arg version=${VERSION} --build-arg WORKSPACE=cloud --tag gisaia/arlas-wui-cloud:${VERSION} .
docker build -f docker/Dockerfile --no-cache --build-arg version=${VERSION} --build-arg WORKSPACE=opensource --tag gisaia/arlas-wui:${VERSION} .
docker push gisaia/arlas-wui-cloud:${VERSION}
docker push gisaia/arlas-wui:${VERSION}
if [ "${STAGE}" == "stable" ] && [ "${IS_LATEST_VERSION}" == "YES" ];
then
docker tag gisaia/arlas-wui:${VERSION} gisaia/arlas-wui:latest
docker tag gisaia/arlas-wui-cloud:${VERSION} gisaia/arlas-wui-cloud:latest
docker push gisaia/arlas-wui-cloud:latest
docker push gisaia/arlas-wui:latest
fi
echo "==> Build arlas-wui library"
rm -rf dist
rm -rf node_modules/
npm install --workspaces=false
npm run build-lib
cd dist/arlas-wui
echo "==> Publish to npm"
if [ "${STAGE}" == "rc" ] || [ "${STAGE}" == "beta" ];
then
echo " -- tagged as ${STAGE}"
npm publish --tag=${STAGE}
else
npm publish
fi
cd ../..
echo "==> Clean local environment"
npm cache clean --force
rm -rf node_modules/
if [ "${REF_BRANCH}" == "develop" ] && [ "${STAGE}" == "stable" ];
then
echo "==> Merge develop into master"
git checkout master
git pull origin master
git merge origin/develop
git push origin master
git checkout develop
git pull origin develop
git rebase origin/master
fi
IFS='.' read -ra TAB <<< "$VERSION"
major=${TAB[0]}
minor=${TAB[1]}
newminor=$(( $minor + 1 ))
newDevVersion=${major}.${newminor}.0
npm --no-git-tag-version version "${newDevVersion}-dev"
npm --no-git-tag-version --prefix src version "${newDevVersion}-dev"
git commit -a -m "development version ${newDevVersion}-dev"
git push origin ${REF_BRANCH}
echo "==> Well done :)"
if [ "$STAGE" == "stable" ] || [ "$STAGE" == "rc" ];
then
send_chat_message "Release of arlas-wui, version ${VERSION}"
send_chat_message "Release of arlas-wui-cloud, version ${VERSION}"
fi