test.sh 2.01 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

# 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"
58
    virtualenv --system-site-packages "$VIRTUALENV_DIR"
59
fi
60

61 62
export PIP_DOWNLOAD_CACHE=/mnt/pip-cache

63
source $VIRTUALENV_DIR/bin/activate
64

65 66
bundle install

67
rake install_prereqs
68
rake clobber
69

70 71
# Run the unit tests (use phantomjs for javascript unit tests)
rake test
72

73 74 75 76
# Generate pylint and pep8 reports
rake pep8 > pep8.log || cat pep8.log
rake pylint > pylint.log || cat pylint.log

77 78
# Generate coverage reports
rake coverage
79

80 81 82
# Generate quality reports
rake quality

83 84
rake autodeploy_properties

85
github_status state:success "passed"