ci: add pre-commit and CI lint workflow (#9)

We introduce pre-commit hook with clang-format to
enforce a unified code style across the project,
reducing style discussions and speeding up cod
reviews.

ref: https://pre-commit.com/
This commit is contained in:
takuya kodama 2025-05-19 11:25:56 +08:00 committed by GitHub
parent d6cc80c17e
commit c9fbd8aada
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 0 deletions

2
.clang-format Normal file
View File

@ -0,0 +1,2 @@
---
BasedOnStyle: Google

31
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: Lint
on:
push:
branches:
- '**'
- '!dependabot/**'
tags:
- '**'
pull_request:
concurrency:
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true
permissions:
contents: read
jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: |
python -m pip install pre-commit
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: pre-commit-
- name: Run
run: |
pre-commit run --show-diff-on-failure --color=always --all-files

5
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,5 @@
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v20.1.4"
hooks:
- id: clang-format