forked from Pradeepsingh61/DSA_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
383 lines (325 loc) Β· 12.7 KB
/
pr-automation.yml
File metadata and controls
383 lines (325 loc) Β· 12.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: π€ PR Automation
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches: [main]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
# Run all tests and validations
run-tests:
name: π§ͺ Run Tests & Validation
runs-on: ubuntu-latest
outputs:
validation-passed: ${{ steps.validation.outputs.passed }}
tests-passed: ${{ steps.tests.outputs.passed }}
steps:
- name: π₯ Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: π Get changed files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files: |
**/*.c
**/*.cpp
**/*.java
**/*.py
**/*.js
**/*.ts
**/*.go
**/*.rs
- name: β
Run PR Validation
id: validation
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Running validation checks..."
# Call existing validation workflow logic
./.github/scripts/validate-pr.sh || validation_failed=true
if [ "$validation_failed" = true ]; then
echo "passed=false" >> $GITHUB_OUTPUT
exit 1
else
echo "passed=true" >> $GITHUB_OUTPUT
fi
- name: π Setup Python for testing
if: contains(steps.changed-files.outputs.all_changed_files, '.py')
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: β Setup Java for testing
if: contains(steps.changed-files.outputs.all_changed_files, '.java')
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: π§ Setup Node.js for testing
if: contains(steps.changed-files.outputs.all_changed_files, '.js') || contains(steps.changed-files.outputs.all_changed_files, '.ts')
uses: actions/setup-node@v4
with:
node-version: '18'
- name: π¦ Setup Rust for testing
if: contains(steps.changed-files.outputs.all_changed_files, '.rs')
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: π§ͺ Run code compilation tests
id: tests
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Running compilation tests..."
test_failed=false
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
case "$file" in
*.cpp)
echo "Testing C++ file: $file"
g++ -std=c++17 -Wall -Wextra -o test_cpp "$file" || test_failed=true
;;
*.c)
echo "Testing C file: $file"
gcc -Wall -Wextra -o test_c "$file" || test_failed=true
;;
*.java)
echo "Testing Java file: $file"
javac "$file" || test_failed=true
;;
*.py)
echo "Testing Python file: $file"
python -m py_compile "$file" || test_failed=true
;;
*.js)
echo "Testing JavaScript file: $file"
node -c "$file" || test_failed=true
;;
*.rs)
echo "Testing Rust file: $file"
rustc --check "$file" || test_failed=true
;;
esac
done
if [ "$test_failed" = true ]; then
echo "passed=false" >> $GITHUB_OUTPUT
exit 1
else
echo "passed=true" >> $GITHUB_OUTPUT
fi
# Wait for all checks to complete
wait-for-checks:
name: β³ Wait for All Tests
runs-on: ubuntu-latest
needs: run-tests
if: always()
steps:
- name: Wait for other workflows
run: |
echo "β³ Waiting for all validation and test workflows to complete..."
sleep 30
echo "β
Proceeding with labeling and notifications"
# Auto-labeling and first-time contributor welcome
auto-label:
name: π·οΈ Auto Label & Welcome
runs-on: ubuntu-latest
needs: [run-tests, wait-for-checks]
if: always()
steps:
- name: π Add Hacktoberfest labels and welcome contributors
uses: actions/github-script@v7
env:
VALIDATION_PASSED: ${{ needs.run-tests.outputs.validation-passed }}
TESTS_PASSED: ${{ needs.run-tests.outputs.tests-passed }}
with:
script: |
const { owner, repo, number } = context.issue;
const validationPassed = process.env.VALIDATION_PASSED === 'true';
const testsPassed = process.env.TESTS_PASSED === 'true';
// Get PR and contributor info
const pr = await github.rest.pulls.get({ owner, repo, pull_number: number });
const contributor = pr.data.user.login;
// Check if first-time contributor
const contributions = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: pr.data.head.sha
});
const isFirstTime = contributions.data.length <= 1;
// Add labels based on PR content and status
const labels = ['hacktoberfest-accepted'];
// Add language labels based on changed files
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: number });
const languages = new Set();
files.data.forEach(file => {
const ext = file.filename.split('.').pop();
switch(ext) {
case 'cpp': languages.add('C++'); break;
case 'c': languages.add('C'); break;
case 'java': languages.add('Java'); break;
case 'py': languages.add('Python'); break;
case 'js': languages.add('JavaScript'); break;
case 'rs': languages.add('Rust'); break;
case 'go': languages.add('Go'); break;
}
});
languages.forEach(lang => labels.push(lang.toLowerCase()));
// Add difficulty labels
if (files.data.length <= 2) labels.push('good first issue');
if (files.data.length > 5) labels.push('advanced');
// Add status labels
if (testsPassed) {
labels.push('tests-passing');
} else {
labels.push('needs-work');
}
if (isFirstTime) {
labels.push('first-time-contributor');
}
// Apply labels
await github.rest.issues.addLabels({
owner,
repo,
issue_number: number,
labels
});
// Welcome first-time contributors
if (isFirstTime) {
const welcomeMessage = `
π **Welcome to Hacktoberfest 2025, @${contributor}!** π
Thank you for your first contribution to our DSA repository! Here's what happens next:
## π Automatic Checks
- β
**Code Validation**: ${validationPassed ? 'Passed' : 'Failed'}
- π§ͺ **Compilation Tests**: ${testsPassed ? 'Passed' : 'Failed'}
## π Next Steps
${testsPassed ?
'π― **Great job!** Your code compiled successfully. Maintainers [@Karanjot786](https://github.com/Karanjot786) and [@Pradeepsingh61](https://github.com/Pradeepsingh61) will review your PR soon.' :
'β οΈ **Action needed**: Please fix the compilation errors and push your changes.'}
## π What You Get
- π **Hacktoberfest Credit**: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
- π **Hall of Fame**: You'll be featured in our contributors list
- π **Learning**: Code review feedback from experienced developers
## π‘ Tips for Success
- Follow our [Contributing Guidelines](./CONTRIBUTING.md)
- Add comments explaining your algorithm
- Include time/space complexity analysis
- Test your code before submitting
Welcome to the community! π
`;
// Check if we already posted a welcome message
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number: number
});
const welcomeComment = comments.data.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('Welcome to Hacktoberfest 2025')
);
// Only post if we haven't already commented, otherwise update
if (!welcomeComment) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body: welcomeMessage
});
} else {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: welcomeComment.id,
body: welcomeMessage
});
}
}
# Request review from maintainers
request-review:
name: π₯ Request Review
runs-on: ubuntu-latest
needs: [run-tests, auto-label]
if: needs.run-tests.outputs.tests-passed == 'true'
steps:
- name: π Request review from maintainers
uses: actions/github-script@v7
with:
script: |
const { owner, repo, number } = context.issue;
// List of maintainers who can review
const reviewers = ['Karanjot786'];
// Get PR details
const pr = await github.rest.pulls.get({ owner, repo, pull_number: number });
// Don't request review from the PR author
const availableReviewers = reviewers.filter(reviewer =>
reviewer !== pr.data.user.login
);
if (availableReviewers.length > 0) {
await github.rest.pulls.requestReviewers({
owner,
repo,
pull_number: number,
reviewers: availableReviewers.slice(0, 2) // Request max 2 reviewers
});
console.log(`Requested review from: ${availableReviewers.slice(0, 2).join(', ')}`);
}
# Notify about PR status
notify-status:
name: π’ Notify Status
runs-on: ubuntu-latest
needs: [run-tests, auto-label, wait-for-checks]
if: always()
steps:
- name: π Comment PR status
uses: actions/github-script@v7
with:
script: |
const { owner, repo, number } = context.issue;
const validationPassed = '${{ needs.run-tests.outputs.validation-passed }}' === 'true';
const testsPassed = '${{ needs.run-tests.outputs.tests-passed }}' === 'true';
let statusMessage = '## π€ Automated PR Status\n\n';
// Validation status
statusMessage += `### π Code Validation\n`;
statusMessage += validationPassed ?
'β
**Passed** - File naming and structure look good!\n\n' :
'β **Failed** - Please check file naming conventions and directory structure.\n\n';
// Test status
statusMessage += `### π§ͺ Compilation Tests\n`;
statusMessage += testsPassed ?
'β
**Passed** - All code compiles successfully!\n\n' :
'β **Failed** - Please fix compilation errors and try again.\n\n';
// Overall status
statusMessage += `### π Overall Status\n`;
if (validationPassed && testsPassed) {
statusMessage += 'π **Ready for Review** - Your PR has passed all automated checks!\n';
statusMessage += 'π₯ Maintainers have been notified for review.\n\n';
} else {
statusMessage += 'β οΈ **Needs Work** - Please address the issues above.\n';
statusMessage += 'π‘ Push new commits to automatically re-run these checks.\n\n';
}
statusMessage += '---\n';
statusMessage += '*This comment was generated automatically. Checks will re-run when you push new commits.*';
// Check if we already posted a status comment
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number: number
});
const statusComment = comments.data.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('Automated PR Status')
);
// Only post if we haven't already commented, otherwise update
if (!statusComment) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body: statusMessage
});
} else {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: statusComment.id,
body: statusMessage
});
}