Skip to content

Commit c9e6f8d

Browse files
authored
Merge pull request linux-system-roles#5 from i386x/new-travis-ci-files
Add common Travis CI settings files
2 parents b792c5e + 26d3046 commit c9e6f8d

40 files changed

+1757
-745
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
passes.yml
22
vault.yml
3+
*.pyc
34
*.retry
4-
5+
/tests/.coverage
6+
/tests/htmlcov*
7+
/.tox

.travis.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-License-Identifier: MIT
2+
---
3+
language: python
4+
env:
5+
global:
6+
- LSR_ANSIBLES='ansible==2.6.* ansible==2.7.* ansible==2.8.*'
7+
- LSR_MSCENARIOS='default'
8+
matrix:
9+
include:
10+
- python: 2.6
11+
dist: trusty
12+
- python: 2.7
13+
- python: 3.5
14+
- python: 3.6
15+
- python: 3.7
16+
- python: 3.7-dev
17+
- python: 3.8-dev
18+
19+
services:
20+
- docker
21+
22+
before_install:
23+
- ./.travis/preinstall
24+
25+
install:
26+
- pip install tox tox-travis
27+
28+
script:
29+
- ./.travis/runtox

.travis/config.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# Use this file to specify custom configuration for a project. Generally, this
4+
# involves the modification of the content of LSR_* environment variables, see
5+
#
6+
# * .travis/preinstall:
7+
#
8+
# - LSR_EXTRA_PACKAGES
9+
#
10+
# * .travis/runtox:
11+
#
12+
# - LSR_ANSIBLES
13+
# - LSR_MSCENARIOS
14+
#
15+
# * .travis/runcoveralls.sh:
16+
#
17+
# - LSR_PUBLISH_COVERAGE
18+
#
19+
# Environment variables that not start with LSR_* but have influence on CI
20+
# process:
21+
#
22+
# * run_pylint.py:
23+
#
24+
# - RUN_PYLINT_INCLUDE
25+
# - RUN_PYLINT_EXCLUDE
26+
# - RUN_PYLINT_DISABLED
27+
#
28+
# * .travis/runblack.sh:
29+
#
30+
# - RUN_BLACK_INCLUDE
31+
# - RUN_BLACK_EXCLUDE
32+
# - RUN_BLACK_DISABLED
33+
#
34+
# * .travis/runflake8.sh:
35+
#
36+
# - RUN_FLAKE8_DISABLED
37+
#
38+
39+
##
40+
# lsr_runcoveralls_hook ARGS
41+
#
42+
# ARGS - see .travis/runcoveralls.sh
43+
#
44+
# Called from .travis/runcoveralls.sh.
45+
function lsr_runcoveralls_hook() {
46+
# Add custom commands here.
47+
return 0
48+
}
49+
50+
##
51+
# lsr_runsyspycmd_hook ARGS
52+
#
53+
# ARGS - see .travis/runsyspycmd.sh
54+
#
55+
# Called from .travis/runsyspycmd.sh.
56+
function lsr_runsyspycmd_hook() {
57+
# Add custom commands here.
58+
return 0
59+
}

.travis/custom.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# This script is executed with two arguments passed to it:
5+
#
6+
# $1 - full path to environment python (python used inside virtual
7+
# environment created by tox)
8+
# $2 - full path to system python (python 3.x installed on the system)
9+
10+
set -e
11+
12+
ME=$(basename $0)
13+
SCRIPTDIR=$(readlink -f $(dirname $0))
14+
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)
15+
16+
# Include library and config:
17+
. ${SCRIPTDIR}/utils.sh
18+
. ${SCRIPTDIR}/config.sh
19+
20+
ENVPYTHON=$1
21+
SYSPYTHON=$2
22+
shift 2
23+
24+
# Write your custom commands here that should be run when `tox -e custom`:

.travis/preinstall

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# Install package specified by user in LSR_EXTRA_PACKAGES. Executed by Travis
5+
# during before_install phase.
6+
#
7+
# LSR_EXTRA_PACKAGES, set by user in .travis/config.sh, is a space separated
8+
# list of packages to be installed on the Travis build environment (Ubuntu).
9+
10+
set -e
11+
12+
SCRIPTDIR=$(readlink -f $(dirname $0))
13+
14+
# Include library.
15+
. ${SCRIPTDIR}/utils.sh
16+
17+
# Add python3-selinux package (it turned out that in some circumstances, i.e
18+
# if selinux policy is enforcing, selinux is required by molecule even if
19+
# running simple test).
20+
if lsr_compare_pythons python -eq /usr/bin/python3; then
21+
LSR_EXTRA_PACKAGES='python3-selinux'
22+
fi
23+
24+
# Include config.
25+
. ${SCRIPTDIR}/config.sh
26+
27+
# Install extra dependencies.
28+
if [[ "${LSR_EXTRA_PACKAGES}" ]]; then
29+
set -x
30+
sudo apt-get update
31+
sudo apt-get install -y ${LSR_EXTRA_PACKAGES}
32+
fi

.travis/runblack.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# Run black (the Python formatter). The first script argument is a full path
5+
# to Python interpreter, the rest of arguments are passed to black.
6+
7+
# Environment variables:
8+
#
9+
# RUN_BLACK_INCLUDE
10+
# a regular expression specifying files to be included; can be overridden
11+
# from command line by --include;
12+
#
13+
# RUN_BLACK_EXCLUDE
14+
# a regular expression specifying files to be excluded; can be overridden
15+
# from command line by --exclude;
16+
#
17+
# RUN_BLACK_DISABLED
18+
# if set to an arbitrary non-empty value, black will be not executed
19+
20+
set -e
21+
22+
ME=$(basename $0)
23+
SCRIPTDIR=$(readlink -f $(dirname $0))
24+
25+
# Include library and config.
26+
. ${SCRIPTDIR}/utils.sh
27+
. ${SCRIPTDIR}/config.sh
28+
29+
if [[ "${RUN_BLACK_DISABLED}" ]]; then
30+
lsr_info "${ME}: black is disabled. Skipping."
31+
exit 0
32+
fi
33+
34+
ENVPYTHON=$1
35+
shift
36+
37+
DEFAULT_INCLUDE='^[^.].*\.py$'
38+
DEFAULT_EXCLUDE='/(\.[^.].*|tests/roles)/'
39+
40+
INCLUDE_ARG=""
41+
EXCLUDE_ARG=""
42+
OTHER_ARGS=()
43+
44+
while [[ $# -gt 0 ]]; do
45+
case "$1" in
46+
--include)
47+
shift
48+
INCLUDE_ARG="$1"
49+
;;
50+
--exclude)
51+
shift
52+
EXCLUDE_ARG="$1"
53+
;;
54+
*)
55+
OTHER_ARGS+=( "$1" )
56+
;;
57+
esac
58+
shift
59+
done
60+
61+
set -x
62+
${ENVPYTHON} -m black \
63+
--include "${INCLUDE_ARG:-${RUN_BLACK_INCLUDE:-${DEFAULT_INCLUDE}}}" \
64+
--exclude "${EXCLUDE_ARG:-${RUN_BLACK_EXCLUDE:-${DEFAULT_EXCLUDE}}}" \
65+
"${OTHER_ARGS[@]}"

.travis/runcoveralls.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# Report coverage results using coveralls. The script is executed with these
5+
# parameters:
6+
#
7+
# $1 - full path to environment python
8+
# $2 - full path to system python
9+
#
10+
# coveralls is executed only if $1 coincides with $2 and $1's environment is
11+
# stable, i.e. TRAVIS_PYTHON_VERSION is of the form [:digit:] "." [:digit:]
12+
# (this prevents running coveralls more then once in the case if both X.Y and
13+
# X.Y-dev coincides with system python which version is also X.Y). The results
14+
# are reported only if LSR_PUBLISH_COVERAGE is non-empty.
15+
16+
set -e
17+
18+
ME=$(basename $0)
19+
SCRIPTDIR=$(readlink -f $(dirname $0))
20+
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)
21+
22+
# Include library and config.
23+
. ${SCRIPTDIR}/utils.sh
24+
. ${SCRIPTDIR}/config.sh
25+
26+
# Run user defined hook from .travis/config.sh.
27+
lsr_runcoveralls_hook "$@"
28+
29+
# Publish the results only if it is desired.
30+
if [[ -z "${LSR_PUBLISH_COVERAGE}" ]]; then
31+
lsr_info "${ME}: Publishing coverage report is not enabled. Skipping."
32+
exit 0
33+
fi
34+
35+
ENVPYTHON=$1
36+
SYSPYTHON=$2
37+
shift 2
38+
39+
if lsr_compare_pythons ${ENVPYTHON} -ne ${SYSPYTHON}; then
40+
lsr_info "${ME}:" \
41+
"Environment Python has no access to system Python libraries. Skipping."
42+
exit 0
43+
fi
44+
45+
if [[ ! "${TRAVIS_PYTHON_VERSION}" =~ ^[[:digit:]]\.[[:digit:]]$ ]]; then
46+
lsr_info "${ME}: Not stable environment. Skipping."
47+
exit 0
48+
fi
49+
50+
COVERALLSCMD=$(command -v coveralls)
51+
52+
# Fix coverage.
53+
cat > ${TOPDIR}/.coveragerc <<EOF
54+
[paths]
55+
source =
56+
.
57+
${TOPDIR}
58+
EOF
59+
mv ${TOPDIR}/.coverage ${TOPDIR}/.coverage.merge
60+
${ENVPYTHON} -m coverage combine --append ${TOPDIR}
61+
62+
set -x
63+
${ENVPYTHON} ${COVERALLSCMD}

.travis/runflake8.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# Run flake8. The first script argument is a full path to Python interpreter,
5+
# the rest of arguments are passed to flake8.
6+
7+
# Environment variables:
8+
#
9+
# RUN_FLAKE8_DISABLED
10+
# if set to an arbitrary non-empty value, flake8 will be not executed
11+
12+
set -e
13+
14+
ME=$(basename $0)
15+
SCRIPTDIR=$(readlink -f $(dirname $0))
16+
17+
# Include library and config.
18+
. ${SCRIPTDIR}/utils.sh
19+
. ${SCRIPTDIR}/config.sh
20+
21+
if [[ "${RUN_FLAKE8_DISABLED}" ]]; then
22+
lsr_info "${ME}: flake8 is disabled. Skipping."
23+
exit 0
24+
fi
25+
26+
ENVPYTHON=$1
27+
shift
28+
29+
set -x
30+
${ENVPYTHON} -m flake8 "$@"

.travis/runpytest.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MIT
3+
4+
# Wrapper around pytest. First argument is a full path to environment python,
5+
# the rest of arguments are passed to pytest.
6+
7+
set -e
8+
9+
ME=$(basename $0)
10+
SCRIPTDIR=$(readlink -f $(dirname $0))
11+
TOPDIR=$(readlink -f ${SCRIPTDIR}/..)
12+
13+
# Include library.
14+
. ${SCRIPTDIR}/utils.sh
15+
16+
if [[ ! -d ${TOPDIR}/tests/unit ]]; then
17+
lsr_info "${ME}: No unit tests found. Skipping."
18+
exit 0
19+
fi
20+
21+
ENVPYTHON=$1
22+
shift
23+
24+
PYTEST_OPTS=()
25+
PYTEST_OPTS_NOCOV=()
26+
USE_COV=no
27+
28+
# Filter out coverage options if there is nothing to be analyzed with coverage.
29+
while [[ $# -gt 0 ]]; do
30+
case "$1" in
31+
--cov=*)
32+
if [[ "${1:6}" && -d "${1:6}" ]]; then
33+
USE_COV=yes
34+
PYTEST_OPTS+=( "$1" )
35+
fi
36+
;;
37+
--cov*|--no-cov*)
38+
PYTEST_OPTS+=( "$1" )
39+
;;
40+
*)
41+
PYTEST_OPTS+=( "$1" )
42+
PYTEST_OPTS_NOCOV+=( "$1" )
43+
;;
44+
esac
45+
shift
46+
done
47+
48+
if [[ "${USE_COV}" == "no" ]]; then
49+
PYTEST_OPTS=( "${PYTEST_OPTS_NOCOV[@]}" )
50+
fi
51+
52+
set -x
53+
${ENVPYTHON} -m pytest "${PYTEST_OPTS[@]}"

0 commit comments

Comments
 (0)