-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergeBranches
executable file
·90 lines (87 loc) · 2.5 KB
/
mergeBranches
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
#!/bin/sh
basePath=`dirname $0`
export PATH="$(cd "$basePath" 2>/dev/null && pwd)/utils:$PATH"
if test -s /etc/keengreeper.conf; then
. /etc/keengreeper.conf
fi
if test -z "$LOGDIR"; then
export LOGDIR=`pwd`/logs
fi
if test -z "$TMPDIR"; then
export TMPDIR=`pwd`/tmp
fi
if test -z "$WORKDIR"; then
export WORKDIR=/home/`id -un`/git
fi
if test -z "$DBDIR"; then
export DBDIR=$WORKDIR
fi
if test -z "$CACHETTL"; then
export CACHETTL=3600
fi
test -d $LOGDIR || mkdir -p $LOGDIR
test -d $TMPDIR || mkdir -p $TMPDIR
test -d $DBDIR || mkdir -p $DBDIR
if ! test -d $DBDIR; then
echo "CRITICAL: $DBDIR does not exist" >&2
exit 1
elif ! test -s $DBDIR/npmjs-cache; then
echo "CRITICAL: npmjs-cache is absent" >&2
exit 1
elif ! test -s $DBDIR/snyk-cache; then
echo "CRITICAL: snyk-cache is absent" >&2
exit 1
elif ! test -s $DBDIR/nodejs-update-db; then
cat <<EOF >&2
CRITICAL: nodejs-update-db absent or empty
use $basePath/configure to create an empty dataset, and configure
which repositories our job should be working with.
EOF
elif ! nodeDbListCache >/dev/null 2>&1; then
echo "CRITICAL: failed listing npmjs cache" >&2
exit 1
fi
for repository in `listRepository`
do
if test "$1"; then
if ! echo $repository | grep -E "$1" >/dev/null; then
test "$DEBUG" && echo "skipping $repository - does not match pattern"
continue
fi
fi
if ! hasCI $repository; then
test "$DEBUG" && echo "skipping $repository - does not have CircleCI or TravisCI configured"
continue
fi
if test -s "$TMPDIR/$repository.lock"; then
if ls /proc/`cat "$TMPDIR/$repository.lock"` >/dev/null 2>&1; then
echo "skipping $repository - lock file exists"
continue
fi
test "$DEBUG" && echo "orphan lock file exists, discarding"
fi
echo $$ >$TMPDIR/$repository.lock
if ! cleanRepository $repository; then
resetRepository $repository
fi
if setBranch $repository staging; then
if ! updateRepository $repository; then
echo "skipping $repositroy - failed updating local copy"
rm -f $TMPDIR/$repository.lock
continue
fi
if ! getLastBranch $repository >/dev/null 2>&1; then
echo "done with $repository - nothing to merge"
else
workWith=`getLastBranch $repository`
if queryCI $repository $workWith; then
if mergeBranch $repository $workWith; then
echo "done merging $repository updates"
fi
fi
fi
else
echo "skipping $repository - failed switching to main working branch"
fi
rm -f $TMPDIR/$repository.lock
done