-
Notifications
You must be signed in to change notification settings - Fork 1
253 lines (221 loc) · 6.9 KB
/
pr-checks.yml
File metadata and controls
253 lines (221 loc) · 6.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: PR Checks
on:
pull_request:
branches:
- main
# Uncomment to enable Git Flow workflow
# - develop
# - feature/**
# - release/**
# - hotfix/**
types:
- opened
- synchronize
- reopened
- edited
- ready_for_review
permissions:
pull-requests: write
contents: read
issues: write
statuses: write
env:
PYTHON_VERSION: "3.12"
jobs:
pr-title-check:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- name: Check PR title format
uses: amannn/action-semantic-pull-request@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
requireScope: false
pr-description-check:
name: Validate PR Description
runs-on: ubuntu-latest
steps:
- name: Check PR has description
uses: actions/github-script@v8
with:
script: |
const pr = context.payload.pull_request;
if (!pr.body || pr.body.length < 50) {
core.setFailed('PR description is too short or missing. Please provide a detailed description.');
}
lint:
name: Lint & Format Code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv and cache dependencies
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install project dependencies
run: |
uv lock
uv sync
- name: Run ruff linter
run: uv run ruff check src/ tests/
- name: Run ruff formatter check
run: uv run ruff format --check src/ tests/
mypy:
name: Mypy Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv and cache dependencies
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install project dependencies
run: |
uv lock
uv sync
- name: Run mypy
run: uv run mypy src/
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv and cache dependencies
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: |
pyproject.toml
uv.lock
- name: Install project dependencies
run: |
uv lock
uv sync
- name: Run tests with coverage
run: |
mkdir -p .log/coverage
uv run pytest
- name: Upload coverage report as artifact
if: always()
uses: actions/upload-artifact@v6
with:
name: coverage-report-${{ env.PYTHON_VERSION }}-${{ github.run_id }}
path: |
.log/coverage/htmlcov
.log/coverage/coverage.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
override_pr: ${{ github.event.pull_request.number }}
slug: ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
conflict-check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check for merge conflict markers
run: |
if git grep -l '<<<<<<< HEAD' -- ':!.github/' || \
git grep -l '>>>>>>> ' -- ':!.github/' || \
git grep -l '=======' -- ':!.github/' ; then
echo "Merge conflict markers found!"
exit 1
fi
size-check:
name: Check File Sizes
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check for large files
run: |
large_files=$(find . -type f -size +10M -not -path "./.git/*")
if [ -n "$large_files" ]; then
echo "Large files detected (>10MB):"
echo "$large_files"
exit 1
fi
pr-checks-summary:
name: PR Checks Summary
runs-on: ubuntu-latest
needs: [pr-title-check, pr-description-check, lint, mypy, test, conflict-check, size-check]
if: always()
steps:
- name: Check all jobs passed
run: |
if [ "${{ contains(join(fromjson(toJSON(needs.*.result)), ',') , 'failure') }}" == "true" ] || \
[ "${{ contains(join(fromjson(toJSON(needs.*.result)), ',') , 'cancelled') }}" == "true" ]; then
echo "One or more required PR checks failed or were cancelled."
exit 1
fi
echo "All required PR checks passed! ✅"
pr-labeler:
name: Apply PR Labels
runs-on: ubuntu-latest
needs: pr-checks-summary
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Apply labels based on PR title
uses: actions/github-script@v8
with:
script: |
const prTitle = context.payload.pull_request.title.toLowerCase();
const labels = [];
if (prTitle.startsWith('feat:')) labels.push('feature');
else if (prTitle.startsWith('fix:')) labels.push('bug');
else if (prTitle.startsWith('docs:')) labels.push('documentation');
else if (prTitle.startsWith('style:')) labels.push('enhancement');
else if (prTitle.startsWith('refactor:')) labels.push('refactor');
else if (prTitle.startsWith('perf:')) labels.push('enhancement');
else if (prTitle.startsWith('test:')) labels.push('enhancement');
else if (prTitle.startsWith('build:')) labels.push('enhancement');
else if (prTitle.startsWith('ci:')) labels.push('ci');
else if (prTitle.startsWith('chore:')) labels.push('enhancement');
if (labels.length > 0) {
core.info(`Applying labels: ${labels.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: labels
});
}