Skip to content

Commit

Permalink
Merge pull request linux-system-roles#5 from i386x/new-travis-ci-files
Browse files Browse the repository at this point in the history
Add common Travis CI settings files
  • Loading branch information
i386x authored Nov 6, 2019
2 parents b792c5e + 26d3046 commit c9e6f8d
Show file tree
Hide file tree
Showing 40 changed files with 1,757 additions and 745 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
passes.yml
vault.yml
*.pyc
*.retry

/tests/.coverage
/tests/htmlcov*
/.tox
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-License-Identifier: MIT
---
language: python
env:
global:
- LSR_ANSIBLES='ansible==2.6.* ansible==2.7.* ansible==2.8.*'
- LSR_MSCENARIOS='default'
matrix:
include:
- python: 2.6
dist: trusty
- python: 2.7
- python: 3.5
- python: 3.6
- python: 3.7
- python: 3.7-dev
- python: 3.8-dev

services:
- docker

before_install:
- ./.travis/preinstall

install:
- pip install tox tox-travis

script:
- ./.travis/runtox
59 changes: 59 additions & 0 deletions .travis/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SPDX-License-Identifier: MIT
#
# Use this file to specify custom configuration for a project. Generally, this
# involves the modification of the content of LSR_* environment variables, see
#
# * .travis/preinstall:
#
# - LSR_EXTRA_PACKAGES
#
# * .travis/runtox:
#
# - LSR_ANSIBLES
# - LSR_MSCENARIOS
#
# * .travis/runcoveralls.sh:
#
# - LSR_PUBLISH_COVERAGE
#
# Environment variables that not start with LSR_* but have influence on CI
# process:
#
# * run_pylint.py:
#
# - RUN_PYLINT_INCLUDE
# - RUN_PYLINT_EXCLUDE
# - RUN_PYLINT_DISABLED
#
# * .travis/runblack.sh:
#
# - RUN_BLACK_INCLUDE
# - RUN_BLACK_EXCLUDE
# - RUN_BLACK_DISABLED
#
# * .travis/runflake8.sh:
#
# - RUN_FLAKE8_DISABLED
#

##
# lsr_runcoveralls_hook ARGS
#
# ARGS - see .travis/runcoveralls.sh
#
# Called from .travis/runcoveralls.sh.
function lsr_runcoveralls_hook() {
# Add custom commands here.
return 0
}

##
# lsr_runsyspycmd_hook ARGS
#
# ARGS - see .travis/runsyspycmd.sh
#
# Called from .travis/runsyspycmd.sh.
function lsr_runsyspycmd_hook() {
# Add custom commands here.
return 0
}
24 changes: 24 additions & 0 deletions .travis/custom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# This script is executed with two arguments passed to it:
#
# $1 - full path to environment python (python used inside virtual
# environment created by tox)
# $2 - full path to system python (python 3.x installed on the system)

set -e

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

# Include library and config:
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

ENVPYTHON=$1
SYSPYTHON=$2
shift 2

# Write your custom commands here that should be run when `tox -e custom`:
32 changes: 32 additions & 0 deletions .travis/preinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Install package specified by user in LSR_EXTRA_PACKAGES. Executed by Travis
# during before_install phase.
#
# LSR_EXTRA_PACKAGES, set by user in .travis/config.sh, is a space separated
# list of packages to be installed on the Travis build environment (Ubuntu).

set -e

SCRIPTDIR=$(readlink -f $(dirname $0))

# Include library.
. ${SCRIPTDIR}/utils.sh

# Add python3-selinux package (it turned out that in some circumstances, i.e
# if selinux policy is enforcing, selinux is required by molecule even if
# running simple test).
if lsr_compare_pythons python -eq /usr/bin/python3; then
LSR_EXTRA_PACKAGES='python3-selinux'
fi

# Include config.
. ${SCRIPTDIR}/config.sh

# Install extra dependencies.
if [[ "${LSR_EXTRA_PACKAGES}" ]]; then
set -x
sudo apt-get update
sudo apt-get install -y ${LSR_EXTRA_PACKAGES}
fi
65 changes: 65 additions & 0 deletions .travis/runblack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Run black (the Python formatter). The first script argument is a full path
# to Python interpreter, the rest of arguments are passed to black.

# Environment variables:
#
# RUN_BLACK_INCLUDE
# a regular expression specifying files to be included; can be overridden
# from command line by --include;
#
# RUN_BLACK_EXCLUDE
# a regular expression specifying files to be excluded; can be overridden
# from command line by --exclude;
#
# RUN_BLACK_DISABLED
# if set to an arbitrary non-empty value, black will be not executed

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))

# Include library and config.
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

if [[ "${RUN_BLACK_DISABLED}" ]]; then
lsr_info "${ME}: black is disabled. Skipping."
exit 0
fi

ENVPYTHON=$1
shift

DEFAULT_INCLUDE='^[^.].*\.py$'
DEFAULT_EXCLUDE='/(\.[^.].*|tests/roles)/'

INCLUDE_ARG=""
EXCLUDE_ARG=""
OTHER_ARGS=()

while [[ $# -gt 0 ]]; do
case "$1" in
--include)
shift
INCLUDE_ARG="$1"
;;
--exclude)
shift
EXCLUDE_ARG="$1"
;;
*)
OTHER_ARGS+=( "$1" )
;;
esac
shift
done

set -x
${ENVPYTHON} -m black \
--include "${INCLUDE_ARG:-${RUN_BLACK_INCLUDE:-${DEFAULT_INCLUDE}}}" \
--exclude "${EXCLUDE_ARG:-${RUN_BLACK_EXCLUDE:-${DEFAULT_EXCLUDE}}}" \
"${OTHER_ARGS[@]}"
63 changes: 63 additions & 0 deletions .travis/runcoveralls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Report coverage results using coveralls. The script is executed with these
# parameters:
#
# $1 - full path to environment python
# $2 - full path to system python
#
# coveralls is executed only if $1 coincides with $2 and $1's environment is
# stable, i.e. TRAVIS_PYTHON_VERSION is of the form [:digit:] "." [:digit:]
# (this prevents running coveralls more then once in the case if both X.Y and
# X.Y-dev coincides with system python which version is also X.Y). The results
# are reported only if LSR_PUBLISH_COVERAGE is non-empty.

set -e

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

# Include library and config.
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

# Run user defined hook from .travis/config.sh.
lsr_runcoveralls_hook "$@"

# 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

ENVPYTHON=$1
SYSPYTHON=$2
shift 2

if lsr_compare_pythons ${ENVPYTHON} -ne ${SYSPYTHON}; then
lsr_info "${ME}:" \
"Environment Python has no access to system Python libraries. Skipping."
exit 0
fi

if [[ ! "${TRAVIS_PYTHON_VERSION}" =~ ^[[:digit:]]\.[[:digit:]]$ ]]; then
lsr_info "${ME}: Not stable environment. Skipping."
exit 0
fi

COVERALLSCMD=$(command -v coveralls)

# Fix coverage.
cat > ${TOPDIR}/.coveragerc <<EOF
[paths]
source =
.
${TOPDIR}
EOF
mv ${TOPDIR}/.coverage ${TOPDIR}/.coverage.merge
${ENVPYTHON} -m coverage combine --append ${TOPDIR}

set -x
${ENVPYTHON} ${COVERALLSCMD}
30 changes: 30 additions & 0 deletions .travis/runflake8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

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

# Environment variables:
#
# RUN_FLAKE8_DISABLED
# if set to an arbitrary non-empty value, flake8 will be not executed

set -e

ME=$(basename $0)
SCRIPTDIR=$(readlink -f $(dirname $0))

# Include library and config.
. ${SCRIPTDIR}/utils.sh
. ${SCRIPTDIR}/config.sh

if [[ "${RUN_FLAKE8_DISABLED}" ]]; then
lsr_info "${ME}: flake8 is disabled. Skipping."
exit 0
fi

ENVPYTHON=$1
shift

set -x
${ENVPYTHON} -m flake8 "$@"
53 changes: 53 additions & 0 deletions .travis/runpytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

# Wrapper around pytest. First argument is a full path to environment python,
# the rest of arguments are passed to pytest.

set -e

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

# Include library.
. ${SCRIPTDIR}/utils.sh

if [[ ! -d ${TOPDIR}/tests/unit ]]; then
lsr_info "${ME}: No unit tests found. Skipping."
exit 0
fi

ENVPYTHON=$1
shift

PYTEST_OPTS=()
PYTEST_OPTS_NOCOV=()
USE_COV=no

# Filter out coverage options if there is nothing to be analyzed with coverage.
while [[ $# -gt 0 ]]; do
case "$1" in
--cov=*)
if [[ "${1:6}" && -d "${1:6}" ]]; then
USE_COV=yes
PYTEST_OPTS+=( "$1" )
fi
;;
--cov*|--no-cov*)
PYTEST_OPTS+=( "$1" )
;;
*)
PYTEST_OPTS+=( "$1" )
PYTEST_OPTS_NOCOV+=( "$1" )
;;
esac
shift
done

if [[ "${USE_COV}" == "no" ]]; then
PYTEST_OPTS=( "${PYTEST_OPTS_NOCOV[@]}" )
fi

set -x
${ENVPYTHON} -m pytest "${PYTEST_OPTS[@]}"
Loading

0 comments on commit c9e6f8d

Please sign in to comment.