This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
run-makeref
executable file
·220 lines (192 loc) · 5.21 KB
/
run-makeref
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
#!/bin/bash
#
# Clone source repo to create ref from, create ref
#
SCRIPT_PID=$$
if [ $# -ne 5 ]; then
echo 'arguments: <main_repo_url> <requester_repo_url> <sha_pull_req> <ref_repo_url> <temp_path>'
echo
exit
fi
MAIN_URL=$1
TARGET_URL=$2
SHA=$3
REF_URL=$4
TMP_DIR=$5
#
# Make sure there are no stray processes running
#
if [ -z "$PDFJSBOT_STAGING" ]; then
echo
echo "========== Killing any stray processes"
ps ax -o "pid command" | grep -v 'grep' | grep -E -i 'test.py' | sed -E 's/([0-9]+) .+/\1/g' | xargs kill -TERM 1>/dev/null 2>/dev/null
ps ax -o "pid comm" | grep -E -i 'firefox' | sed -E 's/([0-9]+) .+/\1/g' | xargs kill -9 1>/dev/null 2>/dev/null
fi
#
# killtree(): Kills all descendant child processes
#
killtree() {
local _pid=$1
local _regex="[ ]*([0-9]+)[ ]+${_pid}"
for _child in $(/bin/ps ax -o "pid= ppid=" | grep -E "${_regex}" | sed -E "s/${_regex}/\1/g"); do
killtree ${_child}
done
kill -KILL ${_pid} 1>/dev/null 2>/dev/null
}
#
# Run killtree() upon signal
# NB: trap only works during "wait" or after a command is done
#
trap "killtree $SCRIPT_PID" SIGTERM SIGINT
#
# Set up vars
#
# Get absolute path for current dir
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Hack to get absolute path for tmp path
mkdir -p $TMP_DIR; cd $TMP_DIR
TMP_DIR="$( cd "$( dirname "$0" )" && pwd )"
TARGET_DIR=$TMP_DIR/tests/$SHA
if [ -d $TARGET_DIR ]; then
rm -rf $TARGET_DIR
fi
#
# Garbage collector
#
echo
echo "========== Running garbage collector in $TMP_DIR"
cd $SCRIPT_DIR
./run-gc $TMP_DIR
#
# Fetch git repo to be tested (target), checkout desired sha
#
echo
echo "========== Cloning pull request repo"
mkdir -p $TARGET_DIR
cd $TARGET_DIR
git clone $TARGET_URL .
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not clone $TARGET_URL"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
git checkout --quiet $SHA
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not checkout sha $SHA"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Merge upstream into pull request
#
echo
echo "========== Merging upstream into pull request clone"
cd $TARGET_DIR
git pull --quiet $MAIN_URL master
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not merge upstream into pull request. Please resolve conflicts."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Run linter
#
echo
echo "========== Running 'make lint'"
cd $TARGET_DIR
make lint &
wait $!
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Lint didn't pass."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Copy existing PDFs *from* local cache
#
cd $TARGET_DIR
cp -n $TMP_DIR/pdf-cache/* test/pdfs
#
# Deploy missing files, make ref set
#
echo
echo "========== Running 'make bot_master'"
cd $TARGET_DIR
# Deploy Makefile for bot_master
cp -f $SCRIPT_DIR/test-files/local.mk . 2>/dev/null
# Deploy missing test/ files
cp -f $SCRIPT_DIR/test-files/browser_manifest.json ./test/resources/browser_manifests 2>/dev/null
# prepare Xvfb
killall -9 Xvfb
Xvfb :1 -screen 0 1280x1024x24 1>/dev/null 2>/dev/null &
XVFB_PID=$!
export DISPLAY=:1
# bot_master
make bot_master &
wait $!
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Something went wrong."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
# kill Xvfb
kill -9 $XVFB_PID 1>/dev/null 2>/dev/null
#
# Copy new PDFs *to* local cache
#
cd $TARGET_DIR
mkdir -p $TMP_DIR/pdf-cache
cp -n test/pdfs/*.pdf $TMP_DIR/pdf-cache
if [ ! -d $TARGET_DIR/test/ref ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR (run-makeref): Could not find test/ref snapshots!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
#
# Push up-to-date reference snapshots
#
echo
echo "========== Pushing new snapshots to reference repo"
mkdir -p $TARGET_DIR/test/ref_repo
cd $TARGET_DIR/test/ref_repo
git init; git pull -f --quiet $REF_URL
cp -Rf $TARGET_DIR/test/ref/* .
# generate REF-INFO
echo url $TARGET_URL > REF-INFO
echo sha $SHA >> REF-INFO
# push a clean repo from scratch
rm -rf .git
git init; git add .; git commit -m 'Overriding repo contents' 1>/dev/null 2>/dev/null
git push -f $REF_URL master
if [ $? != 0 ]; then
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "ERROR: Could not push to reference repo."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
exit
fi
if [ -d $REF_URL ]; then
echo "Running garbage collector in local git repo"
cd $REF_URL
git gc
fi
#
# Erase everything
#
echo
echo "========== Cleaning up"
rm -rf $TARGET_DIR
echo
echo "All done."