-
Notifications
You must be signed in to change notification settings - Fork 1.5k
108 lines (96 loc) · 3.18 KB
/
Copy pathpylint.yml
File metadata and controls
108 lines (96 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Pylint Code Quality Check
on:
pull_request:
branches:
- v3
push:
branches:
- v3
workflow_dispatch:
permissions:
contents: read
concurrency:
group: pylint-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
pylint:
runs-on: ubuntu-latest
name: Pylint Code Quality Check
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
version: '0.12.5'
python-version: '3.14'
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install dependencies
run: uv sync --locked
- name: Verify pylint config
run: |
# 检查项目中的pylint配置文件是否存在
if [ -f .pylintrc ]; then
echo "✅ 找到项目配置文件: .pylintrc"
echo "配置文件内容预览:"
head -10 .pylintrc
else
echo "❌ 未找到 .pylintrc 配置文件"
exit 1
fi
- name: Collect changed Python files
id: changed
env:
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
BEFORE_SHA: ${{ github.event.before }}
CURRENT_SHA: ${{ github.sha }}
run: |
if [[ "$EVENT_NAME" == "pull_request" ]]; then
git diff --name-only --diff-filter=ACMRT \
"origin/$BASE_REF...HEAD" -- '*.py' > changed-python-files.txt
elif [[ "$EVENT_NAME" == "push" ]] \
&& [[ -n "$BEFORE_SHA" ]] \
&& [[ ! "$BEFORE_SHA" =~ ^0+$ ]] \
&& git cat-file -e "$BEFORE_SHA^{commit}"; then
git diff --name-only --diff-filter=ACMRT \
"$BEFORE_SHA" "$CURRENT_SHA" -- '*.py' > changed-python-files.txt
else
git diff-tree --no-commit-id --name-only --diff-filter=ACMRT \
-r HEAD -- '*.py' > changed-python-files.txt
fi
sort -u -o changed-python-files.txt changed-python-files.txt
if [[ -s changed-python-files.txt ]]; then
echo "has_files=true" >> "$GITHUB_OUTPUT"
sed -n '1,200p' changed-python-files.txt
else
echo "has_files=false" >> "$GITHUB_OUTPUT"
echo "本次没有改动 Python 文件"
fi
- name: Run pylint on changed Python files
if: steps.changed.outputs.has_files == 'true'
run: |
xargs uv run --locked --no-sync pylint \
--output-format=colorized --reports=yes --score=yes \
< changed-python-files.txt
- name: Generate full advisory report
if: always()
run: |
uv run --locked --no-sync pylint app/ \
--output-format=json > pylint-report.json || true
- name: Upload pylint report
uses: actions/upload-artifact@v7
if: always()
with:
name: pylint-report
path: pylint-report.json
- name: Summary
run: |
echo "🎉 Pylint 检查完成!"
echo "✅ 改动 Python 文件没有新增语法错误或严重问题"
echo "📊 全仓建议性报告已保存为构建工件"