-
Notifications
You must be signed in to change notification settings - Fork 1
235 lines (203 loc) · 8.09 KB
/
Copy pathpr-checks.yml
File metadata and controls
235 lines (203 loc) · 8.09 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
name: PR Checks
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches: [ main ]
jobs:
# ==================== PR Metadata Checks ====================
pr-metadata:
name: Validate PR Metadata
runs-on: ubuntu-latest
steps:
- name: Check PR Title
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Require PR titles to follow conventional commits
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
requireScope: false
subjectPattern: ^[A-Z].+$
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
must start with an uppercase character.
- name: Check PR Size
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const additions = pr.additions;
const deletions = pr.deletions;
const totalChanges = additions + deletions;
console.log(`PR changes: +${additions} -${deletions} (total: ${totalChanges})`);
// Warn on large PRs (over 500 lines changed)
if (totalChanges > 500) {
core.warning(`This PR is quite large (${totalChanges} lines changed). Consider splitting into smaller PRs for easier review.`);
}
// Error on very large PRs (over 1500 lines changed), unless skip-size-check label is present
const hasSkipLabel = pr.labels.some(label => label.name === 'skip-size-check');
if (totalChanges > 1500 && !hasSkipLabel) {
core.setFailed(`This PR is too large (${totalChanges} lines changed). Please split into smaller, focused PRs or add the "skip-size-check" label.`);
}
# ==================== Dependency Review ====================
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
with:
fail-on-severity: moderate
deny-licenses: GPL-2.0, GPL-3.0
# GHSA-2gh3-rmm4-6rq5: protobuf crash via prometheus 0.13 — no upstream fix available.
# Only reachable from internal Prometheus scraper, not public-facing.
# GHSA-pwjx-qhcg-rvj4: rustls-webpki in operator — fixed by updating to 0.103.10.
allow-ghsas: GHSA-2gh3-rmm4-6rq5, GHSA-pwjx-qhcg-rvj4
# ==================== Label Checks ====================
require-label:
name: Require Label
runs-on: ubuntu-latest
steps:
- name: Check for required labels
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const labels = pr.labels.map(label => label.name);
const requiredLabels = ['bug', 'enhancement', 'documentation', 'maintenance', 'dependencies'];
const hasRequiredLabel = labels.some(label => requiredLabels.includes(label));
if (!hasRequiredLabel) {
core.setFailed(`PR must have at least one of these labels: ${requiredLabels.join(', ')}`);
}
console.log(`PR labels: ${labels.join(', ')}`);
# ==================== Documentation Checks ====================
docs-updated:
name: Check Documentation Updated
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if docs need updating
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const codeChanged = files.data.some(file =>
file.filename.startsWith('src/') ||
file.filename.startsWith('operator/') ||
file.filename === 'Cargo.toml'
);
const docsChanged = files.data.some(file =>
file.filename.startsWith('docs/') ||
file.filename === 'README.md' ||
file.filename.startsWith('examples/')
);
if (codeChanged && !docsChanged) {
core.warning('Code changes detected but no documentation updates. Consider updating docs if needed.');
}
# ==================== Changelog Check ====================
changelog-updated:
name: Check Changelog Updated
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip-changelog')"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check changelog
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const changelogUpdated = files.data.some(file =>
file.filename === 'docs/CHANGELOG.md'
);
const isDraft = pr.draft;
const hasSkipLabel = pr.labels.some(label => label.name === 'skip-changelog');
if (!changelogUpdated && !isDraft && !hasSkipLabel) {
core.warning('CHANGELOG.md not updated. Add "skip-changelog" label if this is intentional.');
}
# ==================== Breaking Change Check ====================
breaking-change:
name: Check Breaking Changes
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for breaking changes
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const body = pr.body || '';
const title = pr.title || '';
const hasBreakingLabel = pr.labels.some(label => label.name === 'breaking-change');
const hasBangInTitle = title.includes('!:');
const hasBreakingInBody = body.toLowerCase().includes('breaking change');
if (hasBreakingLabel || hasBangInTitle || hasBreakingInBody) {
core.warning('⚠️ This PR contains BREAKING CHANGES. Ensure proper documentation and migration guide.');
}
# ==================== Security Check ====================
security-review:
name: Security Review Required
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for security-sensitive changes
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
const securityPaths = [
'src/security',
'SECURITY.md',
'.github/workflows',
'Dockerfile',
'src/kafka/sink.rs'
];
const touchesSecurityCode = files.data.some(file =>
securityPaths.some(path => file.filename.includes(path))
);
if (touchesSecurityCode) {
core.warning('🔒 This PR touches security-sensitive code. Extra review required.');
// Check if security label exists
const hasSecurityLabel = pr.labels.some(label => label.name === 'security');
if (!hasSecurityLabel) {
core.setFailed('Security-sensitive PR must have "security" label');
}
}