Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboard refactored tox & Travis CI setup and configuration vol. 9 #152

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
# - LSR_ANSIBLES
# - LSR_MSCENARIOS
#
# * .travis/runcoveralls.sh:
#
# - LSR_PUBLISH_COVERAGE
# - LSR_TESTSDIR
#
# Environment variables that not start with LSR_* but have influence on CI
# process:
#
Expand All @@ -31,3 +36,6 @@
#
# - RUN_FLAKE8_DISABLED
#

# Allow publishing coverage reports:
export LSR_PUBLISH_COVERAGE=yes
13 changes: 0 additions & 13 deletions .travis/fix-coverage.sh

This file was deleted.

97 changes: 97 additions & 0 deletions .travis/runcoveralls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Reports coverage results using coveralls. The aim of this script is to
# provide a unified way to reporting coverage results across all linux system
# roles projects.

# The first script argument is a path to Python interpreter, the rest of
# arguments are passed to coveralls.

# Environment variables:
#
# LSR_PUBLISH_COVERAGE
# if the variable is empty or unset, nothing will be published; if the
# variable has its value set to 'strict', the reporting is performed in
# strict mode, so situations like missing data to be reported are treated
# as errors; if the value of this variable is 'debug', coveralls is run in
# debug mode (see coveralls debug --help); other values cause that coverage
# results will be reported normally
# LSR_TESTSDIR
# a path to directory where tests and tests artifacts are located; if unset
# or empty, this variable is set to ${TOPDIR}/tests; this path should
# already exists and be populated with tests artifacts before the script
# starts performing actions on it

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)

. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

# Publish the results only if it is desired.
if [[ -z "${LSR_PUBLISH_COVERAGE}" ]]; then
lsr_info "${ME}: Publishing coverage report is not enabled. Skipping."
exit 0
fi

LSR_TESTSDIR=${LSR_TESTSDIR:-${TOPDIR}/tests}

# Sanitize path in case if running within tox (see
# https://github.com/tox-dev/tox/issues/1463):
ENVPYTHON=$(readlink -f $1)
shift

COVERALLSCMD=$(command -v coveralls)

# Ensure we are in $LSR_TESTSDIR. It is supposed that if a user wants to submit
# tests results, $LSR_TESTSDIR always exists.
cd ${LSR_TESTSDIR}

# For simplicity, we suppose that coverage core data file has name .coverage
# and it is situated in $LSR_TESTSDIR. Similarly for .coveragerc.
COVERAGEFILE='.coverage'
COVERAGERCFILE='.coveragerc'

# In case there is no $COVERAGEFILE, there is nothing to report. If we are
# running in strict mode, treat this situation as error.
if [[ ! -s ${COVERAGEFILE} ]]; then
NO_COVERAGEFILE_MSG="${COVERAGEFILE} is missing or empty"
if [[ "${LSR_PUBLISH_COVERAGE}" == "strict" ]]; then
lsr_error "${ME} (strict mode): ${NO_COVERAGEFILE_MSG}!"
fi
lsr_info "${ME}: ${NO_COVERAGEFILE_MSG}, nothing to publish."
exit 0
fi

# Create $COVERAGERCFILE file with a [paths] section. From the official docs:
#
# The first value must be an actual file path on the machine where the
# reporting will happen, so that source code can be found. The other values
# can be file patterns to match against the paths of collected data, or they
# can be absolute or relative file paths on the current machine.
#
# So in our $COVERAGERCFILE file we make both locations to point to the
# project's top directory.
cat > ${COVERAGERCFILE} <<EOF
[paths]
source =
..
$(readlink -f ..)
EOF

# Rename $COVERAGEFILE to ${COVERAGEFILE}.merge. With this trick, coverage
# combine applies configuration in $COVERAGERCFILE also to $COVERAGEFILE.
mv ${COVERAGEFILE} ${COVERAGEFILE}.merge
${ENVPYTHON} -m coverage combine --append

MAYBE_DEBUG=""
if [[ "${LSR_PUBLISH_COVERAGE}" == "debug" ]]; then
MAYBE_DEBUG=debug
fi

set -x
${ENVPYTHON} ${COVERALLSCMD} ${MAYBE_DEBUG} "$@"
12 changes: 6 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ commands =
[testenv:coveralls]
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:coveralls}
passenv = TRAVIS TRAVIS_*
whitelist_externals = bash
deps =
coveralls
changedir = {[base]changedir}
whitelist_externals =
{[base]whitelist_externals}
commands =
bash -c 'cd ..; bash .travis/fix-coverage.sh; cd -'
coveralls
bash {toxinidir}/.travis/runcoveralls.sh {envpython} {posargs}

[molecule_common]
deps =
Expand Down Expand Up @@ -263,8 +263,8 @@ max-line-length = 88
[travis]
python =
2.6: py26,custom
2.7: py27,flake8,pylint,custom
3.5: coveralls,custom
3.6: py36,black,custom
2.7: py27,coveralls,flake8,pylint,custom
3.5: custom
3.6: py36,coveralls,black,custom
3.7: py37,custom
3.8: py38,custom