-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathall-projects.sh
More file actions
executable file
·646 lines (614 loc) · 24.3 KB
/
Copy pathall-projects.sh
File metadata and controls
executable file
·646 lines (614 loc) · 24.3 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
#!/usr/bin/env bash
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## (C) Copyright 2018-2026 Modeling Value Group B.V. (http://modelingvalue.org) ~
## ~
## Licensed under the GNU Lesser General Public License v3.0 (the 'License'). You may not use this file except in ~
## compliance with the License. You may obtain a copy of the License at: https://choosealicense.com/licenses/lgpl-3.0 ~
## Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on ~
## an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the ~
## specific language governing permissions and limitations under the License. ~
## ~
## Maintainers: ~
## Wim Bast, Tom Brus ~
## ~
## Contributors: ~
## Ronald Krijgsheld ✝, Arjan Kok, Carel Bast ~
## --------------------------------------------------------------------------------------------------------------------- ~
## In Memory of Ronald Krijgsheld, 1972 - 2023 ~
## Ronald was suddenly and unexpectedly taken from us. He was not only our long-term colleague and team member ~
## but also our friend. "He will live on in many of the lines of code you see below." ~
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#set -x
set -euo pipefail
INTENDED_PROJECT_VERSION="6.0.0"
INTENDED_GRADLE_VERSION="9.7.1"
INTENDED_JAVA_VERSION="21"
repoSeq=(
sync-proxy
mvg-json
immutable-collections
dclare
dclareForJava
dclareForMPS
cdm
cds-runtime
cdm-generator
)
###########################################################################################################################
if ((BASH_VERSINFO[0] < 4)); then
OTHER_BASH='/opt/local/bin/bash'
if [[ -x "$OTHER_BASH" ]] && (( $("$OTHER_BASH" <<<'echo $BASH_VERSION'|sed 's/[.].*//') >= 4 )); then
echo "INFO: restarting with "$OTHER_BASH" because this bash is too old but that one is new enough."
exec "$OTHER_BASH" "$0" "$@"
fi
echo "ERROR: bash 4.0 or newer is required"
exit 1
fi
trap "onError" ERR
getJavaProjectMajorVersion() {
local v=''
declare -A repo2version version2repo
for repo in "${repoSeq[@]}"; do
v="$(egrep '^version_java[ =]' ../$repo/gradle.properties 2>/dev/null | sed 's/.*= *//')"
if [[ "$v" != "" ]]; then
repo2version["$repo"]="$v"
version2repo["$v"]+="$repo"
fi
done
case "${#version2repo[@]}" in
0) echo "ERROR: java version can not be determined" 1>&2;;
1) echo "${!version2repo[@]}";;
*)
echo "ERROR: java versions do not match accross projects:" 1>&2
for repo in "${repoSeq[@]}"; do
printf " - %-24s: %s\n" "$repo" "${repo2version[$repo]}" 1>&2
done
esac
}
getJavaActiveMajorVersion() {
java -version 2>&1 \
| awk -F '"' '/version/ {gsub(/[.].*/,"");print $2}'
}
switchToCorrectJavaVersion() {
local projectVersion="$(getJavaProjectMajorVersion)"
local activeVersion="$(getJavaActiveMajorVersion)"
if [[ "$projectVersion" == "" ]]; then
exit 89
fi
if [[ "$projectVersion" != "$activeVersion" ]]; then
if [[ -x "/usr/libexec/java_home" ]]; then
local oldVersion="$activeVersion"
export JAVA_HOME="$(/usr/libexec/java_home -v $projectVersion)"
activeVersion="$(getJavaActiveMajorVersion)"
if [[ "$projectVersion" != "$activeVersion" ]]; then
echo "ERROR: can not select correct java version (need $projectVersion but active is $activeVersion, JAVA_HOME=$JAVA_HOME) with '/usr/libexec/java_home -v $projectVersion'"
exit 55
fi
echo "INFO: switched java version from $oldVersion to $activeVersion"
else
echo "ERROR: incorrect java version active $activeVersion i.s.o. $projectVersion"
fi
fi
}
playSound() {
command -v afplay >/dev/null 2>&1 || return 0 # no-op off macOS (e.g. CI)
afplay "done.wav" & sleep 0.3
afplay "done.wav" & sleep 0.3
afplay "done.wav" & sleep 0.3
}
onError() {
playSound
}
numLines() {
wc -l | sed 's/ //g;s/^0$/ /'
}
sec() {
date +%s
}
# option 'c' = CI build: clean+build like option 4 but with NO git actions
# (no cloneFetch, no pull). Meant to be run non-interactively (stdin 'c') after
# the caller has already put the repos on the wanted branch. See main().
all=012345678dtvc
doOverview=012345678__v_
doGradleVersion=_123456____v_
doJavaVersion=_123456____v_
doProjectVersion=_123456____v_
doPull=_12_456______
doClean=__234_6_____c
doPublish=___3456_____c
doTest=______6______
doLog=_______7_____
doToDate=________8____
doTimes=__23456_____c
askWhatToDo() {
REPLY="x"
while ! [[ "$REPLY" =~ ^[$all]$ ]]; do
cat <<EOF >&2
0 - overview only
1 - pull
2 - pull clean
3 - clean build
4 - pull clean build
5 - pull build
6 - pull clean build test
7 - list recent commits on develop
8 - move to a date, after reset & develop [CAUTION will trash any changes in workdir]
d - dev extra's
t - test
v - check and update versions
c - clean build, no git actions (for CI; run non-interactively)
EOF
read -p "what to do? [0] " -n 1 -r
echo 1>&2
if [[ "$REPLY" == "" ]]; then
REPLY=0
fi
done
echo -n "$REPLY"
}
forAllProjects() {
local fun="$1"; shift
local here="$PWD"
for repo in "${repoName[@]}"; do
mkdir -p ../$repo
cd "../$repo"
"$fun" "$repo"
cd "$here"
done
wait
}
getBranch() {
printf "[%s]='%s' " "$1" "$(git rev-parse --abbrev-ref HEAD)"
}
getVersion() {
printf "[%s]='%s' " "$1" "$(if [[ ! -f gradle.properties ]]; then echo ''; else egrep '^version[ =]' gradle.properties | sed 's/.*= *//'; fi)"
}
getNumAhead() {
printf "[%s]='%s' " "$1" "$(if ! git cherry &>/dev/null; then echo "-"; else git cherry | numLines; fi)"
}
getNumBehind() {
printf "[%s]='%s' " "$1" "$(if ! git log HEAD..origin/${branchOf[$1]} --oneline &>/dev/null; then echo "-"; else git log HEAD..origin/${branchOf[$1]} --oneline | numLines; fi)"
}
getNumDirty() {
printf "[%s]='%s' " "$1" "$(git status --porcelain | numLines || :)"
}
getNumDependabot() {
printf "[%s]='%s' " "$1" "$(listDependabotBranches | tr ' ' '\n' | numLines || :)"
}
listLocalBranches() {
local raw="$(git branch | sed 's|..||' | sort)"
local rst="$(egrep -v '^(master|develop)$' <<<"$raw")"
if [[ "$(fgrep -x develop <<<"$raw")" ]]; then printf "d "; else printf ". "; fi
if [[ "$(fgrep -x master <<<"$raw")" ]]; then printf "m "; else printf ". "; fi
printf "%s " $rst
}
listRemoteBranches() {
local raw="$(git branch -r | sed '/^ origin[/]HEAD/d;s|..origin/||' | sort)"
local rst="$(egrep -v '^(master|develop)$' <<<"$raw" | egrep -v '^dependabot/.*')"
if [[ "$(fgrep -x develop <<<"$raw")" ]]; then printf "d "; else printf ". "; fi
if [[ "$(fgrep -x master <<<"$raw")" ]]; then printf "m "; else printf ". "; fi
printf "%s " $rst
}
listDependabotBranches() {
local raw="$(git branch -r | sed '/^ origin[/]HEAD/d;s|..origin/||' | sort)"
local rst="$(egrep -v '^(master|develop)$' <<<"$raw" | egrep '^dependabot/.*' | sed 's|^dependabot/[^/]*/[^/]*/||')"
if [[ "$rst" != "" ]]; then
printf "%s " $rst
fi
}
getProperty() {
local file="$1"; shift
local key="$1"; shift
touch "$file"
sed -n "s/^${key} *= *//p" "$file"
}
setProperty() {
local file="$1"; shift
local key="$1"; shift
local value="$1"; shift
touch "$file"
if grep -q "^${key} *= *" "$file" 2>/dev/null; then
sed -i.bak -e "s|^\(${key} *= *\).*|\1${value}|" "$file"
rm -f "$file.bak"
else
echo "${key}=${value}" >> "$file"
fi
}
###########################################################################################################################
cloneFetchAll() {
echo
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ clone/fetch\n"
forAllProjects cloneFetch
# filter out all projects that could not be cloned (probably private):
local copy=()
for repo in "${repoSeq[@]}"; do
if [[ -e ../$repo/.git ]]; then
copy+=($repo)
fi
done
repoSeq=(${copy[@]})
local copy=()
for repo in "${repoName[@]}"; do
if [[ -e ../$repo/.git ]]; then
copy+=($repo)
fi
done
repoName=(${copy[@]})
}
cloneFetch() {
local repo="$1"; shift
(
if [[ ! -e ".git" ]]; then
printf "# %-30s - cloning...\n" "$repo"
rm -rf TMP_GIT
GIT_TERMINAL_PROMPT=0 git clone https://github.com/ModelingValueGroup/$repo.git TMP_GIT >/dev/null 2>&1 \
|| GIT_TERMINAL_PROMPT=0 git clone git@github.com:ModelingValueGroup/$repo.git TMP_GIT >/dev/null 2>&1 \
|| :
if [[ -d "TMP_GIT/.git" ]]; then
cp -R TMP_GIT/. .
rm -rf TMP_GIT
if [[ "$(listRemoteBranches | tr ' ' '\n' | egrep '^d$')" ]]; then
printf "# %-30s - switching to develop branch...\n" "$repo" 1>&2
git checkout develop >/dev/null 2>&1 || :
fi
fi
fi
if [[ ! -e ".git" ]]; then
printf "# %-30s - not available\n" "$repo" 1>&2
else
git fetch --progress --prune --all >/dev/null 2>&1
printf "# %-30s - done\n" "$repo" 1>&2
fi
)&
}
pullAll() {
echo
echo "############################################ pull..."
forAllProjects pull
}
pull() {
local repo="$1"; shift
(
git pull --all --ff-only 2>&1 | egrep "(file changed|insertions|deletions)" | sed "s/^/$repo: /" || :
)&
}
projectInfoSeparator() {
local repo="${1:-}"
if [[ "$repo" == "" ]] || [[ "$repo" == dclareForMPS ]] || [[ "$repo" == cdm-generator ]]; then
printf "$INFO_FORMAT +\n" "+" "+" "+" "+" "+" "+" "+" "+" "+" | sed 's/ /-/g;s/^.../ /'
fi
}
projectInfoAll() {
INFO_FORMAT=" %-30s %-16s %-10s %-6s %-6s %-6s %-6s %-50s %-50s"
declare -A branchOf versionOf aheadOf behindOf dirtyOf dependabot
eval "branchOf=( $(forAllProjects getBranch ) )"
eval "versionOf=( $(forAllProjects getVersion ) )"
eval "aheadOf=( $(forAllProjects getNumAhead ) )"
eval "behindOf=( $(forAllProjects getNumBehind ) )"
eval "dirtyOf=( $(forAllProjects getNumDirty ) )"
eval "dependabot=( $(forAllProjects getNumDependabot) )"
echo
projectInfoSeparator
printf "$INFO_FORMAT\n" "repos-name" "branch" "version" "ahead" "behind" "dirty" "depbot" "local-branches" "remote-branches"
projectInfoSeparator
forAllProjects projectInfo
projectInfoSeparator
local unrelated="$(showUnrelated)"
if [[ -n "$unrelated" ]]; then
echo "$unrelated"
projectInfoSeparator
fi
echo
}
projectInfo() {
local repo="$1"; shift
printf "$INFO_FORMAT\n" \
"$repo" \
"${branchOf[$repo]:-?}" \
"${versionOf[$repo]:-?}" \
"${aheadOf[$repo]:-?}" \
"${behindOf[$repo]:-?}" \
"${dirtyOf[$repo]:-?}" \
"${dependabot[$repo]:-?}" \
"$(listLocalBranches)" \
"$(listRemoteBranches)"
if [[ "${dependabot[$repo]:- }" != " " ]]; then
printf " %s\n" $(listDependabotBranches)
fi
projectInfoSeparator "$repo"
}
showUnrelated() {
for repo in $(cd ..; eval "ls $(printf " | fgrep -v '%s'" ${repoName[@]})"); do
if [[ -d ../$repo ]]; then
if [[ -e ../$repo/.git ]]; then
projectInfo $repo
else
printf " %-30s NO GIT PROJECT\n" "$repo"
fi
fi
done
}
upgradeProjectAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ UPGRADE PROJECT CHECK\n"
printf " requested project version = %s\n" "$INTENDED_PROJECT_VERSION"
numUpgraded=0
forAllProjects upgradeProject
if [[ $numUpgraded == 0 ]]; then
echo " ok: all projects were already using the requested project version"
else
echo " ok: all projects are now using the requested project version ($numUpgraded upgraded)"
fi
}
upgradeProject() {
local propFile="gradle.properties"
local key="version"
if [[ -f "$propFile" ]]; then
PROJECT_PROJECT_VERSION="$(getProperty "$propFile" "$key")"
if [[ "$PROJECT_PROJECT_VERSION" != "" && "$PROJECT_PROJECT_VERSION" != $INTENDED_PROJECT_VERSION ]]; then
echo " upgrading project: $PROJECT_PROJECT_VERSION => $INTENDED_PROJECT_VERSION: for project $1"
setProperty "$propFile" "$key" "$INTENDED_PROJECT_VERSION"
((numUpgraded++))
fi
fi
}
upgradeJavaAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ UPGRADE JAVA CHECK\n"
printf " requested java version = %s\n" "$INTENDED_JAVA_VERSION"
numUpgraded=0
forAllProjects upgradeJava
if [[ $numUpgraded == 0 ]]; then
echo " ok: all projects were already using the requested java version"
else
echo " ok: all projects are now using the requested java version ($numUpgraded upgraded)"
fi
}
upgradeJava() {
local propFile="gradle.properties"
local key="version_java"
if [[ -f "$propFile" ]]; then
PROJECT_JAVA_VERSION="$(getProperty "$propFile" "$key")"
if [[ "$PROJECT_JAVA_VERSION" != "" && "$PROJECT_JAVA_VERSION" != $INTENDED_JAVA_VERSION ]]; then
echo " upgrading java: $PROJECT_JAVA_VERSION => $INTENDED_JAVA_VERSION: for project $1"
setProperty "$propFile" "$key" "$INTENDED_JAVA_VERSION"
((numUpgraded++))
fi
fi
}
upgradeGradleAll() {
LATEST_GRADLE_VERSION="$(curl --silent https://raw.githubusercontent.com/gradle/gradle/master/released-versions.json | sed -n '1,/finalReleases/d;/version/p' | head -1 | sed 's/.*: "//;s/".*//' || :)"
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ UPGRADE GRADLE CHECK\n"
printf " requested gradle version = %s\n" "$INTENDED_GRADLE_VERSION"
printf " latest gradle version = %s\n" "$LATEST_GRADLE_VERSION"
numUpgraded=0
forAllProjects upgradeGradle
if [[ $numUpgraded == 0 ]]; then
echo " ok: all projects were already using the requested gradle version"
else
echo " ok: all projects are now using the requested gradle version ($numUpgraded upgraded)"
fi
}
upgradeGradle() {
if [[ -f gradlew ]]; then
local preCrc="$(cat gradlew gradlew.bat gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties | cksum)"
./gradlew wrapper --gradle-version $INTENDED_GRADLE_VERSION
local pstCrc="$(cat gradlew gradlew.bat gradle/wrapper/gradle-wrapper.jar gradle/wrapper/gradle-wrapper.properties | cksum)"
if [[ "$preCrc" != "$pstCrc" ]]; then
((numUpgraded++)) || :
fi
fi
}
cleanAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ CLEAN\n"
for dir in \
~/.m2/repository/snapshots/ \
~/.gradle/caches/modules-2/files-2.1/snapshots.org.modelingvalue/ \
; do
if [[ -d "$dir" ]]; then
local numJars="$(find $dir -name \*.jar ! -name \*sources\* ! -name \*javadoc\* | wc -l | sed 's/ //g')"
if (( $numJars > 0 )); then
echo "DELETING '$dir'..."
rm -rf "$dir"
fi
fi
done
for repo in "${repoSeq[@]}"; do
( cd ../$repo
printf ">>>>=========================== CLEAN : %s ===========================\n" "$(basename "$(pwd)")"
printf " _-_-_ (cd %s; ./gradlew clean)\n" "$(pwd)"
./gradlew clean || :
find . -type d -name classes_gen -exec rm -rf {} +
find . -type d -name source_gen -exec rm -rf {} +
find . -type d -name source_gen.caches -exec rm -rf {} +
rm -rf build
printf "<<<<=========================== CLEAN : %s ===========================\n\n\n\n\n" "$(basename "$(pwd)")"
)&
done
wait
for repo in "${repoSeq[@]}"; do
( cd ../$repo
if [[ -d build ]]; then
rm -rf build
fi
local ign="$(git status --ignored --untracked-files=all \
| egrep '^ ' \
| fgrep -v ' modified: ' \
| fgrep -v '.DS_Store' \
| fgrep -v ' .idea' \
| fgrep -v ' .mps' \
| fgrep -v ' .gradle' \
|| :)"
if [[ "$ign" != "" ]]; then
echo "================ ignored in $repo:"
echo "$ign"
fi
)
done
}
publishAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ BUILD\n"
for repo in "${repoSeq[@]}"; do
( cd ../$repo
printf ">>>>=========================== PUBLISH: %s ===========================\n" "$(basename "$(pwd)")"
if [[ -f mps_build.xml ]]; then
printf " _-_-_ (cd %s; ./gradlew download-MPS)\n" "$(pwd)"
./gradlew download-MPS
fi
printf " _-_-_ (cd %s; ./gradlew publish)\n" "$(pwd)"
./gradlew publish
printf "<<<<=========================== PUBLISH: %s ===========================\n" "$(basename "$(pwd)")"
)
done
if [[ -d ~/Downloads ]]; then
echo
echo "INFO: copying the plugins to your ~/Downloads folder:"
for f in \
"../dclareForMPS/build/artifacts/DclareForMPS/DclareForMPS.zip" \
"../cdm/build/artifacts/CDM/CDM.zip" \
"../cdm-generator//build/artifacts/cdm-generator/cdm-generator.zip" \
; do
if [[ -f "$f" ]]; then
cp "$f" ~/Downloads
echo " - $(basename "$f")"
else
echo " - no plugin file at: $f"
fi
done
local allZip=~/Downloads/"cdm-all-$(date '+%Y%m%d-%H%M').zip"
zip -j "$allZip" ~/Downloads/DclareForMPS.zip ~/Downloads/CDM.zip ~/Downloads/cdm-generator.zip
echo " => $allZip"
echo
fi
}
testAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ TEST\n"
for repo in "${repoSeq[@]}"; do
( cd ../$repo
printf ">>>>=========================== TEST : %s ===========================\n" "$(basename "$(pwd)")"
./gradlew --status
./gradlew --stop
./gradlew --status
./gradlew test
printf "<<<<=========================== TEST : %s ===========================\n\n\n\n\n" "$(basename "$(pwd)")"
) #&
done
wait
ls -l ../cdm/build/artifacts/CDM/CDM.zip ../dclareForMPS/build/artifacts/DclareForMPS/DclareForMPS.zip
}
logAll() {
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ LOG\n"
rm -f /tmp/generic-info-log-*
for repo in "${repoSeq[@]}"; do
( cd ../$repo
logOne $repo | fgrep -v '|automation|'> /tmp/generic-info-log-$repo
)&
done
wait
cat /tmp/generic-info-log-* | sort | tr '|\n' '\0\0' | xargs -0 -n 6 printf "%.s%s %s - %-25s %-25s %s\n"
rm -f /tmp/generic-info-log-*
}
logOne() {
local repo="$1"; shift
git log origin/develop --since="2 weeks ago" --first-parent --no-merges --date=format:"%s|%Y-%m-%d|%H:%M:%S" --pretty=tformat:"%cd|$repo|%an|%s"
}
toDateAll() {
local unclean=()
for repo in "${repoSeq[@]}"; do
local output=$(cd ../$repo; git status --porcelain)
if ! [[ -z "$output" ]]; then
unclean+=($repo)
fi
done
if [[ ${#unclean[@]} != 0 ]]; then
printf "PROBLEM: the following repos are dirty (clean them first):\n"
printf " - %s\n" "${unclean[@]}"
else
REPLY=
while ! [[ $REPLY =~ 20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\ [0-9][0-9]:[0-9][0-9] ]]; do
read -p "to what date are we going to time-travel: " -r
echo 1>&2
done
theDate="$REPLY"
for repo in "${repoSeq[@]}"; do
( cd ../$repo
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ moving %-24s to %s\n" "$repo" "$theDate"
git checkout develop
echo "===================="
git checkout $(git rev-list --before "$theDate" --max-count=1 develop)
)
done
wait
fi
}
###########################################################################################################################
main() {
whattodo="$(askWhatToDo)"
. ./info.sh
declare -A workflowOf mainBranchOf
pattern="($(printf "%s|" "${repoSeq[@]}" | sed 's/|$//' | tr -d '\n'))"
eval "repoName=( "${repoSeq[@]}" $(printf "%s%.s%.s\n" "${repoList[@]}" | egrep -v "$pattern" | sort) )"
eval "workflowOf=( $(printf "[%s]=%s%.s " "${repoList[@]}") )"
eval "mainBranchOf=( $(printf "[%s]=%.s%s " "${repoList[@]}") )"
if [[ "$whattodo" != c ]]; then
cloneFetchAll
fi
if [[ $whattodo =~ [$doToDate] ]]; then
toDateAll
fi
if [[ $whattodo =~ [$doPull] ]]; then
pullAll
fi
if [[ $whattodo =~ [$doOverview] ]]; then
projectInfoAll
fi
if [[ $whattodo =~ [$doJavaVersion] ]]; then
upgradeJavaAll
fi
if [[ $whattodo =~ [$doGradleVersion] ]]; then
upgradeGradleAll
fi
if [[ $whattodo =~ [$doProjectVersion] ]]; then
upgradeProjectAll
fi
switchToCorrectJavaVersion
local T0="$(sec)"
if [[ $whattodo =~ [$doClean] ]]; then
local c0="$(sec)"
cleanAll
local c1="$(sec)"
fi
if [[ $whattodo =~ [$doPublish] ]]; then
local p0="$(sec)"
publishAll
local p1="$(sec)"
fi
if [[ $whattodo =~ [$doTest] ]] || [[ $whattodo == t ]]; then
local t0="$(sec)"
testAll
local t1="$(sec)"
fi
local T1="$(sec)"
if [[ $whattodo =~ [$doTimes] ]]; then
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ TIMING\n"
if [[ $whattodo =~ [$doClean] ]]; then
printf " clean time: %4d sec\n" "$((c1-c0))"
fi
if [[ $whattodo =~ [$doPublish] ]]; then
printf " publish time: %4d sec\n" "$((p1-p0))"
fi
if [[ $whattodo =~ [$doTest] ]]; then
printf " test time: %4d sec\n" "$((t1-t0))"
fi
printf " TOTAL time: %4d sec\n" "$((T1-T0))"
fi
if [[ $whattodo =~ [$doLog] ]]; then
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ SCANNING GIT LOGS...\n"
logAll
fi
if [[ $whattodo == d ]]; then
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ DEV EXTRAS...\n"
printf "for repo in %s; do (cd \"../\$repo\";echo \"====== \$repo\"); done\n" "${repoSeq[*]}"
fi
printf "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ DONE\n"
}
###########################################################################################################################
main "$@"