Skip to content
Merged
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
96 changes: 81 additions & 15 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: CI - ROS2 Simulation

on:
pull_request:
Expand All @@ -8,24 +8,90 @@ on:
branches: [main, develop]

jobs:
ros-tests:
ros2-simulation-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout Repository
uses: actions/checkout@v3

- name: Prepare files for Docker build
- name: Set up Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose

- name: Cleanup Docker
run: |
docker container prune -f
docker volume prune -f

- name: Build and Start Simulation
working-directory: docker
run: |
set -e
chmod +x docker_start.sh
./docker_start.sh | tee docker_start_output.log

- name: Show Docker Compose Status and Logs
working-directory: docker
run: |
docker compose ps
docker compose logs --tail=50 auto_shepherd_simulation_ros2_humble

- name: Print Docker Container Logs if Not Running
if: ${{ failure() || !steps.build-and-start-simulation.outcome == 'success' }}
run: |
echo "Container logs:"
docker logs auto_shepherd_simulation_ros2_humble || echo "No logs found."
echo "Docker ps output:"
docker ps -a

- name: Smoke Test Container
run: |
docker exec auto_shepherd_simulation_ros2_humble bash -c "source /opt/ros/humble/setup.bash && ros2 --help"


- name: Build ROS2 Workspace
run: |
mkdir -p docker_build/src
cp ros2_package/auto_shepherd_simulation/ros_interface.py docker_build/src/ros_interface.py
cp -r tests docker_build/tests
cp tests/Dockerfile.test docker_build/Dockerfile
docker exec auto_shepherd_simulation_ros2_humble bash -c \
"source /opt/ros/humble/setup.bash && \
cd /home/ros/base_ws && \
colcon build --symlink-install"

- name: Build ROS Test Container
- name: List ROS2 Topics
run: |
cd docker_build
docker build -t ros_test .
docker exec auto_shepherd_simulation_ros2_humble bash -c \
"source /opt/ros/humble/setup.bash && \
source /home/ros/base_ws/install/setup.bash && \
ros2 topic list"

- name: Wait for and Echo /dbscan_hulls
run: |
docker exec auto_shepherd_simulation_ros2_humble bash -c "
set -e
source /opt/ros/humble/setup.bash
source /home/ros/bash_scripts/bashrc_extensions.sh

github_action_initialise_tmule

for attempt in {1..3}; do
echo \"Attempt \$attempt to trigger and read /dbscan_hulls\"

github_action_initialise_dog
github_action_initialise_goal

echo \"Checking topic list and /dbscan_hulls info\"
ros2 topic list
ros2 topic info /dbscan_hulls -v || echo 'No info for /dbscan_hulls yet'

echo \"Waiting up to 60s for a MarkerArray message on /dbscan_hulls...\"
if timeout 60s ros2 topic echo /dbscan_hulls visualization_msgs/msg/MarkerArray --no-arr --once; then
echo \"Successfully received /dbscan_hulls on attempt \$attempt\"
exit 0
else
echo \"No message received on /dbscan_hulls (attempt \$attempt)\"
fi

sleep 5
done

- name: Run ROS Tests
run: docker run ros_test
echo \"❌ Failed to receive /dbscan_hulls after 3 attempts\"
exit 1
"
89 changes: 89 additions & 0 deletions bash_scripts/container/bashrc_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,92 @@ function con(){ tmule -c $CONNECTED $1 ; }
# TMuLe for injecting data to inputs
export INJECTED=${BASE_WS}/src/auto_shepherd_simulation_ros2/tmule/injected.tmule.yaml
function inj(){ tmule -c $INJECTED $1 ; }


################################
## Aliases for github actions ##
################################

function github_action_initialise_tmule() { tmule -c $INJECTED launch ; }

function github_action_initialise_goal()
{
ros2 topic pub /goal_pose geometry_msgs/msg/PoseStamped "header:
stamp:
sec: 1752234451
nanosec: 558437227
frame_id: field_frame
pose:
position:
x: -15.754144668579102
y: 44.95618438720703
z: 0.0
orientation:
x: 0.0
y: 0.0
z: -0.0721578213596985
w: 0.9973932267749877
" --once ;
}

function github_action_initialise_dog()
{
ros2 topic pub /initialpose geometry_msgs/msg/PoseWithCovarianceStamped "header:
stamp:
sec: 1752234463
nanosec: 6465847
frame_id: field_frame
pose:
pose:
position:
x: -19.47688865661621
y: 8.73109245300293
z: 0.0
orientation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
covariance:
- 0.25
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.25
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.0
- 0.06853891909122467
" --once ;
}




1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ RUN apt-get update && \

# 5. Python pip installs
RUN python3 -m pip install --no-cache-dir --upgrade \
--ignore-installed \
pip wheel \
setuptools==58.2.0 \
packaging==24.2 \
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
auto_shepherd_simulation_ros2_humble:
container_name: auto_shepherd_simulation_ros2_humble # <- included for .git action identification
build:
context: .
dockerfile: Dockerfile
Expand Down
31 changes: 22 additions & 9 deletions docker/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
COMPOSE_FILE="docker-compose.yml"
SERVICE_NAME="auto_shepherd_simulation_ros2_humble"

xhost +local:docker
command -v xhost >/dev/null && xhost +local:docker
#xhost +local:docker

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
HOST_DISPLAY_VAR="$DISPLAY"
Expand All @@ -29,12 +30,24 @@ echo "Docker Compose cleanup completed."
# --- Run the Docker Compose service interactively ---
echo "Starting Docker Compose service '${SERVICE_NAME}' in interactive mode..."

docker compose -f "${COMPOSE_FILE}" run \
-v "$HOME/.Xauthority:/root/.Xauthority:rw" \
-e "HOST_DISPLAY_VAR=${HOST_DISPLAY_VAR}" \
-e QT_X11_NO_MITSHM=1 \
"${DOCKER_RUN_ARGS[@]}" \
"${SERVICE_NAME}" \
bash

docker compose -f "${COMPOSE_FILE}" up -d "${SERVICE_NAME}"
#docker compose -f "${COMPOSE_FILE}" run \
# -v "$HOME/.Xauthority:/root/.Xauthority:rw" \
# -e "HOST_DISPLAY_VAR=${HOST_DISPLAY_VAR}" \
# -e QT_X11_NO_MITSHM=1 \
# "${DOCKER_RUN_ARGS[@]}" \
# "${SERVICE_NAME}" \
# bash

# Check if the container started successfully
docker ps --filter "name=${SERVICE_NAME}" --filter "status=running" | grep ${SERVICE_NAME} > /dev/null
if [ $? -ne 0 ]; then
echo "Container failed to start!"
docker ps -a
docker logs auto_shepherd_simulation_ros2_humble || echo "No logs found for container."
exit 1
fi
echo "Container started successfully."
docker ps -a
docker logs auto_shepherd_simulation_ros2_humble || echo "No logs found for container."
echo "Docker container session ended."