Skip to content

Commit 00d91c1

Browse files
CI fixes (#23)
* Add makefile, update pre-commit hooks * Update * Refactor CI, disable json formatter * Set default shell for CI * feat: Makefile extended with testing and linting * feat: CMake linter and formatter added fix: CMakeLists.txt codestyle fixed * fix: added dependencies in Makefile fix: added check for failure in CI steps * fix: minor codestyle * fix: added to log tests expicitly * fix: .PHONY added to Makefile * feat: added extended colcon test output to console * feat: makefile simplified, sanitizer flags fixed feat: CI pipeline uses Makefile * Update dockerfile, bump action versions, minor fixes * Fix bash shell, replace first step with make cmd * fix: TODOS deleted * feat: added yamllint config fix: parallel clang-tidy tool added * feat: replaced * fix: root access for apt-get granted * fix: root access granted for pip * Minor fixes * fix: fixed YAML codestyle * fix: deleted redundant tags in docker-compose.yaml --------- Co-authored-by: Bakin Denis <denis.bakin5@gmail.com>
1 parent 4aa347c commit 00d91c1

File tree

17 files changed

+256
-168
lines changed

17 files changed

+256
-168
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,69 @@ name: Test
22

33
on:
44
pull_request:
5-
branches: [ "master" ]
6-
types: [ opened, reopened, ready_for_review, synchronize ]
7-
5+
branches: [master]
86
push:
9-
branches: [ "master" ]
7+
branches: [master]
108

11-
workflow_dispatch:
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
1212

1313
jobs:
14+
pre-commit:
15+
name: Run pre-commit hooks
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-python@v5
20+
with: { python-version: "3.10" }
21+
- uses: pre-commit/action@v3.0.1
22+
1423
extract-image:
15-
name: Extraction of configs
24+
name: Get image version
1625
runs-on: ubuntu-latest
1726
outputs:
1827
image-url: ${{ steps.extractor.outputs.image_url }}
1928
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-python@v5
31+
with: { python-version: "3.10" }
32+
33+
- name: Install dependencies
34+
run: |
35+
sudo pip install yq
36+
sudo apt-get install -y jq
2237
2338
- name: Extract image URL
2439
id: extractor
2540
run: |
26-
IMAGE_URL=$(grep -o 'image:\s*[^ ]*' docker-compose.yaml | cut -d ' ' -f2)
27-
echo "image_url=$IMAGE_URL" >> $GITHUB_OUTPUT
28-
echo $IMAGE_URL
41+
IMAGE_URL=$(cat docker-compose.yaml | yq ".services.${{ github.event.repository.name }}.image")
42+
echo "image_url=$IMAGE_URL" | tee -a $GITHUB_OUTPUT
2943
3044
build-and-check:
31-
name: Building, testing, linting
45+
name: Build, test, lint
3246
needs: extract-image
3347
runs-on: self-hosted
34-
concurrency:
35-
group: build-and-check-${{ github.ref }}
36-
cancel-in-progress: true
37-
env:
38-
CMAKE_ARGS: "-DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_TOOLS_ADDRESS_SANITIZER=1"
39-
4048
container:
41-
image: ${{ needs.extract-image.outputs.image-url}}
49+
image: ${{ needs.extract-image.outputs.image-url }}
50+
defaults:
51+
run: { shell: bash }
4252

4353
steps:
44-
- name: Checkout code
45-
uses: actions/checkout@v3
54+
- uses: actions/checkout@v4
4655

4756
- name: Build ROS2 packages
48-
shell: bash
4957
run: |
50-
source $ROS_ROOT/setup.bash
51-
cd $GITHUB_WORKSPACE/packages
52-
colcon build --merge-install --cmake-args $CMAKE_ARGS
58+
make build-all CMAKE_TOOLS_ADDRESS_SANITIZER="ON"
5359
source install/setup.bash
5460
5561
- name: Test ROS2 packages
5662
continue-on-error: true
57-
shell: bash
58-
run: |
59-
cd $GITHUB_WORKSPACE/packages
60-
colcon test --ctest-args tests --merge-install --executor parallel --parallel-workers $(nproc) --return-code-on-test-failure
63+
run: make test-all
6164

6265
- name: Run Clang-Tidy
63-
shell: bash
64-
run: |
65-
FILES=$(find . \( -name '*.h' -or -name '*.cpp' -or -name '*.cc' \) -not -path '*/build/*' -not -path '*/install/*' -not -path '*/log/*')
66-
echo "Files to be linted:"
67-
echo "$FILES"
68-
for FILE in $FILES; do
69-
echo $FILE
70-
clang-tidy --fix -p=packages/build $FILE
71-
done
66+
run: make lint-all
7267

73-
code-style:
74-
name: Formatting
75-
needs: extract-image
76-
runs-on: self-hosted
77-
concurrency:
78-
group: code-style-${{ github.ref }}
79-
cancel-in-progress: true
80-
81-
container:
82-
image: ${{ needs.extract-image.outputs.image-url}}
83-
84-
steps:
85-
- name: Checkout repository
86-
uses: actions/checkout@v3
87-
88-
# temporary solution until pre-commit is not installed in the container
89-
- name: Launching pre-commit
90-
shell: bash
91-
run: |
92-
pip3 install pre-commit
93-
pre-commit run --color=always --all-files
68+
- name: Check previous steps
69+
if: ${{ failure() }}
70+
run: exit 1

.pre-commit-config.yaml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@ repos:
44
rev: v4.5.0
55
hooks:
66
- id: check-added-large-files
7-
args: [--maxkb=512, --enforce-all]
87
- id: check-merge-conflict
98
- id: check-xml
9+
- id: check-json
1010
- id: check-yaml
11+
- id: check-toml
1112
- id: end-of-file-fixer
1213
- id: mixed-line-ending
1314
- id: trailing-whitespace
1415

16+
# YAML linter
17+
- repo: https://github.com/adrienverge/yamllint.git
18+
rev: v1.35.1
19+
hooks:
20+
- id: yamllint
21+
exclude: ^.clang-tidy$
22+
# TODO: Discuss yamllint settings (e.g. line-length)
23+
args: [--strict, -d, ".yamllint-config.yaml"]
24+
25+
# CMake linter and formatter
26+
- repo: https://github.com/cheshirekow/cmake-format-precommit
27+
rev: v0.6.10
28+
hooks:
29+
- id: cmake-format
30+
- id: cmake-lint
1531

1632
# Python linters & formatters
1733
- repo: https://github.com/astral-sh/ruff-pre-commit
1834
rev: v0.1.3
1935
hooks:
2036
- id: ruff
21-
args: [--show-fixes]
37+
args: [--fix, --show-fixes]
2238
- id: ruff-format
23-
args: ["--target-version=py38", "--respect-gitignore",
24-
"--exclude=build", "--exclude=log", "--exclude=install"]
2539

26-
# C++ linters & formatters
27-
- repo: https://github.com/pocc/pre-commit-hooks
28-
rev: 336fdd7
40+
# C++ formatter
41+
- repo: https://github.com/pre-commit/mirrors-clang-format
42+
rev: v17.0.6
2943
hooks:
3044
- id: clang-format
31-
args: [-i, -style=file]
45+
types: [c, c++]

.yamllint-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
rules:
2+
line-length:
3+
max: 120
4+
5+
quoted-strings:
6+
quote-type: double
7+
required: false
8+
9+
braces:
10+
min-spaces-inside: 1
11+
max-spaces-inside: 1
12+
min-spaces-inside-empty: 0
13+
max-spaces-inside-empty: 0
14+
15+
brackets:
16+
min-spaces-inside-empty: 0
17+
max-spaces-inside-empty: 0

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ RUN mkdir -p ${ROS_ROOT} \
293293
vision_opencv \
294294
visualization_msgs \
295295
> ${ROS_ROOT}/ros2.rosinstall \
296-
&& vcs import ${ROS_TMP} < ${ROS_ROOT}/ros2.rosinstall > /dev/null
296+
&& vcs import ${ROS_TMP} < ${ROS_ROOT}/ros2.rosinstall
297297

298298
RUN apt-get update -q \
299299
&& rosdep init \
@@ -353,3 +353,7 @@ RUN printf "export CC='${CC}'\n" >> ${HOME}/.bashrc \
353353
&& printf "export RCUTILS_LOGGING_BUFFERED_STREAM=1\n" >> ${HOME}/.bashrc \
354354
&& printf "export RCUTILS_CONSOLE_OUTPUT_FORMAT='[{severity}:{time}] {message}'\n" >> ${HOME}/.bashrc \
355355
&& ln -sf /usr/bin/clang-format-${CLANG_VERSION} /usr/bin/clang-format
356+
357+
WORKDIR /handy
358+
ENTRYPOINT ["/bin/bash", "-l", "-c"]
359+
CMD ["trap : TERM INT; sleep infinity & wait"]

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.SILENT:
2+
.ONESHELL:
3+
# https://stackoverflow.com/questions/2131213#comment133331794_60363121
4+
.RECIPEPREFIX := $(.RECIPEPREFIX) $(.RECIPEPREFIX)
5+
6+
SHELL = /bin/bash
7+
CMAKE_BUILD_TYPE ?= Release
8+
CMAKE_TOOLS_ADDRESS_SANITIZER ?= OFF
9+
CXXFLAGS := \
10+
${CXXFLAGS} \
11+
$(shell if [ "$${CMAKE_TOOLS_ADDRESS_SANITIZER^^}" = "ON" ]; then echo "-fsanitize=address"; fi)
12+
CMAKE_ARGS ?= \
13+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
14+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
15+
-DCMAKE_CXX_FLAGS="${CXXFLAGS}"
16+
17+
FILES_TO_LINT := $(shell find . \( -name "*.h" -or -name "*.cpp" -or -name "*.cc" \) \
18+
-not -path "*/build/*" -not -path "*/install/*" -not -path "*/log/*")
19+
20+
.PHONY: all
21+
all:
22+
$(error Please use explicit targets)
23+
24+
.PHONY: build-all
25+
build-all:
26+
source ${ROS_ROOT}/setup.sh
27+
colcon --log-base /dev/null build \
28+
--base-paths packages \
29+
--symlink-install \
30+
--cmake-args ${CMAKE_ARGS}
31+
32+
.PHONY: test-all
33+
test-all:
34+
colcon --log-base /dev/null test \
35+
--ctest-args tests --symlink-install \
36+
--executor parallel --parallel-workers $$(nproc) \
37+
--event-handlers console_cohesion+
38+
39+
.PHONY: build
40+
# packages="first_pkg second_pkg third_pkg..."
41+
build:
42+
source ${ROS_ROOT}/setup.sh
43+
colcon --log-base /dev/null build \
44+
--base-paths packages \
45+
--symlink-install \
46+
--cmake-args ${CMAKE_ARGS} \
47+
--packages-up-to $(packages)
48+
49+
.PHONY: test
50+
# packages="first_pkg second_pkg third_pkg..."
51+
test:
52+
colcon --log-base /dev/null test --ctest-args tests --symlink-install \
53+
--executor parallel --parallel-workers $$(nproc) \
54+
--event-handlers console_cohesion+ --packages-select $(packages)
55+
56+
.PHONY: lint-all
57+
# args="-fix ..."
58+
lint-all:
59+
run-clang-tidy -p=build $(args) $(FILES_TO_LINT)
60+
61+
.PHONY: lint
62+
# args="-fix ..."
63+
# files="first_file second_file third_file..."
64+
lint:
65+
run-clang-tidy -p=build $(args) $(files)
66+
67+
.PHONY: clean
68+
clean:
69+
rm -rf build install

docker-compose.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
version: "3.9"
21
services:
32
handy:
3+
image: "registry.robotics-lab.ru/handy:0.7.2"
44
container_name: "${CONTAINER_NAME:-handy-${USER}}"
5-
image: registry.robotics-lab.ru/handy:0.7.0
5+
networks: [default]
66
privileged: true
7-
stdin_open: true
8-
runtime: ${DOCKER_RUNTIME:-runc}
9-
entrypoint: "/bin/bash -c 'trap : TERM INT; sleep infinity & wait'"
10-
working_dir: "/handy"
11-
build:
12-
dockerfile: Dockerfile
13-
context: .
14-
tags:
15-
- "registry.robotics-lab.ru/handy:latest"
16-
- "registry.robotics-lab.ru/handy:0.7.0"
17-
x-bake:
18-
platforms: [linux/arm64, linux/amd64]
19-
cache-to: "type=registry,ref=registry.robotics-lab.ru/handy:cache,mode=max"
20-
cache-from: "type=registry,ref=registry.robotics-lab.ru/handy:cache"
21-
networks:
22-
- default
237
ports:
248
- "${FOXGLOVE_PORT:-8765}:8765"
259
volumes:
2610
- "${PWD}:/handy"
2711
- "/dev:/dev"
12+
13+
build:
14+
dockerfile: Dockerfile
15+
context: .
16+
x-bake:
17+
platforms:
18+
- linux/arm64
19+
- linux/amd64
20+
cache-from:
21+
- type=registry,ref=registry.robotics-lab.ru/handy:cache-arm64
22+
- type=registry,ref=registry.robotics-lab.ru/handy:cache-amd64
23+
cache-to:
24+
# [!!!] Warning: https://github.com/docker/buildx/discussions/1382
25+
# - type=registry,mode=max,ref=registry.robotics-lab.ru/handy:cache-arm64
26+
# - type=registry,mode=max,ref=registry.robotics-lab.ru/handy:cache-amd64
27+
2828
networks:
2929
default:
3030
name: "${CONTAINER_NAME:-handy-${USER}}"

0 commit comments

Comments
 (0)