You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -128,6 +129,37 @@ Unlike the tools above (which analyze code without running it), sanitizers are s
128
129
129
130
While configuring them is beyond the scope of this module, it's crucial to know they exist. They are the ultimate tools for finding those bugs that only appear randomly. They can be enabled in the colcon build by passing compiler flags.
130
131
132
+
## Pre-commit hooks
133
+
134
+
After exploring the main tools that ensure code quality in ROS 2, let’s look at a lightweight way to integrate them seamlessly into everyday development: **pre-commit hooks**.
135
+
136
+
[Pre-commit](https://pre-commit.com) hooks are a **local, optional step** that run before a Git commit is finalized. Their main goal is to provide **immediate feedback** and automatically correct simple issues such as code formatting or basic linting on the **staged files only**. This keeps the commit history clean and avoids unnecessary “fix formatting” commits, while also speeding up the remote CI process.
137
+
138
+
Typical hooks include formatters like `clang-format`, linters such as `clang-tidy`, and scripts that check file headers or trailing whitespace. These checks are intentionally fast so they don’t interrupt development flow.
139
+
140
+
Developers can still bypass the hooks when needed by running `git commit --no-verify`.
141
+
142
+
To enable pre-commit in a repository:
143
+
144
+
1. Add a `.pre-commit-config.yaml` listing the desired hooks.
145
+
2. Run once to install:
146
+
147
+
```bash
148
+
pip install pre-commit
149
+
pre-commit install
150
+
```
151
+
152
+
3. Each `git commit` will now automatically trigger the configured checks. To run all hooks manually:
153
+
154
+
```bash
155
+
pre-commit run --all-files
156
+
```
157
+
158
+
Pre-commit hooks are best suited for **fast, local hygiene checks**. They complement full workspace analyses done by `colcon test` and `ament_lint_auto`, which can also be run locally or in CI (introduced in Module 6).
159
+
160
+
> [!NOTE]
161
+
> This workshop does not use pre-commit for static analysis or linters, since those checks are demonstrated through `ament_lint_auto` and `colcon test`.
162
+
131
163
## Other Useful Tools
132
164
133
165
### Colcon lint
@@ -221,6 +253,7 @@ The task is complete when the command `colcon lint --packages-select module_1` i
Copy file name to clipboardExpand all lines: modules/module_6/README.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,11 @@ Integrating CI into the workflow is essential because it:
48
48
49
49
For projects hosted on GitHub, the easiest and most popular way to implement CI is with **GitHub Actions**.
50
50
51
+
> [!TIP]
52
+
> **Use Pre-commit Hooks to Optimize Your Workflow**
53
+
>
54
+
> While **CI is the mandatory quality gate** for merging, it's often faster for developers to catch simple style errors **locally** before they push. Tools like **pre-commit hooks** (as discussed in Module 1) run fast checks like formatting locally, saving the developer time waiting for the CI pipeline to run just to fail on a style inconsistency. They complement the CI by ensuring your commits are clean and focused on functional changes.
55
+
51
56
### Introduction to GitHub Actions
52
57
53
58
GitHub Actions is a CI/CD platform built directly into GitHub. Automation workflows are defined in a **YAML file** in a special directory in the repository: `.github/workflows/`. GitHub automatically detects these files and runs them based on a set of custom-defined rules or triggers, such as when code is pushed, a pull request is opened, or a scheduled job is due.
0 commit comments