Skip to content

Commit ea59872

Browse files
committed
feat: add pre-commit with hadolint, shellcheck, and commitlint hooks
Install pre-commit in the container image and add .pre-commit-config.yaml with hooks for trailing whitespace, YAML validation, hadolint, shellcheck, and commitlint. https://claude.ai/code/session_01RofXXAMZxK4irobNYjYn3W
1 parent 8c2eb93 commit ea59872

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

.containerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ LICENSE
99
.releaserc.yaml
1010
.commitlintrc.yaml
1111
.containerignore
12+
.pre-commit-config.yaml
1213
scripts/

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-merge-conflict
10+
- id: detect-private-key
11+
12+
- repo: https://github.com/hadolint/hadolint
13+
rev: v2.12.0
14+
hooks:
15+
- id: hadolint-docker
16+
entry: hadolint/hadolint hadolint
17+
args: ["--config", ".hadolint.yaml"]
18+
19+
- repo: https://github.com/shellcheck-py/shellcheck-py
20+
rev: v0.10.0.1
21+
hooks:
22+
- id: shellcheck
23+
args: ["-e", "SC1091"]
24+
25+
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
26+
rev: v9.21.0
27+
hooks:
28+
- id: commitlint
29+
stages: [commit-msg]
30+
additional_dependencies: ["@commitlint/config-conventional"]

Containerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ RUN curl -sSL -o /tmp/pack.tgz \
9898
&& tar -xzf /tmp/pack.tgz -C /usr/local/bin/ \
9999
&& rm /tmp/pack.tgz
100100

101+
# Install pre-commit
102+
# hadolint ignore=DL3013
103+
RUN pip install --no-cache-dir pre-commit
104+
101105
# Install Poetry latest version and add it to PATH
102106
# hadolint ignore=DL4006
103107
RUN curl -sSL https://install.python-poetry.org | python3 -

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ These tools allow the image to run its own build pipeline as a self-hosted runne
3636
| [trivy](https://github.com/aquasecurity/trivy) | Vulnerability scanner |
3737
| [hadolint](https://github.com/hadolint/hadolint) | Dockerfile/Containerfile linter |
3838
| [yq](https://github.com/mikefarah/yq) | YAML processor |
39+
| [pre-commit](https://pre-commit.com/) | Git hooks framework |
3940

4041
## CI/CD
4142

@@ -127,9 +128,37 @@ Run the full build pipeline (lint, build, scan, push):
127128
./scripts/builder.sh
128129
```
129130

131+
### Pre-commit hooks
132+
133+
Install the git hooks locally:
134+
135+
```bash
136+
pre-commit install --hook-type pre-commit --hook-type commit-msg
137+
```
138+
139+
Hooks run automatically on every commit:
140+
141+
| Hook | Stage | Description |
142+
|------|-------|-------------|
143+
| trailing-whitespace | pre-commit | Remove trailing whitespace |
144+
| end-of-file-fixer | pre-commit | Ensure files end with a newline |
145+
| check-yaml | pre-commit | Validate YAML syntax |
146+
| check-added-large-files | pre-commit | Prevent large files from being committed |
147+
| check-merge-conflict | pre-commit | Detect merge conflict markers |
148+
| detect-private-key | pre-commit | Prevent private keys from being committed |
149+
| hadolint | pre-commit | Lint Containerfile |
150+
| shellcheck | pre-commit | Lint shell scripts |
151+
| commitlint | commit-msg | Validate conventional commit messages |
152+
153+
Run all hooks manually against all files:
154+
155+
```bash
156+
pre-commit run --all-files
157+
```
158+
130159
### Contributing
131160

132-
This project uses [Conventional Commits](https://www.conventionalcommits.org/). Commit messages are validated by commitlint on pull requests.
161+
This project uses [Conventional Commits](https://www.conventionalcommits.org/). Commit messages are validated by commitlint on pull requests and locally via pre-commit hooks.
133162

134163
```bash
135164
# Good
@@ -151,6 +180,7 @@ git commit -m "WIP"
151180
├── .releaserc.yaml # Semantic release configuration
152181
├── .hadolint.yaml # Hadolint configuration
153182
├── .commitlintrc.yaml # Commitlint configuration
183+
├── .pre-commit-config.yaml # Pre-commit hooks configuration
154184
├── .containerignore # Build context exclusions
155185
├── .dive-ci # Dive efficiency thresholds
156186
├── .github/

0 commit comments

Comments
 (0)