-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_snapshot.sh
executable file
·347 lines (299 loc) · 8.94 KB
/
build_snapshot.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
#!/bin/bash
BUILD_DIR=/tmp/snapshot
CLONE_OPT="--filter=blob:none"
#SET_PROPERTY_OPT="-DgenerateBackupPoms=false -batch-mode --no-transfer-progress"
SET_PROPERTY_OPT="-DgenerateBackupPoms=false -q"
HELP_EVAL_OPT="-q -DforceStdout"
BUILD_OPT="-T1C"
TEST_OPT=""
MVN="mvn -Dmaven.repo.local=$BUILD_DIR/m2_repository"
function pause() {
read -s -n 1 -p "Press any key to continue..."
echo
}
function displayInfo() {
echo
echo
echo "Used versions"
echo "============="
echo "Core: $CORE_VERSION (branch main)"
echo "OLF: $LOADFLOW_VERSION (branch $LOADFLOW_BRANCH)"
echo "Diagram: $DIAGRAM_VERSION (branch $DIAGRAM_BRANCH)"
echo "Entsoe: $ENTSOE_VERSION (branch $ENTSOE_BRANCH)"
echo "Open RAO: $OPENRAO_VERSION (branch $OPENRAO_BRANCH)"
echo "Dynawo: $DYNAWO_VERSION (branch $DYNAWO_BRANCH)"
echo "Dependencies: $DEPENDENCIES_VERSION (branch $DEPENDENCIES_BRANCH)"
echo
echo
echo "Maven parameters"
echo "================"
grep "<powsybl.*version" ./*/pom.xml | awk -F':|>' '{ gsub(/\.\//,"",$1); gsub(/\/pom\.xml/,"",$1); gsub(/ *</,"",$2); gsub(/<\/.*/,"",$3); printf("%-25s %-30s %s \n", $1, $2, $3) }' | sort
echo
}
function usage() {
echo "Usage: $0 <build_from> [OPTIONS]"
echo " with <build_from> in:"
echo " - \"CORE\": build all repos;"
echo " - \"OLF\": build OFL, Diagram, Entsoe, Open-RAO, Dynawo and Dependencies;"
echo " - \"DIAGRAM\": build Diagram, Entsoe, Open-RAO, Dynawo and Dependencies;"
echo " - \"ENTSOE\": build Entsoe, Open-RAO, Dynawo and Dependencies;"
echo " - \"OPENRAO\": build Open-RAO, Dynawo and Dependencies;"
echo " - \"DYNAWO\": build Dynawo and Dependencies;"
echo " - \"DEPENDENCIES\": build Dependencies;"
echo " - \"NONE\": don't build anything (but retrieve the missing repos)"
echo " Possible options:"
echo " * --skip-tests: skip tests"
echo " * --mono-thread: maven build on single thread"
}
function success() {
echo
echo
echo "=== End ==="
displayInfo
}
# Handle non-positional options
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--skip-tests)
TEST_OPT=$TEST_OPT" -DskipTests"
echo "-> skipping tests"
shift # past argument
;;
--mono-thread)
BUILD_OPT=""
echo "-> maven build on single thread"
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ "$#" -ne 1 ]; then
usage
exit 3
fi
case $1 in
CORE)
START_FROM=0
;;
OLF)
START_FROM=1
;;
DIAGRAM)
START_FROM=2
;;
ENTSOE)
START_FROM=3
;;
OPENRAO)
START_FROM=4
;;
DYNAWO)
START_FROM=5
;;
DEPENDENCIES)
START_FROM=6
;;
NONE)
START_FROM=99
;;
*)
echo "Invalid value: $1"
usage
exit 2;
;;
esac
# Build starting from:
# - 0: Core
# - 1: OLF
# - 2: Diagram
# - 3: Entsoe
# - 4: Open-RAO
# - 5: Dynawo
# - 6: Dependencies
# - Greater: Won't build anything
#START_FROM=99
#START_FROM=0
SCRIPTS_PATH=$(pwd)/$(dirname "$0")
mkdir -p $BUILD_DIR/.versions
cd $BUILD_DIR
echo
echo "Retrieve missing repositories + set versions in pom.xml files:"
# == powsybl-core ==
echo "- powsybl-core"
if [ ! -e powsybl-core ]; then
git clone "$CLONE_OPT" https://github.com/powsybl/powsybl-core.git
fi
cd powsybl-core
CORE_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
cd ..
# == powsybl-open-loadflow ==
REPO=powsybl-open-loadflow
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
cd $REPO
git restore pom.xml
LOADFLOW_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
LOADFLOW_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -Dproperty=powsybl-core.version -DnewVersion="$CORE_VERSION" $SET_PROPERTY_OPT
cd ..
# == powsybl-diagram ==
REPO=powsybl-diagram
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
cd $REPO
git restore pom.xml
DIAGRAM_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
DIAGRAM_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -Dproperty=powsybl-core.version -DnewVersion="$CORE_VERSION" $SET_PROPERTY_OPT
cd ..
# == powsybl-entsoe ==
REPO=powsybl-entsoe
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
echo -e "\
powsyblcore.version=$CORE_VERSION\n\
powsyblopenloadflow.version=$LOADFLOW_VERSION" > .versions/entsoe
cd $REPO
git restore pom.xml
ENTSOE_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
ENTSOE_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -DpropertiesVersionsFile="../.versions/entsoe" $SET_PROPERTY_OPT
cd ..
# == powsybl-open-rao ==
REPO=powsybl-open-rao
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
echo -e "\
powsybl.core.version=$CORE_VERSION\n\
powsybl.entsoe.version=$ENTSOE_VERSION\n\
powsybl.openloadflow.version=$LOADFLOW_VERSION" > .versions/open-rao
cd $REPO
git restore pom.xml
OPENRAO_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
OPENRAO_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -DpropertiesVersionsFile="../.versions/open-rao" $SET_PROPERTY_OPT
cd ..
# == powsybl-dynawo ==
REPO=powsybl-dynawo
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
cd $REPO
git restore pom.xml
DYNAWO_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
DYNAWO_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -Dproperty=powsybl-core.version -DnewVersion="$CORE_VERSION" $SET_PROPERTY_OPT
cd ..
# == powsybl-dependencies ==
REPO=powsybl-dependencies
echo "- $REPO"
if [ ! -e $REPO ]; then
SNAPSHOT_BRANCH=$($SCRIPTS_PATH/check_snapshot_branch.sh "https://github.com/powsybl/$REPO.git" "$CORE_VERSION")
git clone "$CLONE_OPT" -b "$SNAPSHOT_BRANCH" "https://github.com/powsybl/$REPO.git"
fi
echo -e "\
powsybl-core.version=$CORE_VERSION\n\
powsybl-open-loadflow.version=$LOADFLOW_VERSION\n\
powsybl-diagram.version=$DIAGRAM_VERSION\n\
powsybl-dynawo.version=$DYNAWO_VERSION\n\
powsybl-entsoe.version=$ENTSOE_VERSION\n\
powsybl-open-rao.version=$OPENRAO_VERSION" > .versions/dependencies
cd $REPO
git restore pom.xml
DEPENDENCIES_VERSION=$($MVN help:evaluate -Dexpression=project.version $HELP_EVAL_OPT)
DEPENDENCIES_BRANCH=$(git rev-parse --abbrev-ref HEAD)
$MVN versions:set-property -DpropertiesVersionsFile="../.versions/dependencies" $SET_PROPERTY_OPT
cd ..
if [ $START_FROM -eq 99 ]
then
success
exit 0
fi
displayInfo
pause
# == BUILD ==
if [ $START_FROM -lt 1 ]
then
cd powsybl-core
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT -DskipTests
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 2 ]
then
cd powsybl-open-loadflow
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 3 ]
then
cd powsybl-diagram
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 4 ]
then
cd powsybl-entsoe
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 5 ]
then
cd powsybl-open-rao
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 6 ]
then
cd powsybl-dynawo
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
if [ $START_FROM -lt 7 ]
then
cd powsybl-dependencies
$MVN -batch-mode --no-transfer-progress clean install $BUILD_OPT $TEST_OPT
if [[ "$?" -ne 0 ]] ; then
exit 1
fi
cd ..
fi
success