diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 57144bc..a2b6da1 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -124,6 +124,7 @@ jobs: - osrf_ros - upstream_ros - workspace_overlay + - shells steps: - uses: actions/checkout@v6 diff --git a/features/src/ros2/install.sh b/features/src/ros2/install.sh index 2350740..424e808 100755 --- a/features/src/ros2/install.sh +++ b/features/src/ros2/install.sh @@ -164,16 +164,26 @@ chmod 0644 /etc/profile.d/ros2.sh remote_user="${_REMOTE_USER:-${_CONTAINER_USER:-}}" remote_user_home="${_REMOTE_USER_HOME:-${_CONTAINER_USER_HOME:-}}" +ros_profile_line='[ -f /etc/profile.d/ros2.sh ] && . /etc/profile.d/ros2.sh' + if [[ -n "${remote_user}" && -n "${remote_user_home}" && -d "${remote_user_home}" ]]; then - shell_init="${remote_user_home}/.bashrc" - touch "${shell_init}" - if ! grep -Fq '[ -f /etc/profile.d/ros2.sh ] && . /etc/profile.d/ros2.sh' "${shell_init}"; then - printf '\n%s\n' '[ -f /etc/profile.d/ros2.sh ] && . /etc/profile.d/ros2.sh' >> "${shell_init}" + shell_inits=("${remote_user_home}/.bashrc") + if command -v zsh >/dev/null 2>&1; then + shell_inits+=("${remote_user_home}/.zshrc") fi - if ! grep -Fq '[ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ] && . /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' "${shell_init}"; then - printf '%s\n' '[ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ] && . /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' >> "${shell_init}" + for shell_init in "${shell_inits[@]}"; do + touch "${shell_init}" + if ! grep -Fq "${ros_profile_line}" "${shell_init}"; then + printf '\n%s\n' "${ros_profile_line}" >> "${shell_init}" + fi + chown "${remote_user}:$(id -gn "${remote_user}")" "${shell_init}" + done + + bash_completion_line='[ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ] && . /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' + bash_init="${remote_user_home}/.bashrc" + if ! grep -Fq "${bash_completion_line}" "${bash_init}"; then + printf '%s\n' "${bash_completion_line}" >> "${bash_init}" fi - chown "${remote_user}:$(id -gn "${remote_user}")" "${shell_init}" else echo "No effective Dev Container user was provided; skipping user-specific shell configuration." fi diff --git a/features/test/ros2-idempotency/Dockerfile b/features/test/ros2-idempotency/Dockerfile index 4e9b158..9878e3a 100644 --- a/features/test/ros2-idempotency/Dockerfile +++ b/features/test/ros2-idempotency/Dockerfile @@ -15,4 +15,5 @@ RUN bash -lc 'test "${ROS_DISTRO}" = jazzy' \ && sudo -u vscode bash -ic 'complete -p colcon >/dev/null' \ && test -f /etc/ros/rosdep/sources.list.d/20-default.list \ && test "$(grep -Fc '[ -f /etc/profile.d/ros2.sh ] && . /etc/profile.d/ros2.sh' /home/vscode/.bashrc)" -eq 1 \ + && test "$(grep -Fc '[ -f /etc/profile.d/ros2.sh ] && . /etc/profile.d/ros2.sh' /home/vscode/.zshrc)" -eq 1 \ && test "$(grep -Fc '[ -f /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash ] && . /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash' /home/vscode/.bashrc)" -eq 1 diff --git a/features/test/ros2/scenarios.json b/features/test/ros2/scenarios.json index bf637be..db1dde5 100644 --- a/features/test/ros2/scenarios.json +++ b/features/test/ros2/scenarios.json @@ -36,5 +36,15 @@ "workspace_overlay": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", "features": { "ros2": { "package": "ros-base", "workspace": "/tmp/ros2_overlay" } } + }, + "shells": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04", + "features": { + "ros2": { + "distro": "jazzy", + "package": "ros-base", + "workspace": "/tmp/ros2_shell_overlay" + } + } } } diff --git a/features/test/ros2/shells.sh b/features/test/ros2/shells.sh new file mode 100755 index 0000000..62f1fca --- /dev/null +++ b/features/test/ros2/shells.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -e +source dev-container-features-test-lib + +mkdir -p /tmp/ros2_shell_overlay/install +printf '%s\n' 'export ROS2_SHELL_OVERLAY_TEST=loaded' > /tmp/ros2_shell_overlay/install/setup.sh + +check "Bash ROS CLI is available" bash -lc 'command -v ros2 >/dev/null' +check "Bash ROS distribution is available" bash -lc '[ "${ROS_DISTRO:-}" = "jazzy" ]' +check "Bash workspace overlay is sourced" bash -lc '[ "${ROS2_SHELL_OVERLAY_TEST:-}" = loaded ]' +check "Zsh ROS CLI is available" zsh -ic 'command -v ros2 >/dev/null' +check "Zsh ROS distribution is available" zsh -ic '[ "${ROS_DISTRO:-}" = "jazzy" ]' +check "Zsh workspace overlay is sourced" zsh -ic '[ "${ROS2_SHELL_OVERLAY_TEST:-}" = loaded ]' +check "Bash colcon completion is enabled" bash -ic 'complete -p colcon >/dev/null' + +reportResults