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

RHELPLAN-42920 - Collections - script - add tox/travis tests for coll… #45

Merged
merged 1 commit into from
Oct 8, 2020
Merged
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
39 changes: 39 additions & 0 deletions .travis/runcollection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
# SPDX-License-Identifier: MIT

set -e

#uncomment if you use $ME - otherwise set in utils.sh
#ME=$(basename "$0")
SCRIPTDIR=$(readlink -f "$(dirname "$0")")

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

# Collection commands that are run when `tox -e collection`:
role=$(basename "${TOPDIR}")
toxworkdir=${1:-"${TOPDIR}"/.tox}
STABLE_TAG=${2:-master}
cd "${toxworkdir}"
toxworkdir=$(pwd)
envlist=${3:- "black,flake8,yamllint,py38,shellcheck"}
automaintenancerepo=https://raw.githubusercontent.com/linux-system-roles/auto-maintenance/

curl -L -o lsr_role2collection.py "${automaintenancerepo}${STABLE_TAG}"/lsr_role2collection.py
curl -L -o ansible_role_parser.py "${automaintenancerepo}${STABLE_TAG}"/ansible_role_parser.py

python lsr_role2collection.py --src-path "${TOPDIR}/.." --dest-path "${toxworkdir}" --role "${role}" > "${toxworkdir}"/collection.out 2>&1

yamllint="${toxworkdir}"/ansible_collections/fedora/system_roles/.yamllint_defaults.yml
sed -i -e 's/\( *\)\(document-start: disable\)/\1\2\n\1line-length:\n\1\1level: warning/' "${yamllint}"

cd ansible_collections/fedora/system_roles
tox -e "${envlist}" 2>&1 | tee "${toxworkdir}"/collection.tox.out || :

rm -rf "${toxworkdir}"/auto-maintenance "${toxworkdir}"/ansible_collections
cd "${TOPDIR}"
res=$(grep "^ERROR: .*failed" "${toxworkdir}"/collection.tox.out || :)
if [ "$res" != "" ]; then
lsr_error "${ME}: tox in the converted collection format failed."
exit 1
fi
26 changes: 25 additions & 1 deletion .travis/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ function lsr_venv_python_matches_system_python() {
lsr_compare_pythons "${1:-python}" -eq "$syspython"
}

function run_setup_module_utils() {
local srcdir
srcdir="$1"
local destdir
destdir="$2"
if [ -x "$TOPDIR/tests/setup_module_utils.sh" ]; then
bash "$TOPDIR/tests/setup_module_utils.sh" "$srcdir" "$destdir"
else
setup_module_util=$( find "$TOPDIR"/tests -name "setup_module_utils.sh" | head -n 1 )
if [ "$setup_module_util" != "" ]; then
bash "$setup_module_util" "$srcdir" "$destdir"
fi
fi
}

##
# lsr_setup_module_utils [$1] [$2]
#
Expand All @@ -189,7 +204,16 @@ function lsr_setup_module_utils() {
local destdir
destdir="${2:-$DEST_MODULE_UTILS_DIR}"
if [ -n "$srcdir" ] && [ -d "$srcdir" ] && [ -n "$destdir" ] && [ -d "$destdir" ]; then
bash "$TOPDIR/tests/setup_module_utils.sh" "$srcdir" "$destdir"
run_setup_module_utils "$srcdir" "$destdir"
else
srcdir="${SRC_COLL_MODULE_UTILS_DIR}"
destdir="${DEST_COLL_MODULE_UTILS_DIR}"
if [ -n "$destdir" ] && [ -d "$destdir" ]; then
if [ -n "$srcdir" ] && [ ! -d "$srcdir" ]; then
mkdir -p "$srcdir"
fi
run_setup_module_utils "$srcdir" "$destdir"
fi
fi
}

Expand Down
16 changes: 13 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
envlist =
black, pylint, flake8, yamllint
py{26,27,36,37,38}, shellcheck
custom
collection, custom
skipsdist = true
skip_missing_interpreters = true

Expand Down Expand Up @@ -164,6 +164,16 @@ commands =
{[testenv:molecule_syntax]commands}
{[testenv:molecule_test]commands}

[testenv:collection]
i386x marked this conversation as resolved.
Show resolved Hide resolved
changedir = {toxinidir}
ansible_python_interpreter = /usr/bin/python3
deps =
ruamel.yaml
ansible
jmespath
commands =
bash {toxinidir}/.travis/runcollection.sh {toxworkdir} master

[testenv:custom]
changedir = {toxinidir}
envdir = {toxworkdir}/env-{env:TRAVIS_PYTHON_VERSION:custom}
Expand All @@ -184,7 +194,7 @@ addopts = -rxs
[flake8]
show_source = true
max-line-length = 88
ignore = E402,W503
ignore = E402,W503,E501
exclude = .venv,.tox
statistics = true
#verbose = 3
Expand All @@ -200,7 +210,7 @@ max-line-length = 88
python =
2.6: py26,coveralls,custom
2.7: py27,coveralls,flake8,pylint,custom
3.6: py36,coveralls,black,yamllint,shellcheck,custom
3.6: py36,coveralls,black,yamllint,shellcheck,custom,collection
3.7: py37,coveralls,custom
3.8: py38,coveralls,custom
3.8-dev: py38,coveralls,custom