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

Format code with shfmt #598

Draft
wants to merge 4 commits 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
4 changes: 2 additions & 2 deletions .github/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
# 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##*/}
export _FOLDING_TYPE=github_actions

if [ -n "$INPUT_CONFIG" ]; then
vars=$(jq -r 'keys[] as $k | "export \($k)=\(.[$k]|tojson)" | gsub("\\$\\$";"\\$")' <<< "$INPUT_CONFIG" | grep "^export [A-Z][A-Z_]*=")
vars=$(jq -r 'keys[] as $k | "export \($k)=\(.[$k]|tojson)" | gsub("\\$\\$";"\\$")' <<<"$INPUT_CONFIG" | grep "^export [A-Z][A-Z_]*=")
echo "$vars"
eval "$vars"
fi
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
- uses: docker://koalaman/shellcheck-alpine
with:
args: /bin/sh -c "shellcheck -x *.sh industrial_ci/scripts/*_ci industrial_ci/src/*.sh industrial_ci/src/*/*.sh"
shfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: docker://mvdan/shfmt
with:
args: -d -i 4 .
- run: "! grep -rEo 'function +[a-zA-Z_]+ +\\{' *"
industrial_ci:
strategy:
matrix:
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"
37 changes: 18 additions & 19 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'
function show_help() {
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" "$@" "${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
26 changes: 16 additions & 10 deletions industrial_ci/src/builders/catkin_make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,34 @@ function _append_job_opts() {
fi
}

function builder_setup {
function builder_setup() {
ici_install_pkgs_for_command catkin_make "ros-${ROS_DISTRO}-catkin"
}

function builder_run_build {
local extend=$1; shift
local ws=$1; shift
function builder_run_build() {
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
function builder_run_tests() {
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
function builder_test_results() {
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
27 changes: 16 additions & 11 deletions industrial_ci/src/builders/catkin_make_isolated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,36 @@ 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 {
function builder_setup() {
ici_install_pkgs_for_command catkin_make_isolated "ros-${ROS_DISTRO}-catkin"
}

function builder_run_build {
function builder_run_build() {
local opts=()
_append_job_opts opts PARALLEL_BUILDS 0
_run_catkin_make_isolated install "${opts[@]}" "$@"
}

function builder_run_tests {
function builder_run_tests() {
local opts=()
_append_job_opts opts PARALLEL_TESTS 1
_run_catkin_make_isolated run_tests "$1" "$2" "${opts[@]}"
}

function builder_test_results {
local extend=$1; shift
local ws=$1; shift
function builder_test_results() {
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
38 changes: 22 additions & 16 deletions industrial_ci/src/builders/catkin_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,44 @@ function _append_job_opts() {
fi
}

function builder_setup {
ici_install_pkgs_for_command catkin "${PYTHON_VERSION_NAME}-catkin-tools" "ros-$ROS_DISTRO-catkin"
function builder_setup() {
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
function builder_run_build() {
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
function builder_run_tests() {
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
function builder_test_results() {
local extend=$1
shift
local ws=$1
shift
ici_exec_in_workspace "$extend" "$ws" catkin_test_results --verbose
}
Loading