Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
104 changes: 54 additions & 50 deletions .github/workflows/lint_build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Lint, Build & Test
on:
push:
branches:
- master
- master
pull_request:
branches:
- master
- master
defaults:
run:
shell: bash
Expand All @@ -15,53 +15,57 @@ jobs:
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup
run: |
sudo apt-get update && sudo apt-get install -y black libxml2-utils
- name: Lint package.xml
run: |
xmllint --noout --schema http://download.ros.org/schema/package_format3.xsd $(find . -name 'package.xml')
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Lint Python code with black
run: |
echo "Linting Python code..."
black --check . --diff
- name: Setup
run: |
sudo apt-get update && sudo apt-get install -y black clang-format cppcheck libxml2-utils

# Uncomment once tests have been added
# build-and-test:
# needs: Linting
# strategy:
# matrix:
# setup:
# - rosdistro: jazzy
# os: ubuntu-24.04
# - rosdistro: rolling
# os: ubuntu-latest
# runs-on: ${{ matrix.setup.os }}
# container:
# image: ros:${{ matrix.setup.rosdistro }}-ros-base
# steps:
# - name: install build tools
# run: |
# sudo apt-get update
# sudo apt-get install -y ros-dev-tools
# - uses: actions/checkout@v4
# with:
# path: src/repo
# - name: rosdep
# run: |
# rosdep update --rosdistro ${{ matrix.setup.rosdistro }} --include-eol-distros
# rosdep install -y --from-paths src --ignore-src --rosdistro ${{ matrix.setup.rosdistro }}
# - name: build
# run: |
# source /opt/ros/${{ matrix.setup.rosdistro }}/setup.bash
# colcon build
# - name: test
# run: |
# source /opt/ros/${{ matrix.setup.rosdistro }}/setup.bash
# colcon test
# colcon test-result --verbose
- name: Set up Python
uses: actions/setup-python@v4

- name: Install and Run pre-commit
uses: pre-commit/[email protected]
with:
extra_args: --all-files
Comment on lines +30 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you running the pre-commit hooks in the CI?
That would mask any formatting issues that were committed.


build-and-test:
needs: Linting
strategy:
matrix:
setup:
- rosdistro: jazzy
os: ubuntu-24.04
- rosdistro: rolling
os: ubuntu-latest
runs-on: ${{ matrix.setup.os }}
container:
image: ros:${{ matrix.setup.rosdistro }}-ros-base
steps:
- name: install build tools
run: |
sudo apt-get update
sudo apt-get install -y ros-dev-tools
- uses: actions/checkout@v4
with:
repository: tu-darmstadt-ros-pkg/hector_ros2_utils
path: src/hector_ros2_utils
- uses: actions/checkout@v4
with:
path: src/repo
- name: rosdep
run: |
rosdep update --rosdistro ${{ matrix.setup.rosdistro }} --include-eol-distros
rosdep install -y --from-paths src --ignore-src --rosdistro ${{ matrix.setup.rosdistro }}
- name: build
run: |
source /opt/ros/${{ matrix.setup.rosdistro }}/setup.bash
colcon build
- name: test
run: |
source /opt/ros/${{ matrix.setup.rosdistro }}/setup.bash
colcon test
colcon test-result --verbose
91 changes: 86 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,88 @@
# To use:
#
# pre-commit run -a
#
# Or:
#
# pre-commit install # (runs every time you commit in git)
#
# To update this file:
#
# pre-commit autoupdate
#
# See https://github.com/pre-commit/pre-commit

repos:
- repo: https://github.com/psf/black
rev: 24.2.0
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: black
name: Black
language_version: python3
- id: check-added-large-files
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-xml
- id: check-yaml
args: ["--allow-multiple-documents"]
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
exclude_types: [rst]

# CPP Checks
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v20.1.4
hooks:
- id: clang-format
name: Clang Format
args: [--style=file]
files: \.(cpp|hpp|h|c|cc)$

- repo: local
hooks:
- id: cppcheck
name: Cppcheck
entry: bash -c "cppcheck --force --quiet --inline-suppr --error-exitcode=1 --language=c++ $(find . -type d -name 'cmake-build-*' -prune -false -o -name '*.cpp' -o -name '*.hpp' -o -name '*.h' -o -name '*.c' -o -name '*.cc')"
language: system
files: \.(cpp|cc|hpp|h)$
pass_filenames: false
Comment on lines +33 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no and probably never will be any CPP in this repo.


# Python hooks
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.7
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format

# CMake Formatting
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- id: cmake-lint

# Package XML
- repo: https://github.com/Joschi3/package_xml_validation.git
rev: v1.2.3
hooks:
- id: format-package-xml
name: Validate and Format package.xml

# Spellcheck
- repo: https://github.com/crate-ci/typos
rev: v1.34.0
hooks:
- id: typos

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.33.2
hooks:
- id: check-github-workflows
args: ["--verbose"]
- id: check-github-actions
args: ["--verbose"]
- id: check-gitlab-ci
args: ["--verbose"]
- id: check-compose-spec
args: ["--verbose"]
7 changes: 7 additions & 0 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
action="store_true",
help="Clean CMake cache before building.",
)
ament_cmake_args_arg = parser.add_argument(
"--ament-cmake-args",
default=None,
nargs="+",
help="Additional arguments to pass to ament_cmake. Such as VAR=VALUE.",
)
parser.add_argument(
"--verbose",
"-v",
Expand Down Expand Up @@ -107,6 +113,7 @@
build_tests=args.build_tests,
verbose=args.verbose,
cmake_clean_cache=args.cmake_clean_cache,
ament_cmake_args=args.ament_cmake_args,
)
)
except KeyboardInterrupt:
Expand Down
5 changes: 5 additions & 0 deletions tuda_workspace_scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def build_packages(
build_base: str = "build",
install_base: str = "install",
cmake_clean_cache: bool = False,
ament_cmake_args: list[str] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, your default value is violating the type annotation.
This is also wrong for the mixin arg, though.

) -> int:
os.chdir(workspace_root)
packages = packages or []
Expand All @@ -53,6 +54,10 @@ def build_packages(
arguments += ["--cmake-args"] + list(
map(lambda x: f"' {shlex.quote(x)}'", cmake_arguments)
)
if ament_cmake_args:
arguments += ["--ament-cmake-args"] + list(
map(lambda x: f"{"-D" + x}", ament_cmake_args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be other arguments than -DVAR=VALUE, or is that the only argument allowed to be passed to ament cmake?
And it's a bit weird to use a format string and then just concatenate the string in an expression.
Should be f"-D{x}"

)
if mixin and len(mixin) > 0:
arguments += ["--mixin"] + mixin

Expand Down
Loading