|
| 1 | +#!/bin/bash |
| 2 | +# Wrapper for travis tests |
| 3 | + |
| 4 | +function docker_build { |
| 5 | + docker build -t httpse . |
| 6 | +} |
| 7 | + |
| 8 | +# Folder paths, relative to parent |
| 9 | +RULESETFOLDER="src/chrome/content/rules" |
| 10 | + |
| 11 | +# Go to git repo root; taken from ../test.sh. Note that |
| 12 | +# $GIT_DIR is .git in this case. |
| 13 | +if [ -n "$GIT_DIR" ] |
| 14 | +then |
| 15 | + # $GIT_DIR is set, so we're running as a hook. |
| 16 | + cd $GIT_DIR |
| 17 | + cd .. |
| 18 | +else |
| 19 | + # Git command exists? Cool, let's CD to the right place. |
| 20 | + git rev-parse && cd "$(git rev-parse --show-toplevel)" |
| 21 | +fi |
| 22 | + |
| 23 | +# Fetch the current GitHub version of HTTPS-E to compare to its master |
| 24 | +git remote add upstream-for-travis https://github.com/EFForg/https-everywhere.git |
| 25 | +trap 'git remote remove upstream-for-travis' EXIT |
| 26 | +git fetch upstream-for-travis master |
| 27 | +COMMON_BASE_COMMIT=$(git merge-base upstream-for-travis/master HEAD) |
| 28 | +RULESETS_CHANGED=$(git diff --name-only $COMMON_BASE_COMMIT | grep $RULESETFOLDER | grep '.xml') |
| 29 | +if [ "$(git diff --name-only $COMMON_BASE_COMMIT)" != "$RULESETS_CHANGED" ]; then |
| 30 | + ONLY_RULESETS_CHANGED=false |
| 31 | +fi |
| 32 | + |
| 33 | +# At this point, if anything fails, the test should fail |
| 34 | +set -e |
| 35 | + |
| 36 | +if ! $ONLY_RULESETS_CHANGED; then |
| 37 | + echo >&2 "Core code changes have been made." |
| 38 | + if [ "$TEST" == "firefox" ]; then |
| 39 | + echo >&2 "Running firefox test suite." |
| 40 | + docker_build |
| 41 | + docker run --rm -ti -v $(pwd):/opt -e FIREFOX=/$FIREFOX/firefox/firefox httpse bash -c "test/firefox.sh" |
| 42 | + fi |
| 43 | + if [ "$TEST" == "chromium" ]; then |
| 44 | + echo >&2 "Running chromium test suite." |
| 45 | + docker_build |
| 46 | + # --privileged is required here because chromium requires kernel lxc access |
| 47 | + docker run --rm -ti -v $(pwd):/opt --privileged httpse bash -c "test/chromium.sh" |
| 48 | + fi |
| 49 | +fi |
| 50 | +# Only run test if something has changed. |
| 51 | +if [ "$RULESETS_CHANGED" ]; then |
| 52 | + echo >&2 "Ruleset database has changed." |
| 53 | + |
| 54 | + if [ "$TEST" == "rules" ]; then |
| 55 | + echo >&2 "Performing comprehensive coverage test." |
| 56 | + docker_build |
| 57 | + docker run --rm -ti -v $(pwd):/opt httpse bash -c "test/rules.sh" |
| 58 | + fi |
| 59 | + |
| 60 | + |
| 61 | + if [ "$TEST" == "fetch" ]; then |
| 62 | + echo >&2 "Testing test URLs in all changed rulesets." |
| 63 | + docker_build |
| 64 | + # --privileged is required here for miredo to create a network tunnel |
| 65 | + docker run --rm -ti -v $(pwd):/opt -e RULESETS_CHANGED="$RULESETS_CHANGED" --privileged httpse bash -c "service miredo start && test/fetch.sh" |
| 66 | + fi |
| 67 | +fi |
| 68 | + |
| 69 | +exit 0 |
0 commit comments