Skip to content

Commit

Permalink
Format with shfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-luedtke committed Jan 28, 2021
1 parent b23dcca commit c524df6
Show file tree
Hide file tree
Showing 30 changed files with 705 additions and 611 deletions.
2 changes: 1 addition & 1 deletion .github/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# This is the entrypoint for GitHub Actions only.

# 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

export TARGET_REPO_PATH=$GITHUB_WORKSPACE
export TARGET_REPO_NAME=${GITHUB_REPOSITORY##*/}
Expand Down
2 changes: 1 addition & 1 deletion bitbucket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# This is the entrypoint for BitBucket Pipelines only.

# 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

export TARGET_REPO_PATH=$BITBUCKET_CLONE_DIR
export TARGET_REPO_NAME=${BITBUCKET_REPO_SLUG##*/}
Expand Down
2 changes: 1 addition & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# This is the generic entrypoint for CI services.

# 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

export TARGET_REPO_PATH=${TARGET_REPO_PATH:-$(pwd)}
export TARGET_REPO_NAME=${TARGET_REPO_NAME:-${TARGET_REPO_PATH##*/}}
Expand Down
38 changes: 21 additions & 17 deletions gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@
# This is the entrypoint for Gitlab CI only.

# 2016/05/18 http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DIR_THIS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

export TARGET_REPO_PATH=$CI_PROJECT_DIR
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
echo "SSH auto set-up cannot be used in non-disposable environments"
exit 1
fi

# start SSH agent
# shellcheck disable=SC2046
eval $(ssh-agent -s)
# add key to agent
ssh-add <(echo "$SSH_PRIVATE_KEY") || { res=$?; echo "could not add ssh key"; exit $res; }

if [ -n "$SSH_SERVER_HOSTKEYS" ]; then
mkdir -p ~/.ssh
# setup known hosts
echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts
fi
if [ "$CI_DISPOSABLE_ENVIRONMENT" != true ] && ! [ -f /.dockerenv ]; then
echo "SSH auto set-up cannot be used in non-disposable environments"
exit 1
fi

# start SSH agent
# shellcheck disable=SC2046
eval $(ssh-agent -s)
# add key to agent
ssh-add <(echo "$SSH_PRIVATE_KEY") || {
res=$?
echo "could not add ssh key"
exit $res
}

if [ -n "$SSH_SERVER_HOSTKEYS" ]; then
mkdir -p ~/.ssh
# setup known hosts
echo "$SSH_SERVER_HOSTKEYS" >~/.ssh/known_hosts
fi
fi

env "$@" bash "$DIR_THIS/industrial_ci/src/ci_main.sh"
5 changes: 3 additions & 2 deletions industrial_ci/_wrap_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
set -e # exit script on errors

if [ -n "$_EXTERNAL_REPO" ]; then
export TRAVIS_BUILD_DIR; TRAVIS_BUILD_DIR=$(mktemp -d)
export TRAVIS_BUILD_DIR
TRAVIS_BUILD_DIR=$(mktemp -d)
source ./industrial_ci/src/workspace.sh
IFS=" " read -r -a parts <<< "$(ici_resolve_scheme "$_EXTERNAL_REPO")" # name, type, url, version
IFS=" " read -r -a parts <<<"$(ici_resolve_scheme "$_EXTERNAL_REPO")" # name, type, url, version
echo "Cloning '${parts[2]}'...'"
git clone -q "${parts[2]}" "$TRAVIS_BUILD_DIR"
git -C "$TRAVIS_BUILD_DIR" checkout "${parts[3]}"
Expand Down
35 changes: 17 additions & 18 deletions industrial_ci/scripts/rerun_ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

function show_help {
cat - <<'EOF'
cat - <<'EOF'
Usage:
rerun_ci --list
rerun_ci [--clean] TARGET_PATH [PARAM=VALUE>]...
Expand All @@ -28,47 +28,46 @@ EOF

case "$1" in
"--list")
mapfile -t images < <(docker images -q "industrial-ci/rerun_ci/*")
exec docker image inspect --format '{{index .RepoTags 0}} - {{.Comment}}' "${images[@]}" 2> /dev/null
mapfile -t images < <(docker images -q "industrial-ci/rerun_ci/*")
exec docker image inspect --format '{{index .RepoTags 0}} - {{.Comment}}' "${images[@]}" 2>/dev/null
;;
"--rm")
remove=true
shift
remove=true
shift
;;
"--clean")
clean=true
shift
clean=true
shift
;;
"-h" | "--help" | "")
show_help
exit 0
show_help
exit 0
;;
esac

if [ ! -d "$1" ]; then
show_help
exit 1
show_help
exit 1
fi

repo_dir=$(cd "$1" && pwd)
shift

DOCKER_COMMIT_MSG="$repo_dir $*"
env_hash=$(sha256sum <<< "$DOCKER_COMMIT_MSG")
env_hash=$(sha256sum <<<"$DOCKER_COMMIT_MSG")
DOCKER_COMMIT="industrial-ci/rerun_ci/$(basename "$repo_dir"):${env_hash:0:12}"

if [ "$remove" ]; then
exec docker rmi "$DOCKER_COMMIT"
exec docker rmi "$DOCKER_COMMIT"
elif [ "$clean" ]; then
docker rmi "$DOCKER_COMMIT"
docker rmi "$DOCKER_COMMIT"
fi


force_env=("DOCKER_COMMIT=$DOCKER_COMMIT" "DOCKER_COMMIT_MSG=$DOCKER_COMMIT_MSG")
keep_env=("DOCKER_PORT=$DOCKER_PORT" "HOME=$HOME" "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" "TERM=$TERM")

if docker image inspect "$DOCKER_COMMIT" &> /dev/null; then
force_env+=("DOCKER_IMAGE=$DOCKER_COMMIT" "DOCKER_PULL=false")
if docker image inspect "$DOCKER_COMMIT" &>/dev/null; then
force_env+=("DOCKER_IMAGE=$DOCKER_COMMIT" "DOCKER_PULL=false")
fi

env -i "${keep_env[@]}" "$script_dir/run_ci" "$repo_dir" DOCKER_COMMIT_CREDENTIALS=false "$@" "${force_env[@]}" || ret=$?
Expand Down
7 changes: 5 additions & 2 deletions industrial_ci/scripts/run_ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [ -n "$1" ] && [[ ! "$1" =~ "=" ]]; then
if [ -d "$1" ]; then
Expand All @@ -39,7 +39,10 @@ if [ -f "$script_dir/../src/ci_main.sh" ]; then # devel space
elif [ -f "$script_dir/../../share/industrial_ci/src/ci_main.sh" ]; then # install space
ci_dir="$script_dir/../../share/industrial_ci/"
else
ci_dir=$(python2 -c "import rospkg; print rospkg.RosPack().get_path('industrial_ci')" 2>/dev/null) || { echo "could not find ci_main.sh"; exit 1; }
ci_dir=$(python2 -c "import rospkg; print rospkg.RosPack().get_path('industrial_ci')" 2>/dev/null) || {
echo "could not find ci_main.sh"
exit 1
}
fi

env "$@" /bin/bash "$ci_dir/src/ci_main.sh"
Expand Down
18 changes: 12 additions & 6 deletions industrial_ci/src/builders/catkin_make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ function builder_setup {
}

function builder_run_build {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local opts=()
_append_job_opts opts PARALLEL_BUILDS 0
ici_exec_in_workspace "$extend" "$ws" catkin_make --make-args install "${opts[@]}" "$@"
}

function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local opts=()
_append_job_opts opts PARALLEL_TESTS 1
ici_exec_in_workspace "$extend" "$ws" catkin_make --make-args run_tests "${opts[@]}" "$@"
}

function builder_test_results {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
19 changes: 12 additions & 7 deletions industrial_ci/src/builders/catkin_make_isolated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ function _append_job_opts() {
fi
}

function _run_catkin_make_isolated () {
local target=$1; shift
local extend=$1; shift
local ws=$1; shift
ici_exec_in_workspace "$extend" "$ws" catkin_make_isolated --build-space "$ws/build" --install-space "$ws/install" --make-args "$target" "$@"
function _run_catkin_make_isolated() {
local target=$1
shift
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_make_isolated --build-space "$ws/build" --install-space "$ws/install" --make-args "$target" "$@"
}

function builder_setup {
Expand All @@ -48,7 +51,9 @@ function builder_run_tests {
}

function builder_test_results {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
30 changes: 18 additions & 12 deletions industrial_ci/src/builders/catkin_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,43 @@ function _append_job_opts() {
}

function builder_setup {
ici_install_pkgs_for_command catkin "${PYTHON_VERSION_NAME}-catkin-tools" "ros-$ROS_DISTRO-catkin"
ici_install_pkgs_for_command catkin "${PYTHON_VERSION_NAME}-catkin-tools" "ros-$ROS_DISTRO-catkin"
}

function builder_run_build {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local opts=()
if [ "${VERBOSE_OUTPUT:-false}" != false ]; then
opts+=("-vi")
fi
_append_job_opts opts PARALLEL_BUILDS 0
ici_exec_in_workspace "$extend" "$ws" catkin config --install
ici_exec_in_workspace "$extend" "$ws" catkin build "${opts[@]}" --summarize --no-status "$@"
ici_exec_in_workspace "$extend" "$ws" catkin build "${opts[@]}" --summarize --no-status "$@"
}

function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local opts=()
if [ "${VERBOSE_TESTS:-false}" != false ]; then
opts+=(-v)
fi
if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then
opts+=(-i)
opts+=(-v)
fi
if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then
opts+=(-i)
fi
_append_job_opts opts PARALLEL_TESTS 1
ici_exec_in_workspace "$extend" "$ws" catkin build --catkin-make-args run_tests -- "${opts[@]}" --no-status
}

function builder_test_results {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
20 changes: 13 additions & 7 deletions industrial_ci/src/builders/colcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ function builder_setup {
}

function builder_run_build {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local opts=(--event-handlers "${_colcon_event_handlers[@]}")
local jobs
ici_parse_jobs jobs PARALLEL_BUILDS 0
Expand All @@ -40,8 +42,10 @@ function builder_run_build {
}

function builder_run_tests {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
local output_handler
if [ "$IMMEDIATE_TEST_OUTPUT" == true ]; then
output_handler="console_direct+"
Expand All @@ -56,11 +60,13 @@ function builder_run_tests {
elif [ "$jobs" -gt 1 ]; then
opts+=(--executor parallel --parallel-workers "$jobs")
fi
ici_exec_in_workspace "$extend" "$ws" colcon test "${opts[@]}"
ici_exec_in_workspace "$extend" "$ws" colcon test "${opts[@]}"
}

function builder_test_results {
local extend=$1; shift
local ws=$1; shift
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" colcon test-result --verbose
}
Loading

0 comments on commit c524df6

Please sign in to comment.