-
-
Notifications
You must be signed in to change notification settings - Fork 5
625 lines (558 loc) · 30 KB
/
auto-merge-on-approval.yml
File metadata and controls
625 lines (558 loc) · 30 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# ------------------------------------------------------------------------------------
# Auto-merge on Approval Workflow
#
# Purpose: Automatically enable auto-merge for PRs when configurable approval
# and readiness conditions are met. GitHub handles the actual merge
# when all status checks pass.
#
# Configuration: All settings are loaded from modular .github/env/ files for
# centralized management across all workflows.
#
# Triggers:
# - Pull request reviews (submitted)
# - Pull request state changes (ready_for_review, review_request_removed)
#
# Auto-merge Rules (configurable via .github/env/):
# - Minimum number of approvals
# - No requested reviewers remaining (if configured)
# - No "Changes Requested" reviews
# - PR ready for review (not draft, no WIP indicators)
# - Bot PRs handled separately (if configured)
#
# Maintainer: @mrz1836
#
# ------------------------------------------------------------------------------------
name: Auto-merge on Approval
# --------------------------------------------------------------------
# Trigger Configuration
# --------------------------------------------------------------------
on:
pull_request_review:
types: [submitted]
pull_request:
types: [ready_for_review, review_request_removed]
# Security: Restrict default permissions (jobs must explicitly request what they need)
permissions: {}
# --------------------------------------------------------------------
# Concurrency Control
# --------------------------------------------------------------------
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# --------------------------------------------------------------------
# Environment Variables
# --------------------------------------------------------------------
# Note: Configuration variables are loaded from modular .github/env/ files
jobs:
# ----------------------------------------------------------------------------------
# Load Environment Variables
# ----------------------------------------------------------------------------------
load-env:
name: 🌍 Load Environment Variables
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
env-json: ${{ steps.load-env.outputs.env-json }}
steps:
# --------------------------------------------------------------------
# Check out code to access env file
# --------------------------------------------------------------------
- name: 📥 Checkout code (sparse)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
sparse-checkout: |
.github/env
.github/actions/load-env
# --------------------------------------------------------------------
# Load and parse environment file
# --------------------------------------------------------------------
- name: 🌍 Load environment variables
uses: ./.github/actions/load-env
id: load-env
# ----------------------------------------------------------------------------------
# Process Auto-merge
# ----------------------------------------------------------------------------------
process-auto-merge:
name: 🤖 Process Auto-merge
needs: [load-env]
runs-on: ubuntu-latest
permissions:
pull-requests: write # Required: Update PR status and enable auto-merge
issues: write # Required: Add labels and create comments
outputs:
action-taken: ${{ steps.process.outputs.action }}
pr-number: ${{ github.event.pull_request.number }}
steps:
# --------------------------------------------------------------------
# Extract configuration from env-json
# --------------------------------------------------------------------
- name: 🔧 Extract configuration
id: config
env:
ENV_JSON: ${{ needs.load-env.outputs.env-json }}
run: |
echo "📋 Extracting auto-merge configuration from environment..."
# Extract all needed variables
MIN_APPROVALS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_MIN_APPROVALS')
REQUIRE_ALL_REVIEWS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_REQUIRE_ALL_REQUESTED_REVIEWS')
MERGE_TYPES=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_ALLOWED_MERGE_TYPES')
DELETE_BRANCH=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_DELETE_BRANCH')
SKIP_DRAFT=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_DRAFT')
SKIP_WIP=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_WIP')
WIP_LABELS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_WIP_LABELS')
COMMENT_ON_ENABLE=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_COMMENT_ON_ENABLE')
COMMENT_ON_DISABLE=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_COMMENT_ON_DISABLE')
LABELS_TO_ADD=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_LABELS_TO_ADD')
SKIP_BOT_PRS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_BOT_PRS')
SKIP_FORK_PRS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_FORK_PRS')
COMMENT_ON_FORK_SKIP=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_COMMENT_ON_FORK_SKIP')
AUTO_MERGE_REQUIRE_LABEL=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_REQUIRE_LABEL')
AUTO_MERGE_LABEL=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_LABEL')
PREFERRED_TOKEN=$(echo "$ENV_JSON" | jq -r '.PREFERRED_GITHUB_TOKEN')
# Validate required configuration
if [[ -z "$MIN_APPROVALS" ]] || [[ "$MIN_APPROVALS" == "null" ]]; then
MIN_APPROVALS="1" # Default to 1 approval
fi
# Set as environment variables for all subsequent steps
echo "MIN_APPROVALS=$MIN_APPROVALS" >> $GITHUB_ENV
echo "REQUIRE_ALL_REVIEWS=$REQUIRE_ALL_REVIEWS" >> $GITHUB_ENV
echo "MERGE_TYPES=$MERGE_TYPES" >> $GITHUB_ENV
echo "DELETE_BRANCH=$DELETE_BRANCH" >> $GITHUB_ENV
echo "SKIP_DRAFT=$SKIP_DRAFT" >> $GITHUB_ENV
echo "SKIP_WIP=$SKIP_WIP" >> $GITHUB_ENV
echo "WIP_LABELS=$WIP_LABELS" >> $GITHUB_ENV
echo "COMMENT_ON_ENABLE=$COMMENT_ON_ENABLE" >> $GITHUB_ENV
echo "COMMENT_ON_DISABLE=$COMMENT_ON_DISABLE" >> $GITHUB_ENV
echo "LABELS_TO_ADD=$LABELS_TO_ADD" >> $GITHUB_ENV
echo "SKIP_BOT_PRS=$SKIP_BOT_PRS" >> $GITHUB_ENV
echo "SKIP_FORK_PRS=$SKIP_FORK_PRS" >> $GITHUB_ENV
echo "COMMENT_ON_FORK_SKIP=$COMMENT_ON_FORK_SKIP" >> $GITHUB_ENV
echo "AUTO_MERGE_REQUIRE_LABEL=$AUTO_MERGE_REQUIRE_LABEL" >> $GITHUB_ENV
echo "AUTO_MERGE_LABEL=$AUTO_MERGE_LABEL" >> $GITHUB_ENV
# Determine default merge type
DEFAULT_MERGE_TYPE=$(echo "$MERGE_TYPES" | cut -d',' -f1)
if [[ -z "$DEFAULT_MERGE_TYPE" ]]; then
DEFAULT_MERGE_TYPE="squash"
fi
echo "DEFAULT_MERGE_TYPE=$DEFAULT_MERGE_TYPE" >> $GITHUB_ENV
# Log configuration
echo "🔍 Configuration loaded:"
echo " ✅ Min approvals: $MIN_APPROVALS"
echo " 👥 Require all reviews: $REQUIRE_ALL_REVIEWS"
echo " 🔀 Merge types: $MERGE_TYPES (default: $DEFAULT_MERGE_TYPE)"
echo " 🗑️ Delete branch: $DELETE_BRANCH"
echo " 📝 Skip draft: $SKIP_DRAFT"
echo " 🚧 Skip WIP: $SKIP_WIP"
echo " 🏷️ WIP labels: $WIP_LABELS"
echo " 💬 Comment on enable: $COMMENT_ON_ENABLE"
echo " 💬 Comment on disable: $COMMENT_ON_DISABLE"
echo " 🏷️ Labels to add: $LABELS_TO_ADD"
echo " 🤖 Skip bot PRs: $SKIP_BOT_PRS"
echo " 🍴 Skip fork PRs: $SKIP_FORK_PRS"
echo " 💬 Comment on fork skip: $COMMENT_ON_FORK_SKIP"
echo " 🏷️ Require automerge label: $AUTO_MERGE_REQUIRE_LABEL"
echo " 🏷️ Automerge label name: $AUTO_MERGE_LABEL"
echo " 🔑 Token: Selected via github-script action"
# --------------------------------------------------------------------
# Process the PR for auto-merge
# --------------------------------------------------------------------
- name: 🔍 Check conditions and enable auto-merge
id: process
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: ${{ secrets.GH_PAT_TOKEN || secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
console.log(`🔍 Checking auto-merge conditions for PR #${prNumber}`);
console.log('════════════════════════════════════════════════════════════════');
// Get fresh PR data
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber,
});
console.log(`📋 PR #${prNumber}: "${pr.title}"`);
console.log(`👤 Author: ${pr.user.login} (${pr.user.type})`);
// ————————————————————————————————————————————————————————————————
// Check if we should skip bot PRs
// ————————————————————————————————————————————————————————————————
const isBot = pr.user.type === 'Bot' || pr.user.login.endsWith('[bot]');
if (isBot && process.env.SKIP_BOT_PRS === 'true') {
console.log('🤖 Skipping bot PR (handled by separate workflow)');
core.setOutput('action', 'skip-bot');
return;
}
// ————————————————————————————————————————————————————————————————
// Check if we should skip fork PRs
// ————————————————————————————————————————————————————————————————
// Handle edge case: fork repository deleted/inaccessible (pr.head.repo is null)
if (!pr.head.repo) {
console.log('⚠️ PR head repository is null (fork may have been deleted)');
if (process.env.SKIP_FORK_PRS === 'true') {
console.log('🍴 Skipping PR with deleted fork source (security policy)');
core.setOutput('action', 'skip-deleted-fork');
return;
}
// If not skipping forks, log and continue (will be treated as same-repo PR)
console.log('⚠️ Continuing with auto-merge processing (null repo treated as same-repo)');
} else {
// Safe to access pr.head.repo.full_name now
const headRepoFullName = pr.head.repo.full_name;
const baseRepoFullName = `${owner}/${repo}`;
const isForkPR = headRepoFullName !== baseRepoFullName;
if (isForkPR && process.env.SKIP_FORK_PRS === 'true') {
console.log('🍴 Skipping fork PR (security policy: fork PRs are not auto-merged)');
console.log(` Fork source: ${headRepoFullName}`);
console.log(` Base repository: ${baseRepoFullName}`);
console.log(' Security reason: Fork PRs require manual maintainer review before merge');
// Note: Comments are not posted to fork PRs due to read-only GITHUB_TOKEN permissions
// Fork PR handling is already managed by pull-request-management-fork.yml workflow
if (process.env.COMMENT_ON_FORK_SKIP === 'true') {
console.log(' ℹ️ Comment posting skipped for fork PR (handled by fork PR workflow)');
}
core.setOutput('action', 'skip-fork');
return;
}
}
// ————————————————————————————————————————————————————————————————
// Check basic PR conditions
// ————————————————————————————————————————————————————————————————
const isDraft = pr.draft;
const title = pr.title || '';
const labels = pr.labels.map(l => l.name);
if (isDraft && process.env.SKIP_DRAFT === 'true') {
console.log('📝 PR is draft - skipping auto-merge');
core.setOutput('action', 'skip-draft');
return;
}
// Check for WIP indicators
if (process.env.SKIP_WIP === 'true') {
const titleHasWip = /\b(wip|work.in.progress)\b/i.test(title);
const wipLabels = process.env.WIP_LABELS.split(',').map(l => l.trim());
const hasWipLabel = labels.some(label => wipLabels.includes(label));
if (titleHasWip || hasWipLabel) {
console.log('🚧 PR has WIP indicators - skipping auto-merge');
core.setOutput('action', 'skip-wip');
return;
}
}
// ————————————————————————————————————————————————————————————————
// Check for automerge label requirement
// ————————————————————————————————————————————————————————————————
if (process.env.AUTO_MERGE_REQUIRE_LABEL === 'true') {
const automergeLabel = process.env.AUTO_MERGE_LABEL || 'automerge';
const hasAutomergeLabel = labels.includes(automergeLabel);
if (!hasAutomergeLabel) {
console.log(`🏷️ Missing required label "${automergeLabel}" - skipping auto-merge`);
core.setOutput('action', 'skip-missing-automerge-label');
return;
}
console.log(`✅ Has required automerge label: "${automergeLabel}"`);
}
// ————————————————————————————————————————————————————————————————
// Check review conditions
// ————————————————————————————————————————————————————————————————
const { data: reviews } = await github.rest.pulls.listReviews({
owner,
repo,
pull_number: prNumber,
});
// Get latest review per user
const latestReviews = {};
reviews.forEach(review => {
const userId = review.user.id;
if (!latestReviews[userId] || review.submitted_at > latestReviews[userId].submitted_at) {
latestReviews[userId] = review;
}
});
const currentReviews = Object.values(latestReviews);
const approvals = currentReviews.filter(r => r.state === 'APPROVED').length;
const changesRequested = currentReviews.filter(r => r.state === 'CHANGES_REQUESTED').length;
const requestedReviewers = (pr.requested_reviewers || []).length;
const minApprovals = parseInt(process.env.MIN_APPROVALS);
console.log(`👥 Reviews: ${approvals} approvals, ${changesRequested} changes requested, ${requestedReviewers} pending`);
console.log(`✅ Required approvals: ${minApprovals}`);
// ————————————————————————————————————————————————————————————————
// Determine if we should enable auto-merge
// ————————————————————————————————————————————————————————————————
let shouldEnableAutoMerge = approvals >= minApprovals && changesRequested === 0;
if (process.env.REQUIRE_ALL_REVIEWS === 'true' && requestedReviewers > 0) {
shouldEnableAutoMerge = false;
}
if (!shouldEnableAutoMerge) {
if (approvals < minApprovals) {
console.log(`⏳ Needs ${minApprovals - approvals} more approval(s)`);
}
if (changesRequested > 0) {
console.log('🚫 Has "Changes Requested" reviews');
}
if (process.env.REQUIRE_ALL_REVIEWS === 'true' && requestedReviewers > 0) {
console.log(`⏳ Has ${requestedReviewers} pending reviewer request(s)`);
}
core.setOutput('action', 'conditions-not-met');
return;
}
// ————————————————————————————————————————————————————————————————
// Check if this is a disable event
// ————————————————————————————————————————————————————————————————
if (context.eventName === 'pull_request_review' &&
context.payload.review &&
context.payload.review.state === 'CHANGES_REQUESTED') {
// Try to disable auto-merge
try {
const { execSync } = require('child_process');
execSync(`gh pr merge --disable-auto "${pr.html_url}"`, {
env: {
...process.env,
GH_TOKEN: process.env.GITHUB_TOKEN
},
stdio: 'inherit'
});
console.log('🛑 Auto-merge disabled due to "Changes Requested" review');
if (process.env.COMMENT_ON_DISABLE === 'true') {
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: `🛑 **Auto-merge disabled**\n\nChanges were requested in a review. Auto-merge will be re-enabled when conditions are met again.`
});
}
core.setOutput('action', 'disabled-changes-requested');
} catch (disableError) {
// Differentiate between "not enabled" and actual failures
if (disableError.message && (
disableError.message.includes('not enabled') ||
disableError.message.includes('auto-merge is not enabled')
)) {
console.log('ℹ️ Auto-merge was not enabled, no action needed');
} else {
console.error(`❌ Failed to disable auto-merge: ${disableError.message}`);
// Don't fail workflow, but log the error properly
}
}
return;
}
// ————————————————————————————————————————————————————————————————
// Enable auto-merge
// ————————————————————————————————————————————————————————————————
try {
// Check if auto-merge is already enabled
if (pr.auto_merge) {
console.log('✅ Auto-merge already enabled');
core.setOutput('action', 'already-enabled');
return;
}
// Enable auto-merge with the configured merge type
const { execSync } = require('child_process');
const mergeType = process.env.DEFAULT_MERGE_TYPE;
let mergeCommand = `gh pr merge --auto`;
if (mergeType === 'squash') {
mergeCommand += ' --squash';
} else if (mergeType === 'merge') {
mergeCommand += ' --merge';
} else if (mergeType === 'rebase') {
mergeCommand += ' --rebase';
}
if (process.env.DELETE_BRANCH === 'true') {
mergeCommand += ' --delete-branch';
}
mergeCommand += ` "${pr.html_url}"`;
console.log(`🚀 Enabling auto-merge with command: ${mergeCommand}`);
try {
execSync(mergeCommand, {
env: {
...process.env,
GH_TOKEN: process.env.GITHUB_TOKEN
},
stdio: 'inherit'
});
console.log('✅ Auto-merge enabled! PR will merge when all status checks pass.');
} catch (enableError) {
// Handle race condition: another workflow run may have enabled auto-merge
if (enableError.message && (
enableError.message.includes('already enabled') ||
enableError.message.includes('auto-merge is already enabled')
)) {
console.log('ℹ️ Auto-merge already enabled by another workflow run');
core.setOutput('action', 'already-enabled');
return;
}
// Re-throw other errors to be caught by outer catch block
throw enableError;
}
// Add comment if configured
if (process.env.COMMENT_ON_ENABLE === 'true') {
const mergeTypeText = mergeType === 'squash' ? 'squash and merge' :
mergeType === 'merge' ? 'create a merge commit' :
'rebase and merge';
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: `🤖 **Auto-merge enabled**\n\nThis PR will automatically ${mergeTypeText} when all required status checks pass.\n\n` +
`✅ Approvals: ${approvals}/${minApprovals}\n` +
`🔍 Changes requested: ${changesRequested}\n` +
`⏳ Pending reviews: ${requestedReviewers}`
});
}
// Add labels if configured
if (process.env.LABELS_TO_ADD) {
const labelsToAdd = process.env.LABELS_TO_ADD.split(',').map(l => l.trim()).filter(l => l);
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: prNumber,
labels: labelsToAdd
});
console.log(`🏷️ Added labels: ${labelsToAdd.join(', ')}`);
}
}
core.setOutput('action', 'enabled');
} catch (error) {
console.error('❌ Failed to enable auto-merge:', error.message);
// Comment on failure if configured
if (process.env.COMMENT_ON_ENABLE === 'true') {
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: `⚠️ **Auto-merge failed**\n\nCould not enable auto-merge: ${error.message}\n\n` +
`This might be due to:\n` +
`- Branch protection rules\n` +
`- Missing permissions\n` +
`- Repository settings`
});
}
core.setOutput('action', 'failed');
throw error;
}
# ----------------------------------------------------------------------------------
# Generate Workflow Summary Report
# ----------------------------------------------------------------------------------
summary:
name: 📊 Generate Summary
if: always()
needs: [load-env, process-auto-merge]
runs-on: ubuntu-latest
steps:
# --------------------------------------------------------------------
# Generate a workflow summary report
# --------------------------------------------------------------------
- name: 📊 Generate workflow summary
env:
ENV_JSON: ${{ needs.load-env.outputs.env-json }}
run: |
echo "📊 Generating workflow summary..."
echo "# 🤖 Auto-merge on Approval Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**⏰ Processed:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "**📋 PR:** #${{ needs.process-auto-merge.outputs.pr-number }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Determine action taken
ACTION="${{ needs.process-auto-merge.outputs.action-taken }}"
case "$ACTION" in
"enabled")
ACTION_DESC="✅ Auto-merge enabled"
;;
"already-enabled")
ACTION_DESC="✅ Auto-merge already enabled"
;;
"disabled-changes-requested")
ACTION_DESC="🛑 Auto-merge disabled (changes requested)"
;;
"skip-bot")
ACTION_DESC="🤖 Skipped (bot PR)"
;;
"skip-fork")
ACTION_DESC="🍴 Skipped (fork PR - security policy)"
;;
"skip-deleted-fork")
ACTION_DESC="🍴 Skipped (deleted fork PR)"
;;
"skip-draft")
ACTION_DESC="📝 Skipped (draft PR)"
;;
"skip-wip")
ACTION_DESC="🚧 Skipped (work in progress)"
;;
"skip-missing-automerge-label")
ACTION_DESC="🏷️ Skipped (missing automerge label)"
;;
"conditions-not-met")
ACTION_DESC="⏳ Conditions not met"
;;
"failed")
ACTION_DESC="❌ Failed to enable auto-merge"
;;
*)
ACTION_DESC="❓ Unknown action: $ACTION"
;;
esac
echo "## 🎯 Action Taken" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "$ACTION_DESC" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔧 Current Configuration" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Extract configuration for display
MIN_APPROVALS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_MIN_APPROVALS')
REQUIRE_ALL_REVIEWS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_REQUIRE_ALL_REQUESTED_REVIEWS')
MERGE_TYPES=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_ALLOWED_MERGE_TYPES')
SKIP_DRAFT=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_DRAFT')
SKIP_WIP=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_WIP')
SKIP_BOT_PRS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_BOT_PRS')
SKIP_FORK_PRS=$(echo "$ENV_JSON" | jq -r '.AUTO_MERGE_SKIP_FORK_PRS')
echo "| Setting | Value |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Min approvals | $MIN_APPROVALS |" >> $GITHUB_STEP_SUMMARY
echo "| Require all reviews | $REQUIRE_ALL_REVIEWS |" >> $GITHUB_STEP_SUMMARY
echo "| Allowed merge types | $MERGE_TYPES |" >> $GITHUB_STEP_SUMMARY
echo "| Skip draft PRs | $SKIP_DRAFT |" >> $GITHUB_STEP_SUMMARY
echo "| Skip WIP PRs | $SKIP_WIP |" >> $GITHUB_STEP_SUMMARY
echo "| Skip bot PRs | $SKIP_BOT_PRS |" >> $GITHUB_STEP_SUMMARY
echo "| Skip fork PRs | $SKIP_FORK_PRS |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "🤖 _Automated by GitHub Actions_" >> $GITHUB_STEP_SUMMARY
# --------------------------------------------------------------------
# Report final workflow status
# --------------------------------------------------------------------
- name: 📢 Report workflow status
run: |
echo "=== 🤖 Auto-merge on Approval Summary ==="
echo "📋 PR: #${{ needs.process-auto-merge.outputs.pr-number }}"
ACTION="${{ needs.process-auto-merge.outputs.action-taken }}"
case "$ACTION" in
enabled)
echo "✅ Action: Auto-merge enabled successfully"
;;
already-enabled)
echo "✅ Action: Auto-merge was already enabled"
;;
disabled-changes-requested)
echo "🛑 Action: Auto-merge disabled due to changes requested"
;;
skip-fork)
echo "🍴 Action: Skipped - Fork PR (security policy)"
;;
skip-missing-automerge-label)
echo "🏷️ Action: Skipped - Missing automerge label"
;;
skip-*)
echo "⏭️ Action: Skipped - $ACTION"
;;
conditions-not-met)
echo "⏳ Action: Waiting for conditions to be met"
;;
failed)
echo "❌ Action: Failed to enable auto-merge"
;;
*)
echo "❓ Action: $ACTION"
;;
esac
echo "🕐 Completed: $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "✅ Workflow completed!"