From d3723fa4af68ac450cb8aeb59086d06f3a2e4f32 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 25 Oct 2025 15:09:39 -0700 Subject: [PATCH 01/12] Update test_node.cpp --- src/test_node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_node.cpp b/src/test_node.cpp index 0b6a6fe..4bb128b 100644 --- a/src/test_node.cpp +++ b/src/test_node.cpp @@ -1,6 +1,6 @@ #include -// hi +// hi 2 int main(int argc, char ** argv) { (void)argc; From a8e34185df707caac7894a5631725fc19f14853f Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 12:58:05 -0800 Subject: [PATCH 02/12] more tests add linters and formatters --- .gitignore | 6 +++++- .vscode/settings.json | 8 +++++++- CMakeLists.txt | 28 ++++++++++++++-------------- README.md | 7 +++++-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index eacbeaf..696d757 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,8 @@ # ROS specific build/ install/ -log/ \ No newline at end of file +log/ + +# other +.vscode/ +.venv/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 8e0ba0f..ae04379 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,9 @@ { - "ros.distro": "jazzy" + "ros.distro": "jazzy", + "python.autoComplete.extraPaths": [ + "/opt/ros/jazzy/lib/python3.12/site-packages" + ], + "python.analysis.extraPaths": [ + "/opt/ros/jazzy/lib/python3.12/site-packages" + ] } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e74dc16..0d7576c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,6 @@ endif() # find dependencies find_package(ament_cmake REQUIRED) -# uncomment the following section in order to fill in -# further dependencies manually. -# find_package( REQUIRED) # Add executable add_executable(test_node src/test_node.cpp) @@ -20,16 +17,20 @@ install(TARGETS DESTINATION lib/${PROJECT_NAME}) if(BUILD_TESTING) - # find_package(ament_lint_auto REQUIRED) - # the following line skips the linter which checks for copyrights - # comment the line when a copyright and license is added to all source files - # set(ament_cmake_copyright_FOUND TRUE) - # the following line skips cpplint (only works in a git repo) - # comment the line when this package is in a git repo and when - # a copyright and license is added to all source files - # set(ament_cmake_cpplint_FOUND TRUE) - # ament_lint_auto_find_test_dependencies() - + # Manually specify only the linters we want to use + find_package(ament_cmake_cppcheck REQUIRED) + find_package(ament_cmake_lint_cmake REQUIRED) + find_package(ament_cmake_flake8 REQUIRED) + find_package(ament_cmake_pep257 REQUIRED) + find_package(ament_cmake_uncrustify REQUIRED) + find_package(ament_cmake_xmllint REQUIRED) + + ament_cppcheck() + ament_lint_cmake() + ament_flake8() + ament_pep257() + ament_uncrustify() + ament_xmllint() # simple gtest find_package(ament_cmake_gtest REQUIRED) @@ -38,7 +39,6 @@ if(BUILD_TESTING) $ $ ) - # target_link_libraries(${PROJECT_NAME}_tutorial_test name_of_local_library) endif() ament_package() diff --git a/README.md b/README.md index cd77c68..037af01 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ https://www.blacksmith.sh/blog/cache-is-king-a-guide-for-docker-layer-caching-in If I want to cache python deps: https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching - What I'm using: https://github.com/marketplace/actions/ros-2-ci-action To share the workflow across other repos: -https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows \ No newline at end of file +https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows + +Commands +colcon test +colcon test-result --verbose --all \ No newline at end of file From 01167ddbc02539379fddf47d0267dfe20bf93cac Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:36:08 -0800 Subject: [PATCH 03/12] test in workflow --- .github/workflows/main.yml | 12 ++++++++---- CMakeLists.txt | 7 ------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea8d9db..f8bbdde 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,8 +9,12 @@ jobs: container: image: rostooling/setup-ros-docker:ubuntu-jammy-ros-humble-ros-base-latest steps: - - name: Build and run tests - uses: ros-tooling/action-ros-ci@v0.4 + - name: Build package + uses: ros-tooling/setup-ros@v0.7 with: - package-name: build_test - target-ros2-distro: humble + required-ros-distributions: humble + - name: Run tests + run: | + source /opt/ros/humble/setup.bash + colcon test + colcon test-result --verbose --all diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d7576c..5a1ea82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,13 +32,6 @@ if(BUILD_TESTING) ament_uncrustify() ament_xmllint() - # simple gtest - find_package(ament_cmake_gtest REQUIRED) - ament_add_gtest(${PROJECT_NAME}_tutorial_test test/tutorial_test.cpp) - target_include_directories(${PROJECT_NAME}_tutorial_test PUBLIC - $ - $ - ) endif() ament_package() From 78c11681f3473a5413d0b0f858d7f516672308fb Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 13:59:37 -0800 Subject: [PATCH 04/12] cppcheck --- .github/workflows/main.yml | 29 ++++++++++++++++------------- README.md | 16 +++++++++++++++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f8bbdde..6d7201d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,20 +1,23 @@ -name: ROS2 CI (Humble) +name: Lint and Format on: pull_request: branches: [ main ] jobs: - build_and_test_ros2: - runs-on: ubuntu-22.04 - container: - image: rostooling/setup-ros-docker:ubuntu-jammy-ros-humble-ros-base-latest + lint: + name: cppcheck-test + runs-on: ubuntu-latest steps: - - name: Build package - uses: ros-tooling/setup-ros@v0.7 + - uses: actions/checkout@v2 + + - name: cppcheck + uses: deep5050/cppcheck-action@main with: - required-ros-distributions: humble - - name: Run tests - run: | - source /opt/ros/humble/setup.bash - colcon test - colcon test-result --verbose --all + github_token: ${{ secrets.GITHUB_TOKEN}} + + + - name: publish report + uses: mikeal/publish-to-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH_NAME: 'main' # your branch name goes here \ No newline at end of file diff --git a/README.md b/README.md index 037af01..4e6de8e 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,18 @@ https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows Commands colcon test -colcon test-result --verbose --all \ No newline at end of file +colcon test-result --verbose --all + +find_package(ament_cmake_cppcheck REQUIRED) +find_package(ament_cmake_lint_cmake REQUIRED) +find_package(ament_cmake_flake8 REQUIRED) +find_package(ament_cmake_pep257 REQUIRED) +find_package(ament_cmake_uncrustify REQUIRED) +find_package(ament_cmake_xmllint REQUIRED) + +ament_cppcheck() +ament_lint_cmake() +ament_flake8() +ament_pep257() +ament_uncrustify() +ament_xmllint() \ No newline at end of file From 9b206130e43069c4d974d1c0f72e3b99578196d7 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:02:50 -0800 Subject: [PATCH 05/12] does this matter --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d7201d..bf0a32a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: - name: cppcheck uses: deep5050/cppcheck-action@main with: - github_token: ${{ secrets.GITHUB_TOKEN}} + github_token: ${{ secrets.GITHUB_TOKEN }} - name: publish report From 12e1d492253428ca2fd9acae69cc05a58b05471c Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:05:31 -0800 Subject: [PATCH 06/12] test default --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf0a32a..bfb9541 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,10 @@ -name: Lint and Format +name: cppcheck-action-test on: pull_request: branches: [ main ] jobs: - lint: + build: name: cppcheck-test runs-on: ubuntu-latest steps: From 18e6ffc3c199acd12f7f0f836a817eb743359972 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:18:05 -0800 Subject: [PATCH 07/12] uncrustify test --- .github/workflows/main.yml | 21 ++++++--------------- README.md | 10 +++++++++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bfb9541..0f9ed5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,20 +4,11 @@ on: branches: [ main ] jobs: - build: - name: cppcheck-test + cpp_style_check: runs-on: ubuntu-latest + name: Check C++ Style steps: - - uses: actions/checkout@v2 - - - name: cppcheck - uses: deep5050/cppcheck-action@main - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - - - - name: publish report - uses: mikeal/publish-to-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BRANCH_NAME: 'main' # your branch name goes here \ No newline at end of file + - name: Checkout this commit + uses: actions/checkout@v4 + - name: Run style checks + uses: coleaeason/actions-uncrustify@v1 \ No newline at end of file diff --git a/README.md b/README.md index 4e6de8e..3ef8258 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,12 @@ ament_lint_cmake() ament_flake8() ament_pep257() ament_uncrustify() -ament_xmllint() \ No newline at end of file +ament_xmllint() + + +The issue: +I need to run colcon build in order to run colcon test, which makes it hard to test submodules individually. + +If I separate and directly use linters or formatters, they might not have the same configs as what ROS will use. Not too huge an issue + +Just make sure colcon build works I guess \ No newline at end of file From fead25fb377d9db5015d835aba45f56715c938a7 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:24:13 -0800 Subject: [PATCH 08/12] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0f9ed5a..687f289 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,6 @@ jobs: name: Check C++ Style steps: - name: Checkout this commit - uses: actions/checkout@v4 + uses: actions/checkout@v2 - name: Run style checks uses: coleaeason/actions-uncrustify@v1 \ No newline at end of file From b7d35e701ed32bc2b06e636a3205185989db6985 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 15 Nov 2025 12:55:55 -0800 Subject: [PATCH 09/12] Update main.yml --- .github/workflows/main.yml | 44 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 687f289..c5ad069 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,14 +1,42 @@ -name: cppcheck-action-test +name: ROS2 CI (Humble) on: pull_request: branches: [ main ] jobs: - cpp_style_check: - runs-on: ubuntu-latest - name: Check C++ Style + build_and_test_ros2: + runs-on: ubuntu-22.04 + container: + image: ros:humble-ros-base + steps: - - name: Checkout this commit - uses: actions/checkout@v2 - - name: Run style checks - uses: coleaeason/actions-uncrustify@v1 \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install rosdep dependencies + run: | + # Update rosdep + apt-get update + rosdep update + + # Install dependencies from all packages in src/ + rosdep install --from-paths src --ignore-src -r -y + + - name: Build with colcon + run: | + # Source ROS2 environment + source /opt/ros/humble/setup.bash + + # Build the workspace + colcon build --symlink-install + + - name: Run tests + run: | + # Source ROS2 and workspace environment + source /opt/ros/humble/setup.bash + source install/setup.bash + + # Make sure build works + colcon build \ No newline at end of file From 08af09d8c2ad26449ef6ebfb378d5c97a0584c70 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 15 Nov 2025 12:58:11 -0800 Subject: [PATCH 10/12] Update main.yml --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c5ad069..923f6fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,7 @@ jobs: rosdep install --from-paths src --ignore-src -r -y - name: Build with colcon + shell: bash run: | # Source ROS2 environment source /opt/ros/humble/setup.bash @@ -33,6 +34,7 @@ jobs: colcon build --symlink-install - name: Run tests + shell: bash run: | # Source ROS2 and workspace environment source /opt/ros/humble/setup.bash From af05b98fb38730477bb710b90b8cfb5527d40330 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 15 Nov 2025 13:02:18 -0800 Subject: [PATCH 11/12] venv --- .github/workflows/main.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 923f6fe..bb53996 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,6 +15,21 @@ jobs: with: submodules: recursive + - name: Set up Python virtual environment + shell: bash + run: | + # Install python3-venv if not available + apt-get update + apt-get install -y python3-venv python3-pip + + # Create virtual environment + python3 -m venv .venv + + # Activate and install dependencies + source .venv/bin/activate + pip install --upgrade pip + pip install -r requirements/requirements.txt + - name: Install rosdep dependencies run: | # Update rosdep @@ -27,7 +42,8 @@ jobs: - name: Build with colcon shell: bash run: | - # Source ROS2 environment + # Activate venv and source ROS2 environment + source .venv/bin/activate source /opt/ros/humble/setup.bash # Build the workspace @@ -36,9 +52,10 @@ jobs: - name: Run tests shell: bash run: | - # Source ROS2 and workspace environment + # Activate venv and source ROS2 and workspace environment + source .venv/bin/activate source /opt/ros/humble/setup.bash source install/setup.bash # Make sure build works - colcon build \ No newline at end of file + colcon build --packages-select utils aiming_node ballistics_node classical_cv \ No newline at end of file From c229ef8dc035707c462c7bce6afcb60b37ddb150 Mon Sep 17 00:00:00 2001 From: Kane Li <122249106+Li-Kane@users.noreply.github.com> Date: Sat, 15 Nov 2025 13:02:52 -0800 Subject: [PATCH 12/12] Create requirements.txt --- requirements/requirements.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 requirements/requirements.txt diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..469c334 --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1,9 @@ +# colcon build deps +catkin_pkg +empy==3.3.4 +lark +catkin-pkg +PyYAML +setuptools +jinja2 +typeguard \ No newline at end of file