Repository navigation
166 lines (144 loc) · 4.62 KB
/
Copy pathcode-check.yml
File metadata and controls
166 lines (144 loc) · 4.62 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
name: 代码质量门禁
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- dev
workflow_dispatch:
permissions:
contents: read
pull-requests: read
jobs:
# ============================================================
# 检测变更:前端 / 后端语言检查按路径运行
# ============================================================
changes:
name: 代码质量变更检测
runs-on: ubuntu-latest
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.base_ref || github.event.repository.default_branch }}
filters: |
frontend:
- 'frontend/**'
- '.github/workflows/code-check.yml'
backend:
- 'backend/**'
- 'backend.Tests/**'
- 'backend.OracleIntegrationTests/**'
- 'ClubHub.sln'
- '.editorconfig'
- '.github/workflows/code-check.yml'
pre-commit-check:
name: 通用 pre-commit 检查
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: 运行通用 pre-commit 检查
uses: pre-commit/[email protected]
with:
extra_args: --config .pre-commit-ci-config.yaml --all-files
frontend-check:
name: 前端代码检查
runs-on: ubuntu-latest
permissions:
contents: read
needs: changes
if: github.event_name == 'workflow_dispatch' || needs.changes.outputs.frontend == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- name: Install dependencies
run: pnpm install --frozen-lockfile
working-directory: frontend
- name: Prettier 格式检查
run: pnpm run format:ci
working-directory: frontend
backend-check:
name: 后端代码检查
runs-on: ubuntu-latest
permissions:
contents: read
needs: changes
if: github.event_name == 'workflow_dispatch' || needs.changes.outputs.backend == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: dotnet format
run: |
dotnet format backend/ClubHub.Api.csproj --verify-no-changes --exclude "backend/Models/**"
dotnet format backend.Tests/ClubHub.Api.Tests.csproj --verify-no-changes
dotnet format backend.OracleIntegrationTests/ClubHub.Api.OracleIntegrationTests.csproj --verify-no-changes
code-check:
name: 代码质量门禁
runs-on: ubuntu-latest
needs:
- changes
- pre-commit-check
- frontend-check
- backend-check
if: ${{ always() }}
steps:
- name: 汇总代码质量检查结果
shell: bash
run: |
set -euo pipefail
changes="${{ needs.changes.result }}"
pre_commit="${{ needs.pre-commit-check.result }}"
frontend="${{ needs.frontend-check.result }}"
backend="${{ needs.backend-check.result }}"
echo "changes: $changes"
echo "pre-commit-check: $pre_commit"
echo "frontend-check: $frontend"
echo "backend-check: $backend"
if [[ "$changes" != "success" ]]; then
echo "::error::代码质量变更检测失败。"
exit 1
fi
if [[ "$pre_commit" != "success" ]]; then
echo "::error::通用 pre-commit 检查失败。"
exit 1
fi
if [[ "$frontend" != "success" && "$frontend" != "skipped" ]]; then
echo "::error::前端代码检查失败。"
exit 1
fi
if [[ "$backend" != "success" && "$backend" != "skipped" ]]; then
echo "::error::后端代码检查失败。"
exit 1
fi
echo "代码质量门禁通过。"