tobiko/tools/ci/ir

81 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
source $(dirname "$0")/activate
source $(dirname "$0")/tox
set -eu
if [ "${IR_DEBUG:-}" != "" ]; then
set -x
fi
IR_VIRTUAL_ENV=$(realpath "${IR_VIRTUAL_ENV:-.tox/infrared}")
IR_REPO="https://github.com/redhat-openstack/infrared.git"
IR_BRANCH=${IR_BRANCH:-master}
IR_SOURCE_DIR=$(realpath "${IR_SOURCE_DIR:-${IR_VIRTUAL_ENV}/infrared}")
IR_EXECUTABLE=${IR_VIRTUAL_ENV}/bin/infrared
export IR_HOME=$(realpath ${IR_HOME:-$(pwd)/.infrared/})
IR_TOBIKO_PLUGIN=$(realpath ${IR_TOBIKO_PLUGIN:-$(pwd)/roles/infrared})
IR_WORKSPACE_FILE=${IR_WORKSPACE_FILE:-$(realpath ./workspace.tgz)}
function ir {
ir_setup
"${IR_EXECUTABLE}" "$@"
}
function ir_setup {
if ! ir_activate; then
tox -e infrared --notest
ir_activate
fi
if ! [ -x "${IR_EXECUTABLE}" ]; then
git clone "${IR_REPO}" -b "${IR_BRANCH}" "${IR_SOURCE_DIR}"
local package_name
for package_name in pip setuptools "${IR_SOURCE_DIR}"; do
pip install --upgrade "${package_name}"
done
rm -fR "${IR_HOME}"
(
cd "${IR_SOURCE_DIR}"
"${IR_EXECUTABLE}" plugin list --available --versions || true
"${IR_EXECUTABLE}" plugin remove tobiko || true
"${IR_EXECUTABLE}" plugin add "${IR_TOBIKO_PLUGIN}"
if [ -f "${IR_WORKSPACE_FILE}" ]; then
"${IR_EXECUTABLE}" workspace import "${IR_WORKSPACE_FILE}"
fi
)
fi
mkdir -p "${IR_HOME}"
}
function ir_activate {
local venv_script=${IR_VIRTUAL_ENV}/bin/activate
if ! [ -r "${venv_script}" ]; then
return 1
fi
if ! ir_is_active; then
# Activate only once
set +eu
source "${venv_script}"
set -eu
ir_is_active
fi
}
function ir_is_active {
[ "$(python_prefix)" == "${IR_VIRTUAL_ENV}" ]
}
if [ $(basename "$0") == ir ]; then
ir "$@"
fi