forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_travis.sh
executable file
·109 lines (93 loc) · 3.3 KB
/
run_travis.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
#!/bin/bash
set -x
toplevel="$(git rev-parse --show-toplevel)"
testdir="${toplevel}/test/selenium"
srcdir="${toplevel}/chromium"
linter="${toplevel}/utils/eslint/node_modules/.bin/eslint --ignore-path ${srcdir}/.eslintignore"
function run_lint {
$linter $srcdir
if [ $? != 0 ]; then
echo "Linting errors"
exit 1
fi
}
function run_unittests {
pushd ${srcdir}
npm run cover # run with coverage
if [ $? != 0 ]; then
echo "unittest errors"
exit 1
fi
npm run report
popd
}
function run_selenium {
ENABLE_XVFB=1 pytest -v --capture=no ${testdir} # autodiscover and run the tests
}
if [ "$TEST" == "lint" ]; then
echo "running lint tests"
run_lint
elif [ "$TEST" == "unittests" ]; then
echo "Running unittests"
run_unittests
elif [ "$TEST" == "validations" ] || [ "$TEST" == "fetch" ] || [ "$TEST" == "preloaded" ]; then
# Folder paths, relative to parent
RULESETFOLDER="src/chrome/content/rules"
# Go to git repo root; taken from ../test.sh. Note that
# $GIT_DIR is .git in this case.
if [ -n "$GIT_DIR" ]
then
# $GIT_DIR is set, so we're running as a hook.
cd $GIT_DIR
cd ..
else
# Let's CD to the right place.
cd $toplevel
fi
# Fetch the current GitHub version of HTTPS-E to compare to its master
git remote add upstream-for-travis https://github.com/EFForg/https-everywhere.git
trap 'git remote remove upstream-for-travis' EXIT
# Only do a shallow fetch if we're in Travis. No need otherwise.
if [ $TRAVIS ]; then
git fetch --depth=50 upstream-for-travis master
else
git fetch upstream-for-travis master
fi
COMMON_BASE_COMMIT=$(git merge-base upstream-for-travis/master HEAD)
RULESETS_CHANGED=$(git diff --name-only $COMMON_BASE_COMMIT | grep $RULESETFOLDER | grep '.xml')
if [ "$(git diff --name-only $COMMON_BASE_COMMIT)" != "$RULESETS_CHANGED" ]; then
ONLY_RULESETS_CHANGED=false
fi
# At this point, if anything fails, the test should fail
set -e
if [ "$TEST" == "validations" ]; then
echo >&2 "Performing validations on rulesets."
docker run --rm -ti -v $(pwd):/opt httpse bash -c "test/validations.sh"
fi
if [ "$TEST" == "fetch" ]; then
echo >&2 "Testing test URLs in all changed rulesets."
# NET_ADMIN capability is required here for miredo to create a network tunnel
docker run --rm -ti -v $(pwd):/opt -e RULESETS_CHANGED="$RULESETS_CHANGED" --sysctl net.ipv6.conf.all.disable_ipv6=0 --cap-add NET_ADMIN --cap-add MKNOD httpse bash -c "mkdir -p /dev/net && mknod /dev/net/tun c 10 200 && service miredo start && service tor start && test/fetch.sh"
fi
if [ "$TEST" == "preloaded" ]; then
echo >&2 "Ensuring rulesets do not introduce targets which are already HSTS preloaded."
docker run --rm -ti -v $(pwd):/opt -e RULESETS_CHANGED="$RULESETS_CHANGED" node bash -c "cd /opt/utils/hsts-prune && npm install && node index.js"
[ `git diff --name-only $RULESETFOLDER | wc -l` -eq 0 ]
fi
exit 0
else
case $BROWSER in
*chrome*)
echo "running tests on chrome"
run_selenium
;;
*firefox*)
echo "running tests on firefox"
run_selenium
;;
*)
echo "bad TEST variable, got $TEST"
exit 1
;;
esac
fi