From 4bc91dc4da0c4231a7acae5b8e9b1d97e9305d32 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Fri, 21 Nov 2025 21:04:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(pre-commit):=20=E6=AF=8F=E6=AC=A1=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E4=BB=A3=E7=A0=81=E6=88=96=E5=88=9B=E5=BB=BA=20PR=20?= =?UTF-8?q?=E6=97=B6=E9=83=BD=E4=BC=9A=E8=87=AA=E5=8A=A8=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=20pre-commit=20=E6=A3=80=E6=9F=A5=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pre-commit.yml | 36 ++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 25 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7396f34 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,36 @@ +name: Pre-commit Checks + +on: + pull_request: + branches: [master, main] + push: + branches: [master, main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + cache: 'pip' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pre-commit + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Run pre-commit hooks + run: | + pre-commit run --all-files --show-diff-on-failure + + - name: Cache pre-commit hooks + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4d3730c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +default_install_hook_types: [pre-commit, prepare-commit-msg] +ci: + autofix_commit_msg: ":sparkles: auto fixes by pre-commit hooks" + autofix_prs: true + autoupdate_branch: master + autoupdate_schedule: weekly + autoupdate_commit_msg: ":sparkles: pre-commit autoupdate" +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.14.1 + hooks: + # Run the linter. + - id: ruff-check + types_or: [ python, pyi ] + args: [ --fix ] + # Run the formatter. + - id: ruff-format + types_or: [ python, pyi ] + +- repo: https://github.com/asottile/pyupgrade + rev: v3.21.0 + hooks: + - id: pyupgrade + args: [--py310-plus]