From ebfac168a2de9e2a3a8fb4c5a53667c88c8434d4 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Fri, 9 Sep 2016 14:52:52 +0200 Subject: [PATCH] Put update_coverage commands in the script called by tox --- .update_coverage | 37 +++++++++++++++++++++++++++++++++++++ tox.ini | 9 ++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100755 .update_coverage diff --git a/.update_coverage b/.update_coverage new file mode 100755 index 0000000..a4a6887 --- /dev/null +++ b/.update_coverage @@ -0,0 +1,37 @@ +#!/bin/bash +BASEDIR="$1" +PROJECT_NAME="$2" + +cd "$BASEDIR/htmlcov/"; tar czf "$BASEDIR/coverage.tar.gz" ./ + + +cd "$BASEDIR" + +# build by gitlab CI +if [ -n "$CI_BUILD_REF_NAME" ]; then + BRANCH="$CI_BUILD_REF_NAME" +# 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" + else + BRANCH="$TRAVIS_BRANCH" + fi +else + BRANCH="$(git rev-parse --abbrev-ref HEAD)" +fi + +if [[ "$BRANCH" = "HEAD" ]] || [ -z "$BRANCH" ]; then + echo "bad branch name '$BRANCH', ignoring it" + exit 0 +fi + +curl https://badges.genua.fr/local/coverage/ \ + -F "secret=$COVERAGE_TOKEN" \ + -F "tar=@$BASEDIR/coverage.tar.gz" \ + -F "project=$PROJECT_NAME" \ + -F "branch=$BRANCH" + +rm "$BASEDIR/coverage.tar.gz" + diff --git a/tox.ini b/tox.ini index 3baf0d3..43e8774 100644 --- a/tox.ini +++ b/tox.ini @@ -128,14 +128,17 @@ whitelist_externals={[post_cmd]whitelist_externals} [testenv:coverage] basepython=python -passenv=COVERAGE_TOKEN +passenv= + COVERAGE_TOKEN + CI_BUILD_REF_NAME + TRAVIS_BRANCH + TRAVIS_PULL_REQUEST deps= -r{toxinidir}/requirements.txt -r{toxinidir}/requirements-dev.txt skip_install=True commands= py.test --cov=cas_server --cov-report term --cov-report html - bash -c 'cd {toxinidir}/htmlcov/; tar czf {toxinidir}/coverage.tar.gz ./' - bash -c 'curl -F "secret=$COVERAGE_TOKEN" -F "tar=@{toxinidir}/coverage.tar.gz" -F "project=django-cas-server" -F "branch=$(git rev-parse --abbrev-ref HEAD)" https://badges.genua.fr/local/coverage/; rm {toxinidir}/coverage.tar.gz' + {toxinidir}/.update_coverage "{toxinidir}" "django-cas-server" {[post_cmd]commands} whitelist_externals={[post_cmd]whitelist_externals}