Skip to content

Commit 4948243

Browse files
committed
ci: add pre-commit hooks and GitHub Actions workflow
- Add .pre-commit-config.yaml with ruff and pre-commit-hooks - Add CONTRIBUTING.md with coding style guidelines - Add GitHub Actions workflow for automatic pre-commit checks on PR and push
1 parent b069220 commit 4948243

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

.github/workflows/pre-commit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
jobs:
9+
pre-commit:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: '3.10'
16+
- name: Install pre-commit
17+
run: pip install pre-commit
18+
- name: Run pre-commit
19+
run: pre-commit run --all-files

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Follow https://verdantfox.com/blog/how-to-use-git-pre-commit-hooks-the-hard-way-and-the-easy-way
2+
repos:
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.11.0
5+
hooks:
6+
- id: ruff
7+
args: [--fix, --respect-gitignore, --config=pyproject.toml]
8+
- id: ruff-format
9+
args: [--config=pyproject.toml]
10+
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v4.5.0
13+
hooks:
14+
- id: trailing-whitespace
15+
- id: end-of-file-fixer
16+
- id: check-yaml
17+
- id: check-toml
18+
- id: check-added-large-files
19+
args: ['--maxkb=3000'] # Allow files up to 3MB
20+
- id: check-case-conflict
21+
- id: check-merge-conflict
22+
- id: debug-statements

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Contributing Guidelines
2+
3+
### Coding Style Guide
4+
5+
In general, we adhere to [Google Python style guide](https://google.github.io/styleguide/pyguide.html), and we recommend to use `yapf` to format your code.
6+
7+
In this project, we adopted `pre-commit` to automatic check the code style.
8+
9+
To begin with, you should follow the step below to install `pre-commit`.
10+
11+
```bash
12+
pip install pre-commit
13+
```
14+
15+
Then, you should config the pre-commit hook as below.
16+
17+
```bash
18+
pre-commit install
19+
```
20+
21+
Then when you commit your change, your code will be automatically checked.

0 commit comments

Comments
 (0)