-
Notifications
You must be signed in to change notification settings - Fork 0
262 lines (228 loc) · 8.49 KB
/
Copy pathpr-validation.yml
File metadata and controls
262 lines (228 loc) · 8.49 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
254
255
256
257
258
259
260
261
262
name: PR Validation
on:
pull_request:
types: [opened, edited, synchronize, reopened]
branches: [main] # Focus on main branch PRs only
permissions:
contents: read
issues: write
pull-requests: write
jobs:
# Validate PR title follows conventional commits
validate-pr-title:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v6.1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Configure which types are allowed (must match semantic-release config)
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
deps
# Configure which scopes are allowed (optional)
scopes: |
webhook
helm
ci
docs
security
deps
release
docker
k8s
grafana
tests
controller
# Require a scope to be provided
requireScope: false
# Disable validation of the subject's case
subjectPattern: ^(?![A-Z]).+$
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern. Please ensure that the subject
doesn't start with an uppercase character.
# Ignore merge commits
ignoreLabels: |
ignore-semantic-pull-request
# Validate that PR has appropriate labels - DISABLED
# validate-pr-labels:
# name: Validate PR Labels
# runs-on: ubuntu-latest
# steps:
# - name: Check for required labels
# uses: actions/github-script@v9
# with:
# script: |
# # Label validation disabled for simplified workflow
# Check PR size and complexity
check-pr-size:
name: Check PR Size
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Check PR size
uses: actions/github-script@v9
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const additions = pullRequest.additions;
const deletions = pullRequest.deletions;
const changedFiles = pullRequest.changed_files;
const totalChanges = additions + deletions;
console.log(`PR Statistics:
- Files changed: ${changedFiles}
- Lines added: ${additions}
- Lines deleted: ${deletions}
- Total changes: ${totalChanges}`);
let sizeLabel = '';
let sizeComment = '';
if (totalChanges < 100) {
sizeLabel = 'size:small';
sizeComment = '🟢 **Small PR** - Easy to review';
} else if (totalChanges < 500) {
sizeLabel = 'size:medium';
sizeComment = '🟡 **Medium PR** - Moderate complexity';
} else if (totalChanges < 1000) {
sizeLabel = 'size:large';
sizeComment = '🟠 **Large PR** - Consider breaking into smaller PRs';
} else {
sizeLabel = 'size:xl';
sizeComment = '🔴 **Extra Large PR** - Strongly consider breaking into smaller PRs for easier review';
}
// Add size label if not already present
const labels = pullRequest.labels.map(label => label.name);
const hasSizeLabel = labels.some(label => label.startsWith('size:'));
if (!hasSizeLabel) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [sizeLabel]
});
}
// Add comment for large PRs
if (totalChanges >= 500) {
const comment = `## 📊 PR Size Analysis
${sizeComment}
**Statistics:**
- 📁 Files changed: ${changedFiles}
- ➕ Lines added: ${additions}
- ➖ Lines deleted: ${deletions}
- 📈 Total changes: ${totalChanges}
${totalChanges >= 1000 ? `
### 💡 Suggestions for Large PRs:
- Consider breaking this PR into smaller, focused changes
- Ensure comprehensive testing for all changes
- Add detailed description of all modifications
- Consider pair programming or additional reviewers
` : ''}
*This comment was automatically generated based on PR size analysis.*`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}
# Validate that PR has proper description
validate-pr-description:
name: Validate PR Description
runs-on: ubuntu-latest
steps:
- name: Check PR description
uses: actions/github-script@v9
with:
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
const body = pullRequest.body || '';
const minLength = 50;
if (body.length < minLength) {
const comment = `## 📝 PR Description Required
This PR needs a more detailed description to help reviewers understand the changes.
**Current description length:** ${body.length} characters
**Minimum required:** ${minLength} characters
### Please include:
- 🎯 **What** - What changes are being made?
- 🤔 **Why** - Why are these changes necessary?
- 🧪 **Testing** - How were the changes tested?
- 📸 **Screenshots** - If UI changes, include before/after screenshots
- 🔗 **Related Issues** - Link to related issues or tickets
### Template:
\`\`\`markdown
## Description
Brief description of the changes
## Motivation and Context
Why is this change required? What problem does it solve?
## How Has This Been Tested?
- [ ] Unit tests
- [ ] Integration tests
- [ ] Manual testing
## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
## Checklist:
- [ ] My code follows the code style of this project
- [ ] My change requires a change to the documentation
- [ ] I have updated the documentation accordingly
\`\`\`
*Please update the PR description and this check will pass automatically.*`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
core.setFailed(`PR description is too short (${body.length} characters, minimum ${minLength} required)`);
} else {
console.log('✅ PR description meets minimum requirements');
}
# Summary of all validations
pr-validation-summary:
name: PR Validation Summary
runs-on: ubuntu-latest
needs: [validate-pr-title, check-pr-size, validate-pr-description]
if: always()
steps:
- name: Validation summary
run: |
echo "## PR Validation Summary 📋"
echo ""
echo "| Check | Status |"
echo "|-------|--------|"
echo "| PR Title (Conventional Commits) | ${{ needs.validate-pr-title.result }} |"
echo "| PR Size Analysis | ${{ needs.check-pr-size.result }} |"
echo "| PR Description | ${{ needs.validate-pr-description.result }} |"
echo ""
if [[ "${{ needs.validate-pr-title.result }}" == "success" && \
"${{ needs.check-pr-size.result }}" == "success" && \
"${{ needs.validate-pr-description.result }}" == "success" ]]; then
echo "✅ All PR validations passed!"
else
echo "❌ Some PR validations failed. Please address the issues above."
exit 1
fi