Skip to content

Commit b1d3821

Browse files
authored
Merge pull request #7 from tu-darmstadt-ros-pkg/feature/improved_pre_commits
Feature/improved pre commits
2 parents 20714e0 + 93a3fd3 commit b1d3821

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

copier.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ ci_type:
214214
when: "{{ 'ci' in template }}"
215215

216216
add_pre_commit:
217-
help: Add pre-commit hooks?
218-
default: false
217+
help: Add pre-commit hooks? [Recommended]
218+
default: true
219219
type: bool
220220
when: "{{ 'ci' in template }}"
221221

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/mirrors-clang-format
3-
rev: v14.0.6
3+
rev: v20.1.4
44
hooks:
55
- id: clang-format
66
name: Clang Format
@@ -11,14 +11,37 @@ repos:
1111
hooks:
1212
- id: cppcheck
1313
name: Cppcheck
14-
entry: cppcheck --force --quiet --language=c++
14+
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')"
1515
language: system
16-
types: [c, c++]
17-
files: \.(cpp|hpp|h|c|cc)$
16+
files: \.(cpp|cc|hpp|h)$
17+
pass_filenames: false
1818

1919
- repo: https://github.com/psf/black
20-
rev: 24.2.0
20+
rev: 25.1.0
2121
hooks:
2222
- id: black
2323
name: Black
2424
language_version: python3
25+
26+
- repo: https://github.com/pre-commit/pre-commit-hooks
27+
rev: v5.0.0
28+
hooks:
29+
- id: trailing-whitespace
30+
- id: check-yaml
31+
- id: check-xml
32+
- id: check-merge-conflict
33+
34+
35+
- repo: https://github.com/cheshirekow/cmake-format-precommit
36+
rev: v0.6.13
37+
hooks:
38+
- id: cmake-format
39+
- id: cmake-lint
40+
41+
42+
- repo: https://github.com/Joschi3/package_xml_validation.git
43+
rev: v1.1.7
44+
hooks:
45+
- id: format-package-xml
46+
name: Validate and Format package.xml
47+

templates/ci/{% if ci_type == 'github' %}.github{% endif %}/workflows/lint_build_test.yaml.jinja

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,21 @@ jobs:
1919
uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
22+
2223
- name: Setup
2324
run: |
2425
sudo apt-get update && sudo apt-get install -y black clang-format cppcheck libxml2-utils
26+
27+
{% if add_pre_commit %}
28+
- name: Set up Python
29+
uses: actions/setup-python@v4
30+
31+
- name: Install and Run pre-commit
32+
uses: pre-commit/[email protected]
33+
with:
34+
extra_args: --all-files
35+
36+
{% else %}
2537
- name: Lint C++ code
2638
run: |
2739
echo "Linting C++ code..."
@@ -40,6 +52,8 @@ jobs:
4052
run: |
4153
echo "Linting Python code..."
4254
black --check .
55+
{% endif %}
56+
4357

4458

4559
build-and-test:
@@ -78,4 +92,4 @@ jobs:
7892
run: |
7993
source /opt/ros/{{ '${{ matrix.setup.rosdistro }}' }}/setup.bash
8094
colcon test
81-
colcon test-result --verbose
95+
colcon test-result --verbose

templates/ci/{% if ci_type == 'gitlab' %}.gitlab-ci.yml{% endif %}.jinja

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ variables:
77

88
linting:
99
stage: linting
10+
{% if add_pre_commit %}
11+
image: $CI_REGISTRY/hector/workspace/docker_workspace:dev-amd64
12+
rules:
13+
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
14+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH'
15+
before_script:
16+
- sudo apt-get update && sudo apt-get install -y clang-format cppcheck libxml2-utils black git pre-commit
17+
- git config --global --add safe.directory "$CI_PROJECT_DIR"
18+
- rosdep update --rosdistro ${ROS_DISTRO}
19+
script:
20+
- echo "Running pre-commit hooks..."
21+
- pre-commit run --all-files
22+
{% else %}
1023
image: ubuntu:latest
1124
rules:
1225
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
@@ -22,6 +35,8 @@ linting:
2235
- xmllint --noout --schema http://download.ros.org/schema/package_format3.xsd $(find . -name 'package.xml')
2336
- echo "Linting Python files..."
2437
- black --check .
38+
{% endif %}
39+
2540

2641
build-and-test:
2742
stage: build_and_test

0 commit comments

Comments
 (0)