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

implement and use true/false helpers #458

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export TARGET_REPO_NAME=$CI_PROJECT_NAME
export _FOLDING_TYPE=gitlab

if [ -n "$SSH_PRIVATE_KEY" ]; then
if [ "$CI_DISPOSABLE_ENVIRONMENT" != true ] && ! [ -f /.dockerenv ] ; then
if ici_is_false_or_unset "$CI_DISPOSABLE_ENVIRONMENT" && ! [ -f /.dockerenv ] ; then
echo "SSH auto set-up cannot be used in non-disposable environments"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/builders/catkin_make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local -a opts
if [ "$PARALLEL_TESTS" == false ]; then
if ici_is_false_or_unset "$PARALLEL_TESTS"; then
opts+=(-j1)
fi
ici_exec_in_workspace "$extend" "$ws" catkin_make --make-args run_tests "${opts[@]}" "$@"
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/builders/catkin_make_isolated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function builder_run_build {

function builder_run_tests {
local -a opts
if [ "$PARALLEL_TESTS" == false ]; then
if ici_is_false_or_unset "$PARALLEL_TESTS"; then
opts+=(-j1)
fi
_run_catkin_make_isolated run_tests "$1" "$2" "${opts[@]}"
Expand Down
8 changes: 4 additions & 4 deletions industrial_ci/src/builders/catkin_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function builder_run_build {
local extend=$1; shift
local ws=$1; shift
local -a opts
if [ "$VERBOSE_OUTPUT" != false ]; then
if ici_is_true"$VERBOSE_OUTPUT"; then
opts+=("-vi")
fi
ici_exec_in_workspace "$extend" "$ws" catkin config --install
Expand All @@ -34,13 +34,13 @@ function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local -a opts
if [ "$VERBOSE_TESTS" != false ]; then
if ici_is_true"$VERBOSE_TESTS"; then
opts+=(-v)
fi
if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then
if ici_is_true"$IMMEDIATE_TEST_OUTPUT"; then
opts+=(-i)
fi
if [ "$PARALLEL_TESTS" == false ]; then
if ici_is_false_or_unset "$PARALLEL_TESTS"; then
opts+=(-j1 -p1)
fi
ici_exec_in_workspace "$extend" "$ws" catkin build --catkin-make-args run_tests -- "${opts[@]}" --no-status
Expand Down
4 changes: 2 additions & 2 deletions industrial_ci/src/builders/colcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local output_handler
if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then
if ici_is_true "$IMMEDIATE_TEST_OUTPUT"; then
output_handler="console_direct+"
else
output_handler="console_cohesion+"
fi
local opts=(--event-handlers "${_colcon_event_handlers[@]}" "${output_handler}")
if [ "$PARALLEL_TESTS" == false ]; then
if ici_is_false_or_unset "$PARALLEL_TESTS"; then
opts+=(--executor sequential --ctest-args -j1)
else
opts+=(--executor parallel)
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ source "${ICI_SRC_PATH}/env.sh"
trap ici_exit EXIT # install industrial_ci exit handler

# Start prerelease, and once it finishs then finish this script too.
if [ "$PRERELEASE" == true ]; then
if ici_is_true "$PRERELEASE"; then
# shellcheck source=industrial_ci/src/tests/ros_prerelease.sh
source "${ICI_SRC_PATH}/tests/ros_prerelease.sh"
run_ros_prerelease
Expand Down
4 changes: 2 additions & 2 deletions industrial_ci/src/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ function docker_cp {
function ici_docker_build() {
local -a build_opts
ici_parse_env_array build_opts DOCKER_BUILD_OPTS
if [ "$DOCKER_PULL" != false ]; then
if ici_is_true_or_unset "$DOCKER_PULL"; then
build_opts+=("--pull")
fi
docker build -t "$DOCKER_IMAGE" "${build_opts[@]}" "$@"
}

function ici_docker_try_pull {
local image=$1
if [ "$DOCKER_PULL" != false ]; then
if ici_is_true_or_unset "$DOCKER_PULL"; then
echo "Pulling Docker image '$image'..."
ici_quiet docker pull "$image"
fi
Expand Down
10 changes: 5 additions & 5 deletions industrial_ci/src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ici_enforce_deprecated CATKIN_CONFIG "Explicit catkin configuration is not avail
ici_enforce_deprecated INJECT_QEMU "Please check https://github.com/ros-industrial/industrial_ci/blob/master/doc/migration_guide.md#inject_qemu"

if [ -n "$NOT_TEST_INSTALL" ]; then
if [ "$NOT_TEST_INSTALL" != true ]; then
if ici_is_false "$NOT_TEST_INSTALL"; then
ici_enforce_deprecated NOT_TEST_INSTALL "testing installed test files has been removed."
else
ici_mark_deprecated NOT_TEST_INSTALL "testing installed test files has been removed, NOT_TEST_INSTALL=false is superfluous"
Expand Down Expand Up @@ -80,7 +80,7 @@ function use_snapshot() {
}

function use_repo_or_final_snapshot() {
if [ "$ROS_VERSION_EOL" = true ]; then
if ici_is_true "$ROS_VERSION_EOL"; then
use_snapshot final
if [ -n "$ROS_REPO" ]; then
ici_warn "'$ROS_DISTRO' is in end-of-life state, ROS_REPO='$ROS_REPO' gets ignored"
Expand Down Expand Up @@ -242,20 +242,20 @@ if [ "$UPSTREAM_WORKSPACE" = "debian" ]; then
unset UPSTREAM_WORKSPACE
fi

if [ "$USE_DEB" = true ]; then
if ici_is_true "$USE_DEB"; then
if [ "${UPSTREAM_WORKSPACE:-debian}" != "debian" ]; then
ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict"
fi
ici_warn "Setting 'USE_DEB=true' is superfluous"
fi

if [ "$UPSTREAM_WORKSPACE" = "file" ] || [ "${USE_DEB:-true}" != true ]; then
if [ "$UPSTREAM_WORKSPACE" = "file" ] || ici_is_false "$USE_DEB"; then
ROSINSTALL_FILENAME="${ROSINSTALL_FILENAME:-.travis.rosinstall}"
if [ -f "$TARGET_REPO_PATH/$ROSINSTALL_FILENAME.$ROS_DISTRO" ]; then
ROSINSTALL_FILENAME="$ROSINSTALL_FILENAME.$ROS_DISTRO"
fi

if [ "${USE_DEB:-true}" != true ]; then # means UPSTREAM_WORKSPACE=file
if ici_is_false "$USE_DEB"; then # means UPSTREAM_WORKSPACE=file
if [ "${UPSTREAM_WORKSPACE:-file}" != "file" ]; then
ici_error "USE_DEB and UPSTREAM_WORKSPACE are in conflict"
fi
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/tests/abi_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function abi_process_workspace() {
}

function abi_configure() {
if [ "$ABICHECK_MERGE" = true ]; then
if ici_is_true "$ABICHECK_MERGE"; then
local ref_list
if ici_split_array ref_list "$(cd "$TARGET_REPO_PATH" && git rev-list --parents -n 1 HEAD)" && [ "${#ref_list[@]}" -gt 2 ]; then
ABICHECK_VERSION="${ref_list[1]}"
Expand Down
12 changes: 6 additions & 6 deletions industrial_ci/src/tests/source_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function run_source_tests {
target_ws=~/target_ws
downstream_ws=~/downstream_ws

if [ "$CCACHE_DIR" ]; then
if [ -n "$CCACHE_DIR" ]; then
ici_run "setup_ccache" ici_asroot apt-get install -qq -y ccache
export PATH="/usr/lib/ccache:$PATH"
fi
Expand All @@ -122,16 +122,16 @@ function run_source_tests {
extend="$upstream_ws/install"
fi

if [ "${CLANG_TIDY:-false}" != false ]; then
if ! ici_is_false_or_unset "$CLANG_TIDY"; then
TARGET_CMAKE_ARGS="$TARGET_CMAKE_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi
ici_with_ws "$target_ws" ici_build_workspace "target" "$extend" "$target_ws"

if [ "$NOT_TEST_BUILD" != "true" ]; then
if ici_is_false_or_unset "$NOT_TEST_BUILD"; then
ici_with_ws "$target_ws" ici_test_workspace "target" "$extend" "$target_ws"
fi

if [ "$CATKIN_LINT" == "true" ] || [ "$CATKIN_LINT" == "pedantic" ]; then
if ici_is_true "$CATKIN_LINT" || [ "$CATKIN_LINT" == "pedantic" ]; then
ici_run "install_catkin_lint" install_catkin_lint
local -a catkin_lint_args
ici_parse_env_array catkin_lint_args CATKIN_LINT_ARGS
Expand All @@ -141,7 +141,7 @@ function run_source_tests {
ici_with_ws "$target_ws" ici_run "catkin_lint" ici_exec_in_workspace "$extend" "$target_ws" catkin_lint --explain "${catkin_lint_args[@]}" src

fi
if [ "${CLANG_TIDY:-false}" != false ]; then
if ! ici_is_false_or_unset "$CLANG_TIDY"; then
run_clang_tidy_check "$target_ws"
fi

Expand All @@ -150,7 +150,7 @@ function run_source_tests {
ici_with_ws "$downstream_ws" ici_build_workspace "downstream" "$extend" "$downstream_ws"
#extend="$downstream_ws/install"

if [ "$NOT_TEST_DOWNSTREAM" != "true" ]; then
if ici_is_true_or_unset "$NOT_TEST_DOWNSTREAM"; then
ici_with_ws "$downstream_ws" ici_test_workspace "downstream" "$extend" "$downstream_ws"
fi
fi
Expand Down
38 changes: 34 additions & 4 deletions industrial_ci/src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ function ici_ansi_cleared_line {
echo -en "$*\r\e[0K"
}

function ici_is_true {
local v=$1; shift
case "${v,,}" in
"true" | "on" | "enabled" | "1")
return 0
;;
esac
return 1
}

function ici_is_false {
local v=$1; shift
case "${v,,}" in
"false" | "off" | "disabled" | "0")
return 0
;;
esac
return 1
}

function ici_is_true_or_unset {
local v=$1; shift
[ -z "$v" ] || ici_is_true "$v"
}

function ici_is_false_or_unset {
local v=$1; shift
[ -z "$v" ] || ici_is_false "$v"
}

function ici_source_setup {
local u_set=1
[[ $- =~ u ]] || u_set=0
Expand Down Expand Up @@ -105,7 +135,7 @@ source "${ICI_SRC_PATH}/folding/${_FOLDING_TYPE:-none}.sh" || ici_error "Folding

function ici_time_start {
ici_hook "before_${1}"
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi
if ici_is_true "$DEBUG_BASH"; then set +x; fi
ICI_START_TIME=$(date -u +%s%N)
ICI_TIME_ID="$(printf %08x $((RANDOM * RANDOM)))"
ICI_FOLD_NAME=$1
Expand All @@ -116,7 +146,7 @@ function ici_time_start {

ici_color_output $ANSI_BLUE ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
ici_color_output $ANSI_BLUE "Starting function '$ICI_FOLD_NAME'"
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi
if ici_is_true "$DEBUG_BASH"; then set -x; fi
}

#######################################
Expand All @@ -135,7 +165,7 @@ function ici_time_start {
# (None)
#######################################
function ici_time_end {
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi
if ici_is_true "$DEBUG_BASH"; then set +x; fi
local color_wrap=${1:-${ANSI_GREEN}}
local exit_code=${2:-$?}
local name=$ICI_FOLD_NAME
Expand All @@ -150,7 +180,7 @@ function ici_time_end {
ici_color_output "$color_wrap" "Function '$name' returned with code '${exit_code}' after $(( elapsed_seconds / 60 )) min $(( elapsed_seconds % 60 )) sec"

unset ICI_FOLD_NAME
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi
if ici_is_true "$DEBUG_BASH"; then set -x; fi
ici_hook "after_${name}"

}
Expand Down