.update_coverage 1.2 KB
Newer Older
1 2 3 4
#!/bin/bash
BASEDIR="$1"
PROJECT_NAME="$2"

5
TITLE="Coverage report of $PROJECT_NAME"
6 7 8 9

# build by gitlab CI
if [ -n "$CI_BUILD_REF_NAME" ]; then
    BRANCH="$CI_BUILD_REF_NAME"
10
    TITLE="$TITLE, $BRANCH branch"
11 12 13 14 15
# build by travis
elif [ -n "$TRAVIS_BRANCH" ]; then
    # if this a pull request ?
    if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
        BRANCH="pull-request-$TRAVIS_PULL_REQUEST"
16
        TITLE="$TITLE, pull request n°$BRANCH"
17 18
    else
        BRANCH="$TRAVIS_BRANCH"
19
        TITLE="$TITLE, $BRANCH branch"
20 21 22
    fi
else
    BRANCH="$(git rev-parse --abbrev-ref HEAD)"
23
    TITLE="$TITLE, $BRANCH branch"
24 25 26 27 28 29 30
fi

if [[ "$BRANCH" = "HEAD" ]] || [ -z "$BRANCH" ]; then
    echo "bad branch name '$BRANCH', ignoring it"
    exit 0
fi

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

VENV="$(mktemp -d)"
HTMLREPORT="$(mktemp -d)"
virtualenv "$VENV"
"$VENV/bin/pip" install coverage
"$VENV/bin/coverage" html --title "$TITLE" --directory "$HTMLREPORT"
rm -rf "$VENV"


cd "$HTMLREPORT"; tar czf "$BASEDIR/coverage.tar.gz" ./

cd "$BASEDIR"

rm -rf "$HTMLREPORT"


Valentin Samir's avatar
Valentin Samir committed
47
curl https://badges.genua.fr/coverage/ \
48 49 50 51 52 53 54
    -F "secret=$COVERAGE_TOKEN" \
    -F "tar=@$BASEDIR/coverage.tar.gz" \
    -F "project=$PROJECT_NAME" \
    -F "branch=$BRANCH"

rm "$BASEDIR/coverage.tar.gz"