Skip to content

feat(ruff): add Ruff configuration for code linting and formatting #10

feat(ruff): add Ruff configuration for code linting and formatting

feat(ruff): add Ruff configuration for code linting and formatting #10

Workflow file for this run

name: Ruff Linter
on: [ push, pull_request ]
jobs:
ruff:
name: Run Ruff Linter
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x' # 兼容所有 Python 版本
- name: Cache Ruff
uses: actions/cache@v3
with:
path: ~/.cache/ruff
key: ruff-${{ runner.os }}-${{ github.sha }}
restore-keys: |
ruff-${{ runner.os }}-
- name: Run Ruff Linter
uses: astral-sh/ruff-action@v3
with:
args: check . # 执行 lint 代码检查
# 尝试自动修复
- name: Fix Ruff Issues (Optional)
run: ruff check . --fix
# 如果检测失败,则终止 CI
- name: Fail if Lint Errors Exist
run: |
if [[ $(ruff check . --output-format=json | jq '. | length') -gt 0 ]]; then
exit 1
fi