Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 91 lines (76 sloc) 2.256 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
#! /bin/bash

REVRANGE="$1..HEAD"
TEST='buildbot.test buildslave.test'

# some colors
# plain
_ESC=$'\e'
GREEN="$_ESC[0;32m"
MAGENTA="$_ESC[0;35m"
RED="$_ESC[0;31m"
YELLOW="$_ESC[1;33m"
NORM="$_ESC[0;0m"

if [ $# -eq 0 ]; then
    echo "USAGE: common/validate.sh oldrev"
    echo " This script will test a set of patches (oldrev..HEAD) for basic acceptability as a patch"
    echo " Run it in an activated virtualenv with the current Buildbot installed, as well as"
    echo " sphinx, pyflakes, mock, and coverage."
    echo "To use a different directory for tests, pass TRIALTMP=/path as an env variable"
    exit 1
fi

status() {
    echo ""
    echo "${YELLOW}-- ${*} --${NORM}"
}

ok=true
not_ok() {
    ok=false
echo "${RED}** ${*} **${NORM}"
}

check_long_lines() {
    # only check python files
    local long_lines=false
for f in $(git diff --name-only --stat "$REVRANGE" | grep '.py$'); do
        # don't try to check removed files
        [ ! -f "$f" ] && continue
        if [ $(git diff "$REVRANGE" $f | grep -c '+.{80}') != 0 ]; then
            echo " $f"
            long_lines=true
fi
    done
    $long_lines
}

if ! git diff --no-ext-diff --quiet --exit-code; then
    not_ok "changed files in working copy"
    exit 1
fi

echo "${MAGENTA}Validating the following commits:${NORM}"
git log "$REVRANGE" --pretty=oneline || exit 1

status "checking formatting"
git diff "$REVRANGE" | grep -q $'+.*\t' && not_ok "$REVRANGE adds tabs"
check_long_lines && not_ok "$REVRANGE adds long lines"

status "running tests"
if [ -n "${TRIALTMP}" ]; then
    echo rm -rf ${TRIALTMP}
    TEMP_DIRECTORY_OPT="--temp-directory ${TRIAL_TMP}"
fi

coverage erase || exit 1
coverage run --rcfile=.coveragerc \
    sandbox/bin/trial --reporter summary ${TEMP_DIRECTORY_OPT} ${TEST} \
    || not_ok "tests failed"

status "running pyflakes"
make pyflakes || not_ok "failed pyflakes"

status "coverage report"
coverage report > covreport || exit 1
head -n2 covreport || exit 1
tail -n1 covreport || exit 1
rm covreport || exit 1

status "building docs"
make -C master/docs VERSION=latest clean html || not_ok "docs failed"

echo ""
if $ok; then
    echo "${GREEN}GOOD!${NORM}"
    exit 0
else
    echo "${RED}NO GOOD!${NORM}"
    exit 1
fi
Something went wrong with that request. Please try again.