Skip to content

Commit 75f59a5

Browse files
committed
setup pre-commit checks
1 parent 9c5720f commit 75f59a5

File tree

16 files changed

+119
-27
lines changed

16 files changed

+119
-27
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.4.2
1+
8.4.2

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BasedOnStyle: Google
2+
IndentWidth: 2
3+
ColumnLimit: 100

.github/workflows/ci.yml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,75 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
test:
11-
name: Build & Test
10+
# --- JOB 1: LINTING (The Style Police) ---
11+
# This runs fast. If it fails, we don't bother building.
12+
lint:
13+
name: Lint & Format
1214
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install Poetry
25+
run: pip install poetry
26+
27+
- name: Add Export Plugin to Poetry
28+
run: poetry self add "poetry-plugin-export"
29+
30+
- name: Install pre-commit
31+
run: pip install pre-commit
32+
33+
# Runs all hooks defined in .pre-commit-config.yaml
34+
# Checks every file in the repo.
35+
- name: Run pre-commit
36+
run: pre-commit run --all-files
37+
38+
# --- JOB 2: BUILD & TEST ---
39+
test:
40+
name: Test (${{ matrix.os }})
41+
needs: lint # Wait for lint to pass
42+
runs-on: ${{ matrix.os }}
43+
44+
strategy:
45+
fail-fast: false # If Linux fails, let macOS finish so we see all errors
46+
matrix:
47+
os: [ubuntu-latest, macos-latest]
1348

1449
steps:
15-
# 1. Checkout
1650
- name: Checkout repo
1751
uses: actions/checkout@v4
1852

19-
# 2. Setup Python
20-
- name: Setup Python 3.11
53+
- name: Setup Python
2154
uses: actions/setup-python@v5
2255
with:
2356
python-version: '3.11'
2457

25-
# 3. Setup Bazel (The Modern Way)
26-
# This installs Bazelisk AND handles the build cache automatically.
2758
- name: Setup Bazel
2859
uses: bazel-contrib/[email protected]
2960
with:
30-
# Uses .bazelversion file automatically
3161
bazelisk-cache: true
3262
disk-cache: true
3363
repository-cache: true
3464

35-
# 4. Run Tests
36-
- name: Run Tests
65+
# 1. Standard Test Run
66+
# Runs all tests in standard mode.
67+
- name: Run All Tests (Standard)
3768
run: bazel test //... --test_output=errors
69+
70+
# 2. Memory Safety Run (AddressSanitizer) - Linux Only
71+
# Catches buffer overflows and memory leaks.
72+
- name: Run Tests with AddressSanitizer (ASan)
73+
if: runner.os == 'Linux'
74+
run: |
75+
bazel test //... \
76+
--test_output=errors \
77+
--copt=-fsanitize=address \
78+
--linkopt=-fsanitize=address \
79+
--copt=-g \
80+
--copt=-O1 \
81+
--copt=-fno-omit-frame-pointer

.idea/bazelVersionCache.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/material_theme_project_new.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/puava.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.pre-commit-config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# See https://pre-commit.com for more information
2+
# To update hooks: pre-commit autoupdate
3+
4+
repos:
5+
# --- 1. Generic File Fixes ---
6+
# These keep the repo clean and prevent silly merge conflicts.
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.6.0
9+
hooks:
10+
- id: check-yaml
11+
- id: check-toml
12+
- id: check-merge-conflict
13+
- id: end-of-file-fixer
14+
- id: trailing-whitespace
15+
- id: check-added-large-files
16+
17+
# --- 2. Python Linting & Formatting (Ruff) ---
18+
# This replaces Black, Isort, and Flake8 with a single, fast tool.
19+
- repo: https://github.com/astral-sh/ruff-pre-commit
20+
rev: v0.4.4
21+
hooks:
22+
- id: ruff
23+
args: [--fix]
24+
- id: ruff-format
25+
26+
# --- 3. C/C++ Formatting (Clang-Format) ---
27+
# This enforces the Google C Style Guide automatically.
28+
# It will format .c, .h, and .cc (test) files.
29+
- repo: https://github.com/pre-commit/mirrors-clang-format
30+
rev: v18.1.5
31+
hooks:
32+
- id: clang-format
33+
types_or: [c, c++]
34+
35+
# --- 4. The "Poetry Bridge" ---
36+
# This automatically updates requirements_lock.txt whenever poetry.lock changes.
37+
# Keeps Bazel in sync with Poetry.
38+
- repo: local
39+
hooks:
40+
- id: poetry-export
41+
name: poetry-export
42+
entry: poetry export --with dev --without-hashes --format=requirements.txt --output requirements_lock.txt
43+
language: system
44+
# Only runs if poetry.lock changes
45+
files: ^poetry\.lock$
46+
pass_filenames: false

0 commit comments

Comments
 (0)