diff --git a/.devcontainer/setup-env.sh b/.devcontainer/setup-env.sh index 2543286..42f8f8f 100755 --- a/.devcontainer/setup-env.sh +++ b/.devcontainer/setup-env.sh @@ -14,8 +14,10 @@ elif [ -n "$BASH_VERSION" ]; then source ~/.bashrc 2>/dev/null || true fi -# Initialize rosdep -sudo rosdep init +# Initialize rosdep if not already initialized +if [ ! -f /etc/ros/rosdep/sources.list.d/20-default.list ]; then + sudo rosdep init +fi rosdep update # Test installations diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3bd6201 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + pull_request: + branches: [main] + +jobs: + build-and-test: + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up ROS 2 Jazzy + uses: ros-tooling/setup-ros@v0.7 + with: + required-ros-distributions: jazzy + + - name: Install dependencies + run: | + sudo apt-get update + rosdep update + rosdep install --from-paths src --ignore-src -r -y + + - name: Build packages + run: | + source /opt/ros/jazzy/setup.bash + colcon build --symlink-install --cmake-args -DCMAKE_BUILD_TYPE=Release + + - name: Run tests + run: | + source /opt/ros/jazzy/setup.bash + source install/setup.bash + colcon test --return-code-on-test-failure + + - name: Show test results + if: always() + run: | + colcon test-result --verbose diff --git a/README.md b/README.md index f19edee..5dee1db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ros2_diag_tree +[![CI](https://github.com/bburda/ros2_diag_tree/actions/workflows/ci.yml/badge.svg)](https://github.com/bburda/ros2_diag_tree/actions/workflows/ci.yml) + Modern, SOVD-compatible diagnostics for ROS 2 robots, built around an entity tree (Area / Component / Function / App) for runtime discovery, health modeling, and troubleshooting. @@ -31,6 +33,32 @@ so the same concepts can be used across robots, vehicles, and other embedded sys - Health state modeled per Area / Component / Function / App - Better remote troubleshooting and fleet-level observability for ROS 2 robots +## Development + +### Installing Dependencies + +```bash +rosdep install --from-paths src --ignore-src -r -y +``` + +### Building + +```bash +colcon build --symlink-install +``` + +### Testing + +```bash +colcon test +colcon test-result --verbose +``` + +### CI/CD + +All pull requests are automatically built and tested using GitHub Actions. +The CI workflow runs on Ubuntu 24.04 with ROS 2 Jazzy. + ## Contributing Contributions and early feedback are welcome! Please read [`CONTRIBUTING.md`](CONTRIBUTING.md) for guidelines. diff --git a/src/ros2_diag_tree_gateway/CMakeLists.txt b/src/ros2_diag_tree_gateway/CMakeLists.txt index 01cc60c..e96f50f 100644 --- a/src/ros2_diag_tree_gateway/CMakeLists.txt +++ b/src/ros2_diag_tree_gateway/CMakeLists.txt @@ -8,30 +8,16 @@ endif() # Find dependencies find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) +find_package(nlohmann_json REQUIRED) -# Add dependencies via FetchContent -include(FetchContent) - -# httplib -fetchcontent_declare( - httplib - GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git - GIT_TAG v0.14.3 -) - -# nlohmann/json -fetchcontent_declare( - json - GIT_REPOSITORY https://github.com/nlohmann/json.git - GIT_TAG v3.11.3 -) - -fetchcontent_makeavailable(httplib json) +# Find cpp-httplib using pkg-config +find_package(PkgConfig REQUIRED) +pkg_check_modules(cpp_httplib REQUIRED IMPORTED_TARGET cpp-httplib) # Gateway node executable add_executable(gateway_node src/gateway_node.cpp) ament_target_dependencies(gateway_node rclcpp) -target_link_libraries(gateway_node httplib::httplib nlohmann_json::nlohmann_json) +target_link_libraries(gateway_node PkgConfig::cpp_httplib nlohmann_json::nlohmann_json) target_include_directories(gateway_node PUBLIC $ $) @@ -44,14 +30,14 @@ install(TARGETS gateway_node if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # Exclude uncrustify since we use clang-format - set(ament_cmake_uncrustify_FOUND TRUE) + list(APPEND AMENT_LINT_AUTO_EXCLUDE ament_cmake_uncrustify) ament_lint_auto_find_test_dependencies() # Add GTest find_package(ament_cmake_gtest REQUIRED) ament_add_gtest(test_gateway_node test/test_gateway_node.cpp) - target_link_libraries(test_gateway_node httplib::httplib nlohmann_json::nlohmann_json) + target_link_libraries(test_gateway_node PkgConfig::cpp_httplib nlohmann_json::nlohmann_json) ament_target_dependencies(test_gateway_node rclcpp) endif() diff --git a/src/ros2_diag_tree_gateway/package.xml b/src/ros2_diag_tree_gateway/package.xml index 5044b5b..7415f42 100644 --- a/src/ros2_diag_tree_gateway/package.xml +++ b/src/ros2_diag_tree_gateway/package.xml @@ -11,6 +11,8 @@ ament_cmake rclcpp + nlohmann-json-dev + libcpp-httplib-dev ament_lint_auto ament_lint_common diff --git a/src/ros2_diag_tree_gateway/src/gateway_node.cpp b/src/ros2_diag_tree_gateway/src/gateway_node.cpp index 4f0f410..76bdafe 100644 --- a/src/ros2_diag_tree_gateway/src/gateway_node.cpp +++ b/src/ros2_diag_tree_gateway/src/gateway_node.cpp @@ -16,7 +16,7 @@ #include #include -#include // NOLINT(build/include_order) +#include // NOLINT(build/include_order) #include #include @@ -62,7 +62,7 @@ class GatewayNode : public rclcpp::Node { // Health endpoint http_server_->Get( "/health", [this](const httplib::Request &req, httplib::Response &res) { - (void)req; // Unused parameter + (void)req; // Unused parameter nlohmann::json health_json = {{"status", "ok"}, {"node", node_name_}, @@ -75,7 +75,7 @@ class GatewayNode : public rclcpp::Node { // Root endpoint http_server_->Get( "/", [this](const httplib::Request &req, httplib::Response &res) { - (void)req; // Unused parameter + (void)req; // Unused parameter nlohmann::json info_json = { {"service", "ros2_diag_tree_gateway"}, diff --git a/src/ros2_diag_tree_gateway/test/test_gateway_node.cpp b/src/ros2_diag_tree_gateway/test/test_gateway_node.cpp index b22c4ae..bee429e 100644 --- a/src/ros2_diag_tree_gateway/test/test_gateway_node.cpp +++ b/src/ros2_diag_tree_gateway/test/test_gateway_node.cpp @@ -18,7 +18,7 @@ #include #include -#include // NOLINT(build/include_order) +#include // NOLINT(build/include_order) #include #include