-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-noDocker.sh
executable file
·189 lines (167 loc) · 4.25 KB
/
build-noDocker.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
#!/bin/bash
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 yarn.lock
}
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
PRECOMMIT_CMD="yarn test && yarn docs && git add ./docs/*"
yarn install && yarn prepare && npx husky add .husky/pre-commit "$PRECOMMIT_CMD" # && git add .husky/pre-commit"
}
tests () {
yarn test
}
build () {
yarn build
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"
yarn watch --build_target=dist
else
echo "Watching => $SPRINGBOARD springboard"
yarn watch --build_target=$PWD/../$SPRINGBOARD/assets/js/ode-ts-client
fi
}
audit () {
yarn audit
}
doc () {
yarn docs
}
publishNPM () {
LOCAL_BRANCH=`echo $GIT_BRANCH | sed -e "s|origin/||g"`
yarn publish --tag $LOCAL_BRANCH
}
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)
tests
;;
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