7 #-------------------------------------------------------------------------------
8 # Various tests are run using tox such as jjbtest, yamllint, and shellcheck.
9 #-------------------------------------------------------------------------------
12 echo "Info : Preparing to run tox for the repo ${GERRIT_PROJECT:-project}"
14 # set and export defaults
15 LINT_TYPE="${LINT_TYPE:-jjbtest}"
16 VERBOSITY=${VERBOSITY:-false}
17 export LINT_TYPE VERBOSITY
19 # ensure we are in job build WORKSPACE
22 # set DEBIAN_FRONTEND to run apt non-interactively
23 DEBIAN_FRONTEND=noninteractive
24 export DEBIAN_FRONTEND
26 # Wait for other apt auto-update process to finish by checking the dpkg lock file.
27 DPKG_LOCK="/var/lib/dpkg/lock-frontend"
29 while sudo lsof "${DPKG_LOCK}" > /dev/null 2>&1 ; do
30 echo "DPKG file locked: ${DPKG_LOCK}."
31 echo " Waiting for another pkg instalaltion process to finish ..."
33 if [[ ${try} -gt 120 ]] ; then
34 echo "ERROR: Max number of re-tries reached, exiting..."
40 # install dependencies
41 echo "Info : Install python3.7-minimal python3-distutils virtualenv using apt"
42 redirect_cmd sudo apt update
43 redirect_cmd sudo apt install -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew -y \
44 python3.7-minimal python3-distutils virtualenv
46 # create and activate virtualenv
47 echo "Info : Create and activate python virtualenv"
48 redirect_cmd virtualenv -p python3 .venv
50 redirect_cmd source .venv/bin/activate
53 # install only tox since the rest of the requirements are installed by tox itself
54 TOX_PACKAGE=$(grep "^tox==" jjb/infra/test-requirements.txt)
55 echo "Info : Install $TOX_PACKAGE"
56 redirect_cmd pip install --force-reinstall "$TOX_PACKAGE"
59 echo "Info : Run $LINT_TYPE using tox"
60 echo "----------------------------------------------------"
62 echo "----------------------------------------------------"
66 #-------------------------------------------------------------------------------
67 # In some cases, it is useful to see all the output generated by commands so
68 # this function makes it possible for users to achieve that by not redirecting
69 # output to /dev/null when verbosity is enabled
70 #-------------------------------------------------------------------------------
73 if [[ "$VERBOSITY" == "false" ]]; then
80 #-------------------------------------------------------------------------------
82 #-------------------------------------------------------------------------------
86 # vim: set ts=2 sw=2 ft=bash expandtab: