test.sh 2.44 KB
Newer Older
1 2
#! /bin/bash

3 4 5
set -e
set -x

6 7 8 9
##
## requires >= 1.3.0 of the Jenkins git plugin
##

10
function github_status {
11 12 13 14 15 16 17 18 19 20
    if [[ ! ${GIT_URL} =~ git@github.com:([^/]+)/([^\.]+).git ]]; then
        echo "Cannot parse Github org or repo from URL, using defaults."
        ORG="edx"
        REPO="edx-platform"
    else
        ORG=${BASH_REMATCH[1]}
        REPO=${BASH_REMATCH[2]}
    fi

    gcli status create $ORG $REPO $GIT_COMMIT \
21 22 23 24 25 26 27 28 29
         --params=$1 \
                  target_url:$BUILD_URL \
                  description:"Build #$BUILD_NUMBER $2" \
         -f csv
}

function github_mark_failed_on_exit {
    trap '[ $? == "0" ] || github_status state:failure "failed"' EXIT
}
30

31 32
git remote prune origin

33
github_mark_failed_on_exit
34
github_status state:pending "is running"
35

36 37 38 39 40 41 42
# Reset the submodule, in case it changed
git submodule foreach 'git reset --hard HEAD'

# Set the IO encoding to UTF-8 so that askbot will start
export PYTHONIOENCODING=UTF-8

GIT_BRANCH=${GIT_BRANCH/HEAD/master}
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

# When running in parallel on jenkins, workspace could be suffixed by @x
# In that case, we want to use a separate virtualenv that matches up with
# workspace
#
# We need to handle both the case of /path/to/workspace
# and /path/to/workspace@2, which is why we use the following substitutions
#
# $WORKSPACE is the absolute path for the workspace
WORKSPACE_SUFFIX=$(expr "$WORKSPACE" : '.*\(@.*\)') || true

VIRTUALENV_DIR="/mnt/virtualenvs/${JOB_NAME}${WORKSPACE_SUFFIX}"

if [ ! -d "$VIRTUALENV_DIR" ]; then
    mkdir -p "$VIRTUALENV_DIR"
    virtualenv "$VIRTUALENV_DIR"
59
fi
60

61 62
export PIP_DOWNLOAD_CACHE=/mnt/pip-cache

63 64 65
# Allow django liveserver tests to use a range of ports
export DJANGO_LIVE_TEST_SERVER_ADDRESS=${DJANGO_LIVE_TEST_SERVER_ADDRESS-localhost:8000-9000}

66
source /mnt/virtualenvs/"$JOB_NAME"/bin/activate
67

68
rake install_prereqs
69
rake clobber
70 71
rake pep8 > pep8.log || cat pep8.log
rake pylint > pylint.log || cat pylint.log
72

73
TESTS_FAILED=0
74 75

# Run the python unit tests
76 77
rake test_cms || TESTS_FAILED=1
rake test_lms || TESTS_FAILED=1
78 79
rake test_common/lib/capa || TESTS_FAILED=1
rake test_common/lib/xmodule || TESTS_FAILED=1
80

81
# Run the javascript unit tests
82
rake phantomjs_jasmine_lms || TESTS_FAILED=1
83
rake phantomjs_jasmine_cms || TESTS_FAILED=1
84
rake phantomjs_jasmine_common/lib/xmodule || TESTS_FAILED=1
85
rake phantomjs_jasmine_common/static/coffee || TESTS_FAILED=1
86

87 88
# Generate coverage reports
rake coverage
89 90

[ $TESTS_FAILED == '0' ]
91 92
rake autodeploy_properties

93
github_status state:success "passed"