Skip to content

Commit 9928e97

Browse files
chore: add pre-commit, CI checks, and trivy scanning
1 parent d63d337 commit 9928e97

4 files changed

Lines changed: 117 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
rust-checks:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Rust
20+
uses: dtolnay/rust-toolchain@stable
21+
22+
- name: Format check
23+
run: cargo fmt --all -- --check
24+
25+
- name: Tests
26+
run: cargo test --all-targets

.github/workflows/trivy.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Trivy Scan
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
- cron: "21 4 * * 1"
10+
11+
permissions:
12+
contents: read
13+
security-events: write
14+
15+
jobs:
16+
trivy:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Run Trivy filesystem scan
23+
uses: aquasecurity/trivy-action@0.28.0
24+
with:
25+
scan-type: fs
26+
scan-ref: .
27+
scanners: vuln,misconfig,secret
28+
severity: HIGH,CRITICAL
29+
ignore-unfixed: true
30+
exit-code: "1"
31+
format: table

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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-toml
9+
- id: check-merge-conflict
10+
11+
- repo: https://github.com/gitleaks/gitleaks
12+
rev: v8.24.2
13+
hooks:
14+
- id: gitleaks
15+
args: ["protect", "--staged", "--verbose"]
16+
17+
- repo: local
18+
hooks:
19+
- id: cargo-fmt-check
20+
name: cargo fmt --check
21+
entry: cargo fmt --all -- --check
22+
language: system
23+
pass_filenames: false
24+
types_or: [rust]
25+
26+
- id: cargo-test
27+
name: cargo test
28+
entry: cargo test -q
29+
language: system
30+
pass_filenames: false
31+
stages: [pre-push]
32+
33+
- id: trivy-fs-high-critical
34+
name: trivy fs (HIGH/CRITICAL)
35+
entry: trivy fs --scanners vuln,misconfig,secret --severity HIGH,CRITICAL --exit-code 1 --no-progress .
36+
language: system
37+
pass_filenames: false
38+
stages: [pre-push]

CONTRIBUTING.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Thanks for contributing.
99
- Rust stable toolchain
1010
- Git
1111
- `bd` (beads) for issue tracking
12+
- `pre-commit`
13+
- `gitleaks`
14+
- `trivy`
1215

1316
## Getting Started
1417

@@ -70,13 +73,29 @@ cargo test
7073

7174
- If behavior changes, update docs in the same PR (`README.md`, `AGENTS.md`, this file, or `SECURITY.md` when relevant).
7275

73-
## Secret Scanning
76+
## Pre-commit Hooks
7477

75-
- CI runs `gitleaks` on pushes and pull requests.
76-
- Before opening a PR, run a local scan if `gitleaks` is installed:
78+
Install and enable hooks:
79+
80+
```bash
81+
pre-commit install
82+
pre-commit install --hook-type pre-push
83+
```
84+
85+
Run all hooks manually:
86+
87+
```bash
88+
pre-commit run --all-files
89+
```
90+
91+
## Security Scanning
92+
93+
- CI runs `gitleaks` and `trivy` on pushes and pull requests.
94+
- Before opening a PR, run local scans:
7795

7896
```bash
7997
gitleaks git --no-banner
98+
trivy fs --scanners vuln,misconfig,secret --severity HIGH,CRITICAL --exit-code 1 --no-progress .
8099
```
81100

82101
## Commit Guidelines

0 commit comments

Comments
 (0)