github.com/crowdsecurity/crowdsec@v1.6.1/test/ansible/prepare-run (about)

     1  #!/usr/bin/env bash
     2  
     3  # This loops over all the available boxes, running the test suite on each one.
     4  # The results are collected in a file. If the file already exists, tests are not run again.
     5  
     6  env=$1
     7  
     8  if [[ -z "${env}" ]]; then
     9    echo "Usage: $0 <env> [vagrant-dir]..."
    10    exit 1
    11  fi
    12  
    13  shift
    14  
    15  vagrant_dirs=("$@")
    16  if [[ $# -eq 0 ]]; then
    17      # find all targets, with possibly weird names, don't go into subfolders (like 'experimental/')
    18      readarray -d '' vagrant_dirs < <(find vagrant -mindepth 1 -maxdepth 1 -type d -print0 | sort -z | grep -z -v .vagrant)
    19  fi
    20  
    21  #shellcheck disable=SC1090
    22  . "${env}"
    23  
    24  VAGRANT_FORCE_COLOR=true
    25  export VAGRANT_FORCE_COLOR
    26  
    27  for vm in "${vagrant_dirs[@]}"; do
    28      outfile="$(basename "${env}").out"
    29      pushd "${vm}" >/dev/null || exit
    30      if [[ ! -f "Vagrantfile" ]]; then
    31              popd >/dev/null || exit
    32              continue
    33      fi
    34      echo "Prepare and run tests on ${vm}..."
    35      if [[ -x "skip" ]]; then
    36          if ! ./skip; then
    37              popd >/dev/null || exit
    38              continue
    39          fi
    40      fi
    41      if [[ ! -f "${outfile}" ]]; then
    42          vagrant up --no-provision
    43          vagrant provision 2>&1 | tee "${outfile}"
    44          vagrant destroy -f
    45      else
    46          echo "skipping: ${vm}, file ${outfile} already exists." >&2
    47      fi
    48      popd >/dev/null || exit
    49  done