1+ # AGB Python SDK CI/CD Pipeline
2+ name : " AGB SDK Quality Assurance"
3+
4+ triggers :
5+ merge_request :
6+ target-branches :
7+ - " **"
8+ types :
9+ - " opened"
10+ push :
11+ branches :
12+ - " master"
13+ - " release_v*"
14+
15+ traits :
16+ - type : " notification"
17+ properties :
18+ types :
19+ - " dingtalk"
20+ when :
21+ - " fail"
22+ users :
23+ - " 68125" # 替换为实际用户ID
24+ - " 187788" # 替换为实际用户ID
25+ webhooks :
26+ - " https://oapi.dingtalk.com/robot/send?access_token=eea6bd5473a4542870d3a33ebd678b8ba214f2f99a756ce04db1c3da8ba32280"
27+ dingtalkGroupIds :
28+ - " cid4XzFY99C8o2VZU/LaPj6BA=="
29+
30+ params :
31+ python_enabled :
32+ name : 启用Python代码扫描
33+ type : boolean
34+ default : true
35+ python_version :
36+ name : Python版本
37+ type : string
38+ default : " 3.10"
39+ security_scan_enabled :
40+ name : 启用安全扫描
41+ type : boolean
42+ default : true
43+ unit_test_enabled :
44+ name : 启用单元测试
45+ type : boolean
46+ default : false
47+ format_code_enabled :
48+ name : 启用代码格式检查
49+ type : boolean
50+ default : true
51+ compare_to :
52+ name : 对比目标
53+ description : " 默认在PUSH场景下为前一个提交,CR场景下为目标分支"
54+ type : string
55+ advanced : true
56+ default : " ${{(git.merge_request != null ? git.merge_request.targetBranch : (git.push != null ? git.push.beforeSha256 : params.before_commit_id)) ?: git.defaultBranch}}"
57+ runs_on_resources :
58+ name : 资源规格
59+ description : " 运行时容器资源规格"
60+ default : " 4-16Gi"
61+ options :
62+ - " 4-16Gi"
63+ - " 8-32Gi"
64+ - " 16-64Gi"
65+
66+ jobs :
67+ setup :
68+ name : " 环境准备"
69+ runs-on :
70+ - " ${{params.runs_on_resources}}"
71+ outputs :
72+ python_code : ' ${{steps.cloc.outputs.Python_code ?: "0"}}'
73+ python_code_inc : ' ${{steps.cloc.outputs.Python_added_code ?: "0"}}'
74+ image : alios-8u
75+ steps :
76+ - uses : checkout
77+ - uses : cloc
78+ id : cloc
79+ continue-on-error : false
80+ inputs :
81+ compare_to : " ${{params.compare_to}}"
82+ write_outputs : true
83+ - uses : setup-env
84+ inputs :
85+ python-version : " ${{params.python_version}}"
86+
87+
88+
89+ code-quality-scan :
90+ name : " 代码质量扫描"
91+ needs : ["setup"]
92+ when : " ${{params.python_enabled}}"
93+ timeout : " 30m"
94+ runs-on :
95+ - " ${{params.runs_on_resources}}"
96+ steps :
97+ - uses : checkout
98+ - uses : setup-env
99+ inputs :
100+ python-version : " ${{params.python_version}}"
101+
102+
103+ # 代码格式检查
104+ - id : format-check
105+ when : " ${{params.format_code_enabled}}"
106+ continue-on-error : true
107+ run : |
108+ echo "检查代码格式,不修改文件..."
109+ python -m pip install --upgrade pip
110+ pip install black && black agb tests --exclude "agb/modules/browser/eval" --check --diff
111+ pip install isort && isort --check-only --diff --verbose agb tests --skip agb/modules/browser/eval
112+ echo "格式检查完成"
113+
114+ # 代码质量检查
115+ - id : lint-check
116+ run : |
117+ echo "执行代码质量检查..."
118+ python -m pip install --upgrade pip
119+ pip install flake8 && flake8 agb tests --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=agb/modules/browser/eval
120+ echo "质量检查完成"
121+
122+ # 类型检查
123+ - id : type-check
124+ continue-on-error : false
125+ run : |
126+ echo "执行类型检查..."
127+ python -m pip install --upgrade pip
128+ pip install mypy
129+ pip install types-requests types-aiohttp types-Pillow types-setuptools types-pydantic || true
130+ mypy agb --install-types --no-error-summary --exclude 'agb/modules/browser/eval' --install-types --non-interactive
131+ echo "类型检查完成"
132+
133+ security-scan :
134+ name : " 安全扫描"
135+ needs : ["setup"]
136+ when : " ${{params.security_scan_enabled}}"
137+ timeout : " 20m"
138+ runs-on :
139+ - " ${{params.runs_on_resources}}"
140+ steps :
141+ - uses : checkout
142+ - uses : setup-env
143+ inputs :
144+ python-version : " ${{params.python_version}}"
145+
146+
147+ # Bandit安全扫描
148+ - id : bandit-scan
149+ continue-on-error : false
150+ run : |
151+ echo "执行Bandit安全扫描..."
152+ python -m pip install --upgrade pip
153+ pip install bandit
154+ python -m bandit -r agb/ -v --skip B105,B106,B107 --exclude agb/modules/browser/eval
155+ echo "Bandit扫描完成"
156+
157+ # Running security scans
158+ - id : pip-audit-scan
159+ continue-on-error : false
160+ run : |
161+ echo "执行pip-audit依赖漏洞扫描..."
162+ python -m pip install --upgrade pip
163+ pip install pip-audit
164+ pip-audit --desc
165+ echo "依赖漏洞扫描完成"
166+
167+ # 单元测试(暂时注释,待添加测试用例后启用)
168+ # unit-tests:
169+ # name: "单元测试"
170+ # needs: ["setup"]
171+ # when: "${{params.unit_test_enabled && #number(jobs.setup.outputs.python_code) > 0}}"
172+ # timeout: "20m"
173+ # runs-on:
174+ # - "${{params.runs_on_resources}}"
175+ # steps:
176+ # - uses: checkout
177+ # - uses: setup-env
178+ # inputs:
179+ # python-version: "${{params.python_version}}"
180+ #
181+ # - id: install-deps
182+ # run: |
183+ # echo "安装测试依赖..."
184+ # pip install -e .[test]
185+ # echo "依赖安装完成"
186+ #
187+ # - id: run-tests
188+ # run: |
189+ # echo "执行单元测试..."
190+ # pytest tests/ -v --cov=agb --cov-report=term-missing --cov-report=xml:coverage.xml --cov-report=html:htmlcov/
191+ # echo "单元测试完成"
192+ #
193+ # - uses: upload-artifact
194+ # inputs:
195+ # retention-days: 30
196+ # path: |
197+ # coverage.xml
198+ # htmlcov/**/*
199+ # .coverage
200+
201+ summary :
202+ name : " 质量检查总结"
203+ needs : ["code-quality-scan", "security-scan"]
204+ runs-on :
205+ - " 4-16Gi"
206+ steps :
207+ - id : generate-summary
208+ run : |
209+ echo "=========================================="
210+ echo " AGB SDK 质量检查完成"
211+ echo "=========================================="
212+ echo "✅ 代码质量扫描: 已完成"
213+ echo "✅ 安全扫描: 已完成"
214+
215+ echo "📝 单元测试: 待添加测试用例后启用"
216+ echo "=========================================="
217+ echo "请查看各个任务的详细报告获取更多信息"
218+ echo "=========================================="
0 commit comments