-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·242 lines (219 loc) · 5.86 KB
/
build.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
#!/bin/bash
# Options
NO_DOCKER=""
for i in "$@"
do
case $i in
--no-docker*)
NO_DOCKER="true"
shift
;;
*)
;;
esac
done
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <clean|init|build|install|watch>"
echo "Example: $0 clean"
echo "Example: $0 init"
echo "Example: $0 build"
echo "Example: $0 install"
echo "Example: $0 [--springboard=recette] watch"
exit 1
fi
MVN_MOD_GROUPID=`grep 'modowner=' gradle.properties | sed 's/modowner=//'`
MVN_MOD_NAME=`grep 'modname=' gradle.properties | sed 's/modname=//'`
MVN_MOD_VERSION=`grep 'version=' gradle.properties | sed 's/version=//'`
if [ ! -e node_modules ]
then
mkdir node_modules
fi
if [ -z ${USER_UID:+x} ]
then
export USER_UID=1000
export GROUP_GID=1000
fi
if [ -e "?/.gradle" ] && [ ! -e "?/.gradle/gradle.properties" ]
then
echo "odeUsername=$NEXUS_ODE_USERNAME" > "?/.gradle/gradle.properties"
echo "odePassword=$NEXUS_ODE_PASSWORD" >> "?/.gradle/gradle.properties"
echo "sonatypeUsername=$NEXUS_SONATYPE_USERNAME" >> "?/.gradle/gradle.properties"
echo "sonatypePassword=$NEXUS_SONATYPE_PASSWORD" >> "?/.gradle/gradle.properties"
fi
# options
SPRINGBOARD=""
for i in "$@"
do
case $i in
-s=*|--springboard=*)
SPRINGBOARD="${i#*=}"
shift
;;
*)
;;
esac
done
clean () {
rm -rf node_modules dist test .husky .gradle package.json package-lock.json deployment pnpm-lock.yaml .pnpm-store
}
init () {
echo "[init] Get branch name from jenkins env..."
BRANCH_NAME=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
if [ "$BRANCH_NAME" = "" ]; then
echo "[init] Get branch name from git..."
BRANCH_NAME=`git branch | sed -n -e "s/^\* \(.*\)/\1/p"`
fi
echo "[init] Generate deployment file from conf.deployment..."
mkdir -p deployment/$MVN_MOD_NAME
cp conf.deployment deployment/$MVN_MOD_NAME/conf.json.template
sed -i "s/%MODNAME%/${MVN_MOD_NAME}/" deployment/$MVN_MOD_NAME/conf.json.template
sed -i "s/%VERSION%/${MVN_MOD_VERSION}/" deployment/$MVN_MOD_NAME/conf.json.template
echo "[init] Generate package.json from package.json.template..."
NPM_VERSION_SUFFIX=`date +"%Y%m%d%H%M"`
cp package.json.template package.json
sed -i "s/%generateVersion%/${NPM_VERSION_SUFFIX}/" package.json
if [ "$NO_DOCKER" = "true" ] ; then
pnpm install && pnpm run prepare && npx husky add .husky/pre-commit "pnpm run test && pnpm run docs && git add ./docs/*"
else
PRECOMMIT_CMD="docker-compose run --rm -u \\\"$USER_UID:$GROUP_GID\\\" node sh -c \\\"pnpm run test && pnpm run docs\\\" && git add ./docs/*"
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm install && pnpm run prepare && npx husky add .husky/pre-commit \"$PRECOMMIT_CMD\""
fi
}
test () {
if [ "$NO_DOCKER" = "true" ] ; then
pnpm run test
else
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm run test"
fi
}
build () {
if [ "$NO_DOCKER" = "true" ] ; then
pnpm run build
else
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm run build"
fi
status=$?
if [ $status != 0 ];
then
exit $status
fi
VERSION=`grep "version=" gradle.properties| sed 's/version=//g'`
echo "ode-ts-client=$VERSION `date +'%d/%m/%Y %H:%M:%S'`" >> dist/version.txt
}
watch () {
if [ -z $SPRINGBOARD ]; then
echo "Watching => ./dist folder"
if [ "$NO_DOCKER" = "true" ] ; then
pnpm run watch --build_target=dist
else
docker-compose run \
--rm \
-u "$USER_UID:$GROUP_GID" \
node sh -c "npm run watch --build_target=dist"
fi
else
echo "Watching => $SPRINGBOARD springboard"
if [ "$NO_DOCKER" = "true" ] ; then
pnpm run watch --build_target=$PWD/../$SPRINGBOARD/assets/js/ode-ts-client
else
docker-compose run \
--rm \
-u "$USER_UID:$GROUP_GID" \
-v $PWD/../$SPRINGBOARD:/home/node/springboard \
node sh -c "pnpm run watch --build_target=/home/node/springboard/assets/js/ode-ts-client"
fi
fi
}
audit () {
if [ "$NO_DOCKER" = "true" ] ; then
npm audit
else
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm run audit"
fi
}
doc () {
if [ "$NO_DOCKER" = "true" ] ; then
pnpm run docs
else
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm run docs"
fi
}
publishNPM () {
LOCAL_BRANCH=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
if [ "$NO_DOCKER" = "true" ] ; then
pnpm publish --tag $LOCAL_BRANCH
else
docker-compose run --rm -u "$USER_UID:$GROUP_GID" node sh -c "pnpm publish --no-git-checks --tag $LOCAL_BRANCH"
fi
}
# archive() {
# echo "[archive] Archiving dist folder and conf.j2 file..."
# tar cfzh ${MVN_MOD_NAME}.tar.gz dist/* ode-ts-client/conf.j2
# }
publishNexus () {
case "$MVN_MOD_VERSION" in
*SNAPSHOT) nexusRepository='snapshots' ;;
*) nexusRepository='releases' ;;
esac
mvn deploy:deploy-file \
--batch-mode \
-DgroupId=$MVN_MOD_GROUPID \
-DartifactId=$MVN_MOD_NAME \
-Dversion=$MVN_MOD_VERSION \
-Dpackaging=tar.gz \
-Dfile=${MVN_MOD_NAME}.tar.gz \
-DrepositoryId=wse \
-Durl=https://maven.opendigitaleducation.com/nexus/content/repositories/$nexusRepository/
}
publishMavenLocal(){
mvn install:install-file \
--batch-mode \
-DgroupId=$MVN_MOD_GROUPID \
-DartifactId=$MVN_MOD_NAME \
-Dversion=$MVN_MOD_VERSION \
-Dpackaging=tar.gz \
-Dfile=${MVN_MOD_NAME}.tar.gz
}
for param in "$@"
do
case $param in
clean)
clean
;;
init)
init
;;
build)
build
;;
test)
test
;;
watch)
watch
;;
doc)
doc
;;
install)
build && archive && publishMavenLocal && rm -rf build
;;
audit)
audit
;;
archive)
archive
;;
publishNPM)
publishNPM
;;
publishNexus)
publishNexus
;;
*)
echo "Invalid argument : $action"
esac
if [ ! $? -eq 0 ]; then
exit 1
fi
done