2016-09-09 12:52:52 +00:00
|
|
|
#!/bin/bash
|
2020-01-01 11:14:44 +00:00
|
|
|
set -x
|
|
|
|
set -e
|
|
|
|
BASEDIR="$(realpath "$1")"
|
2016-09-09 12:52:52 +00:00
|
|
|
PROJECT_NAME="$2"
|
|
|
|
|
2016-09-11 17:30:26 +00:00
|
|
|
TITLE="Coverage report of $PROJECT_NAME"
|
2016-09-09 12:52:52 +00:00
|
|
|
|
|
|
|
# build by gitlab CI
|
|
|
|
if [ -n "$CI_BUILD_REF_NAME" ]; then
|
|
|
|
BRANCH="$CI_BUILD_REF_NAME"
|
2016-09-11 17:30:26 +00:00
|
|
|
TITLE="$TITLE, $BRANCH branch"
|
2016-09-09 12:52:52 +00:00
|
|
|
# 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"
|
2016-09-11 17:30:26 +00:00
|
|
|
TITLE="$TITLE, pull request n°$BRANCH"
|
2016-09-09 12:52:52 +00:00
|
|
|
else
|
|
|
|
BRANCH="$TRAVIS_BRANCH"
|
2016-09-11 17:30:26 +00:00
|
|
|
TITLE="$TITLE, $BRANCH branch"
|
2016-09-09 12:52:52 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
2016-09-11 17:30:26 +00:00
|
|
|
TITLE="$TITLE, $BRANCH branch"
|
2016-09-09 12:52:52 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$BRANCH" = "HEAD" ]] || [ -z "$BRANCH" ]; then
|
|
|
|
echo "bad branch name '$BRANCH', ignoring it"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2016-09-11 17:30:26 +00:00
|
|
|
|
|
|
|
VENV="$(mktemp -d)"
|
|
|
|
HTMLREPORT="$(mktemp -d)"
|
2020-01-01 11:14:44 +00:00
|
|
|
virtualenv -p python3 "$VENV"
|
2016-09-11 17:30:26 +00:00
|
|
|
"$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"
|
|
|
|
|
2020-01-01 11:14:44 +00:00
|
|
|
set +x
|
|
|
|
echo "curl https://badges.genua.fr/coverage/ ..."
|
2016-09-09 23:16:33 +00:00
|
|
|
curl https://badges.genua.fr/coverage/ \
|
2016-09-09 12:52:52 +00:00
|
|
|
-F "secret=$COVERAGE_TOKEN" \
|
|
|
|
-F "tar=@$BASEDIR/coverage.tar.gz" \
|
|
|
|
-F "project=$PROJECT_NAME" \
|
|
|
|
-F "branch=$BRANCH"
|
|
|
|
|
2020-01-01 11:14:44 +00:00
|
|
|
set -x
|
2016-09-09 12:52:52 +00:00
|
|
|
rm "$BASEDIR/coverage.tar.gz"
|
|
|
|
|