test.sh 2.23 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
# Reset the submodule, in case it changed
git submodule foreach 'git reset --hard HEAD'

39 40 41 42 43 44 45
# Assumes that Xvfb has been started by upstart
# and is capturing display :1
# The command for this is:
# /usr/bin/Xvfb :1 -screen 0 1024x268x24
# This allows us to run Chrome or Firefox without a display
export DISPLAY=:1

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

GIT_BRANCH=${GIT_BRANCH/HEAD/master}
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

# 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"
65
    virtualenv --system-site-packages "$VIRTUALENV_DIR"
66
fi
67

68 69
export PIP_DOWNLOAD_CACHE=/mnt/pip-cache

70
source $VIRTUALENV_DIR/bin/activate
71

72 73
bundle install

74
rake install_prereqs
75
rake clobber
76

77 78
# Run the unit tests (use phantomjs for javascript unit tests)
rake test
79

80 81 82 83
# Generate pylint and pep8 reports
rake pep8 > pep8.log || cat pep8.log
rake pylint > pylint.log || cat pylint.log

84 85
# Generate coverage reports
rake coverage
86

87 88 89
# Generate quality reports
rake quality

90 91
rake autodeploy_properties

92
github_status state:success "passed"