tobiko/tools/ci/ir

94 lines
2.3 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)}
IR_WORKSPACE_URL=${IR_WORKSPACE_URL:-}
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
# Cleanup IR workspaces
rm -fR "${IR_HOME}"
(
# IR requires to work from its source folder
cd "${IR_SOURCE_DIR}"
# Install IR plugins
"${IR_EXECUTABLE}" plugin list --available --versions || true
"${IR_EXECUTABLE}" plugin add "${IR_TOBIKO_PLUGIN}"
# Import IR workspace
if [ "${IR_WORKSPACE_URL}" != "" ]; then
local temp_file=$(mktemp)
curl "${IR_WORKSPACE_URL}" -o "${temp_file}"
mkdir -p $(dirname "${IR_WORKSPACE_FILE}")
mv "${temp_file}" "${IR_WORKSPACE_FILE}"
fi
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