mahara_jenkins.php 3.16 KB
Newer Older
1 2 3 4 5 6
#!/bin/bash

# Quit on error
set -e

MAXBEHIND=30
7 8
BEHATNOTNEEDED="behatnotneeded"
BEHATTESTREGEX="^test/behat/features/"
9 10

echo ""
11
echo "########## Check the patch is less than $MAXBEHIND patches behind remote branch HEAD"
12
echo ""
13
git fetch origin $GERRIT_BRANCH
14 15
echo ""
BEHINDBY=`git rev-list HEAD..origin/$GERRIT_BRANCH | wc -l`
16
echo "This patch is behind $GERRIT_BRANCH by $BEHINDBY commit(s)"
17 18
[[ "$BEHINDBY" -lt "$MAXBEHIND" ]] || { echo "This patch is too far behind master, please rebase"; exit 1; }

19
echo "########## Check the patch and its parents are not already rejected"
20
echo ""
21 22
# Fetch the git commit ids that exist between this commit and the origin
# that exists when the patch was made.
23
HEAD=`git rev-parse HEAD`
24
the_list=`git log --pretty=format:'%H' origin/$GERRIT_BRANCH..$HEAD`
25
firstcommit=1
26 27
while IFS= read -r line
do
Robert Lyon's avatar
Robert Lyon committed
28 29 30 31
        if [ -z "$line" ]; then
            echo "Patch already merged"
            exit 1;
        fi
32
        # check if the commit or it's parents have been rejected
33
        php=`which php`
34
        outcome=`$php $HOME/mahara/mahara-scripts/jenkins/gerrit_query.php -- $line $firstcommit`
35
        if [ "$outcome" = "1" ]; then
36
            echo "The patch with git commit id $line has been rejected"
37
            exit 1;
38 39 40
        elif [ "$outcome" = "3" ]; then
            echo "The patch with git commit id $line is not the latest (current) patch"
            exit 1;
41 42 43
        elif [ "$outcome" = "4" ]; then
            echo "This patch or a parent patch has been abandoned"
            exit 1;
44
        else
45
            echo "The patch with git commit id $line looks ok so we will continue"
46
        fi
47
        firstcommit=0
48 49
done <<< "$the_list"

50 51 52
echo ""
echo "########## Check the patch contains a Behat test"
echo ""
53
if [ "$(git diff-tree --no-commit-id --name-only -r HEAD | grep -c $BEHATTESTREGEX)" -ge 1 ]; then
54 55 56 57
    echo "Patch includes a Behat test."
else
    echo "This patch does not include a Behat test!"
    # Check whether the commit message has "behatnotneeded" in it.
58
    if [ "$(git log -1 | grep -i -c $BEHATNOTNEEDED)" -ge 1 ]; then
59 60 61 62 63 64 65
        echo "... but the patch is marked with \"$BEHATNOTNEEDED\", so we will continue."
    else
        echo "Please write a Behat test for it, or, if it cannot be tested, put \"$BEHATNOTNEEDED\" in its commit message."
        exit 1;
    fi
fi

66 67 68 69 70 71 72 73
echo ""
echo "########## Run make minaccept"
echo ""
make minaccept

echo ""
echo "########## Run install"
echo ""
74
dropdb $JOB_NAME
75 76
rm -Rf $HOME/mahara/sitedata/$JOB_NAME/*
rm -Rf $HOME/mahara/sitedata/behat_$JOB_NAME/*
77 78 79
createdb -O jenkins -E utf8 $JOB_NAME

cd htdocs
80
cp $HOME/mahara/mahara-scripts/jenkins/mahara_config.php config.php
81 82 83
php admin/cli/install.php --adminpassword='password' --adminemail=never@example.com
cd ..

84 85 86 87 88
# Check if composer is not available
if [ ! -f external/composer.json ]; then
    exit 0
fi

89 90 91 92 93 94 95 96 97
echo ""
echo "########## Install composer"
echo ""
cd external
curl -sS https://getcomposer.org/installer | php
php composer.phar update
cd ..

echo ""
98
echo "########## Run unit tests"
99
echo ""
100
external/vendor/bin/phpunit htdocs/
101

102
echo ""
103
echo "########## Build & Minify CSS"
104
echo ""
105
make
106

107 108 109 110
echo ""
echo "########## Run Behat"
echo ""

111
test/behat/mahara_behat.sh runheadless
112