feat: add pre-commit ci (#1824)

This commit is contained in:
yetone
2025-04-07 14:55:21 +08:00
committed by GitHub
parent 1e2e233ff5
commit f83378a67e
7 changed files with 46 additions and 83 deletions

View File

@@ -53,30 +53,6 @@ jobs:
nvim --version
make luatest
stylua:
name: Check Lua style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- name: Install stylua
uses: baptiste0928/cargo-install@v3
with:
crate: stylua
features: lua54
- run: stylua --version
- run: stylua --color always --check ./lua/ ./plugin/ ./tests/
luacheck:
name: Lint Lua
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- name: Luacheck linter
uses: lunarmodules/luacheck@cc089e3f65acdd1ef8716cc73a3eca24a6b845e4 # ratchet:lunarmodules/luacheck@v1
with:
args: ./lua/
typecheck:
name: Typecheck
runs-on: ubuntu-latest

38
.github/workflows/pre-commit.yaml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: pre-commit
on:
pull_request:
types: [labeled, opened, reopened, synchronize]
push:
branches: [main, test-me-*]
jobs:
pre-commit:
if: "github.event.action != 'labeled' || github.event.label.name == 'pre-commit ci run'"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: gh pr edit ${{ github.event.number }} --remove-label 'pre-commit ci run'
if: github.event.action == 'labeled' && github.event.label.name == 'pre-commit ci run'
env:
GH_TOKEN: ${{ github.token }}
- uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v5
- run: |
uv venv
source .venv/bin/activate
uv pip install -r py/rag-service/requirements.txt
- uses: leafo/gh-actions-lua@v11
- uses: leafo/gh-actions-luarocks@v5
- run: luarocks install luacheck
- name: Install stylua from crates.io
uses: baptiste0928/cargo-install@v3
with:
crate: stylua
args: --features lua54
- uses: pre-commit/action@v3.0.1
- uses: pre-commit-ci/lite-action@v1.1.0
if: always()

View File

@@ -1,31 +0,0 @@
name: Python
on:
push:
branches:
- main
paths:
- '**/*.py'
- '.github/workflows/python.yaml'
pull_request:
branches:
- main
paths:
- '**/*.py'
- '.github/workflows/python.yaml'
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: '3.11'
- run: |
python -m venv .venv
source .venv/bin/activate
pip install -r py/rag-service/requirements.txt
- uses: pre-commit/action@v3.0.1
with:
extra_args: --files $(find ./py -type f -name "*.py")

View File

@@ -29,27 +29,3 @@ jobs:
components: clippy, rustfmt
- name: Run rust tests
run: cargo test --features luajit
style:
name: Check Rust style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # ratchet:Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # ratchet:dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy, rustfmt
- name: Run rustfmt
run: make ruststylecheck
lint:
name: Lint Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # ratchet:Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # ratchet:dtolnay/rust-toolchain@master
with:
toolchain: "1.85.0"
components: clippy, rustfmt
- name: Run rustfmt
run: make rustlint

View File

@@ -12,6 +12,10 @@ repos:
hooks:
- id: stylua-system # or stylua-system / stylua-github
files: \.lua$
- repo: https://github.com/Calinou/pre-commit-luacheck
rev: v1.0.0
hooks:
- id: luacheck
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:

View File

@@ -13,8 +13,8 @@
<a href="https://github.com/yetone/avante.nvim/actions/workflows/rust.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/rust.yaml?style=flat-square&logo=rust&logoColor=ffffff&label=Rust+CI&labelColor=BC826A&color=347D39&event=push" alt="Rust CI status" />
</a>
<a href="https://github.com/yetone/avante.nvim/actions/workflows/python.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/python.yaml?style=flat-square&logo=python&logoColor=ffffff&label=Python+CI&labelColor=3672A5&color=347D39&event=push" alt="Python CI status" />
<a href="https://github.com/yetone/avante.nvim/actions/workflows/pre-commit.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/pre-commit.yaml?style=flat-square&logo=pre-commit&logoColor=ffffff&label=pre-commit&labelColor=FAAF3F&color=347D39&event=push" alt="pre-commit status" />
</a>
<a href="https://discord.gg/QfnEFEdSjz" target="_blank">
<img src="https://img.shields.io/discord/1302530866362323016?style=flat-square&logo=discord&label=Discord&logoColor=ffffff&labelColor=7376CF&color=268165" alt="Discord" />

View File

@@ -13,8 +13,8 @@
<a href="https://github.com/yetone/avante.nvim/actions/workflows/rust.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/rust.yaml?style=flat-square&logo=rust&logoColor=ffffff&label=Rust+CI&labelColor=BC826A&color=347D39&event=push" alt="Rust CI status" />
</a>
<a href="https://github.com/yetone/avante.nvim/actions/workflows/python.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/python.yaml?style=flat-square&logo=python&logoColor=ffffff&label=Python+CI&labelColor=3672A5&color=347D39&event=push" alt="Python CI status" />
<a href="https://github.com/yetone/avante.nvim/actions/workflows/pre-commit.yaml" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/yetone/avante.nvim/pre-commit.yaml?style=flat-square&logo=pre-commit&logoColor=ffffff&label=pre-commit&labelColor=FAAF3F&color=347D39&event=push" alt="pre-commit status" />
</a>
<a href="https://discord.gg/QfnEFEdSjz" target="_blank">
<img src="https://img.shields.io/discord/1302530866362323016?style=flat-square&logo=discord&label=Discord&logoColor=ffffff&labelColor=7376CF&color=268165" alt="Discord" />