-
Notifications
You must be signed in to change notification settings - Fork 14
174 lines (145 loc) · 4.7 KB
/
Copy pathcode-quality.yml
File metadata and controls
174 lines (145 loc) · 4.7 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Code Quality & AI Review
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
pull_request:
branches:
- main
paths:
- 'firmware/**'
- 'tools/**'
- '.github/workflows/code-quality.yml'
push:
branches:
- main
paths:
- 'firmware/**'
- 'tools/**'
schedule:
# 每天凌晨 2 点运行一次完整扫描
- cron: '0 2 * * *'
permissions:
contents: read
security-events: write
pull-requests: write
actions: read
jobs:
# CodeQL 安全扫描(仅 JavaScript;C/C++ 固件使用 MounRiver/WCH 工具链,无标准构建系统)
codeql-analysis:
name: CodeQL Security Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: javascript
queries: +security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v4
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:javascript"
# JavaScript/TypeScript 代码质量检查
js-ts-quality:
name: JavaScript/TypeScript Quality Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 11.9.0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'pnpm'
cache-dependency-path: tools/studio/pnpm-lock.yaml
- name: Install dependencies
working-directory: tools/studio
run: pnpm install --frozen-lockfile
- name: Run ESLint
working-directory: tools/studio
run: pnpm run lint || echo "ESLint check completed with warnings"
- name: Run TypeScript type check
working-directory: tools/studio
run: pnpm run type-check
- name: Build check
working-directory: tools/studio
run: pnpm run build-only
# C/C++ 代码质量检查
cpp-quality:
name: C/C++ Quality Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install cppcheck
run: |
sudo apt-get update
sudo apt-get install -y cppcheck
- name: Run cppcheck on firmware
continue-on-error: true
run: |
cppcheck --enable=all --suppress=missingIncludeSystem \
--xml --xml-version=2 \
firmware/CH592F/ 2> cppcheck-result.xml || true
cppcheck --enable=all --suppress=missingIncludeSystem \
--xml --xml-version=2 \
firmware/CH552G/ 2> cppcheck-result2.xml || true
- name: Upload cppcheck results
uses: actions/upload-artifact@v4
if: always()
with:
name: cppcheck-results
path: cppcheck-result*.xml
retention-days: 7
# 代码复杂度分析
complexity-analysis:
name: Code Complexity Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Install complexity analysis tools
run: |
npm install -g jscpd@latest
- name: Check code duplication (JavaScript/TypeScript)
continue-on-error: true
run: |
jscpd tools/studio/ --min-lines 5 --min-tokens 50 --format markdown > duplication-report.md || true
- name: Upload complexity report
uses: actions/upload-artifact@v4
if: always()
with:
name: complexity-report
path: duplication-report.md
retention-days: 7
# 总结报告
quality-summary:
name: Quality Check Summary
runs-on: ubuntu-latest
needs: [codeql-analysis, js-ts-quality, cpp-quality, complexity-analysis]
if: always()
steps:
- name: Check results
run: |
echo "## Code Quality Check Summary" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| CodeQL Analysis | ${{ needs.codeql-analysis.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| JS/TS Quality | ${{ needs.js-ts-quality.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| C/C++ Quality | ${{ needs.cpp-quality.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Complexity Analysis | ${{ needs.complexity-analysis.result }} |" >> $GITHUB_STEP_SUMMARY