-
-
Notifications
You must be signed in to change notification settings - Fork 0
512 lines (443 loc) Β· 20.1 KB
/
buddy-bot.yml
File metadata and controls
512 lines (443 loc) Β· 20.1 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
name: Buddy Bot
on:
schedule:
# Check for rebase requests every ~20 minutes (offset to avoid overlap with update/dashboard)
- cron: '5,25,45 * * * *'
# Update dependencies every 2 hours
- cron: '0 */2 * * *'
# Update dashboard 15 minutes after dependency updates (ensures updates are reflected)
- cron: '15 */2 * * *'
workflow_dispatch: # Manual trigger
inputs:
job:
description: Which job to run
required: false
default: all
type: choice
options:
- all
- check
- update
- dashboard
# Update job inputs
strategy:
description: Update strategy
required: false
default: patch
type: choice
options:
- all
- major
- minor
- patch
packages:
description: Specific packages (comma-separated)
required: false
type: string
# Dashboard job inputs
title:
description: Custom dashboard title
required: false
type: string
issue_number:
description: Specific issue number to update
required: false
type: string
# Common inputs
dry_run:
description: Dry run (preview only)
required: false
default: false
type: boolean
verbose:
description: Enable verbose logging
required: false
default: true
type: boolean
env:
# For workflow file updates, you need a Personal Access Token with 'repo' and 'workflow' scopes
# Create a PAT at: https://github.com/settings/tokens
# Add it as a repository secret named 'BUDDY_BOT_TOKEN'
# If BUDDY_BOT_TOKEN is not available, falls back to GITHUB_TOKEN (limited permissions)
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUDDY_BOT_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN }}
permissions:
contents: write
pull-requests: write
issues: write
actions: write
checks: read
statuses: read
jobs:
# Job to determine which jobs should run based on trigger
determine-jobs:
runs-on: ubuntu-latest
outputs:
run_check: ${{ steps.determine.outputs.run_check }}
run_update: ${{ steps.determine.outputs.run_update }}
run_dashboard: ${{ steps.determine.outputs.run_dashboard }}
steps:
- name: Determine which jobs to run
id: determine
run: |
# Default to not running any jobs
echo "run_check=false" >> $GITHUB_OUTPUT
echo "run_update=false" >> $GITHUB_OUTPUT
echo "run_dashboard=false" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
JOB="${{ github.event.inputs.job || 'all' }}"
if [ "$JOB" = "all" ] || [ "$JOB" = "check" ]; then
echo "run_check=true" >> $GITHUB_OUTPUT
fi
if [ "$JOB" = "all" ] || [ "$JOB" = "update" ]; then
echo "run_update=true" >> $GITHUB_OUTPUT
fi
if [ "$JOB" = "all" ] || [ "$JOB" = "dashboard" ]; then
echo "run_dashboard=true" >> $GITHUB_OUTPUT
fi
elif [ "${{ github.event_name }}" = "schedule" ]; then
# Determine based on cron schedule
if [ "${{ github.event.schedule }}" = "5,25,45 * * * *" ]; then
echo "run_check=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.schedule }}" = "0 */2 * * *" ]; then
echo "run_update=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event.schedule }}" = "15 */2 * * *" ]; then
echo "run_dashboard=true" >> $GITHUB_OUTPUT
fi
fi
# Shared setup job for common dependencies
setup:
runs-on: ubuntu-latest
needs: determine-jobs
if: ${{ needs.determine-jobs.outputs.run_check == 'true' || needs.determine-jobs.outputs.run_update == 'true' || needs.determine-jobs.outputs.run_dashboard == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # Fetch full history for rebasing
persist-credentials: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup PHP and Composer (if needed)
if: ${{ hashFiles('composer.json') != '' }}
uses: shivammathur/setup-php@2.35.5
with:
php-version: '8.4'
tools: composer
coverage: none
- name: Install Composer dependencies (if needed)
if: ${{ hashFiles('composer.json') != '' }}
run: composer install --prefer-dist --optimize-autoloader
- name: Install dependencies
run: bun install
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Check job (handles both rebase requests and auto-closing PRs)
check:
runs-on: ubuntu-latest
needs: [determine-jobs, setup]
if: ${{ needs.determine-jobs.outputs.run_check == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Check token permissions
run: |
if [ -z "${{ secrets.BUDDY_BOT_TOKEN }}" ]; then
echo "β οΈ Using GITHUB_TOKEN (limited permissions)"
echo "π‘ For full workflow file update support:"
echo " 1. Create a Personal Access Token with 'repo' and 'workflow' scopes"
echo " 2. Add it as repository secret 'BUDDY_BOT_TOKEN'"
echo " 3. Re-run this workflow"
else
echo "β
Using BUDDY_BOT_TOKEN (full permissions)"
fi
- name: Check for PRs that need attention
run: |
echo "π Checking for PRs that need attention (rebase requests or auto-closing)..."
echo "π§ Environment info:"
echo "Current directory: $(pwd)"
echo "GITHUB_TOKEN set: $([[ -n "$GITHUB_TOKEN" ]] && echo "Yes" || echo "No")"
echo "Repository: ${{ github.repository }}"
echo "Event: ${{ github.event_name }}"
echo ""
echo "π Running update-check command..."
set -e # Exit on any error
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "π Running in DRY RUN mode..."
bunx buddy-bot update-check --dry-run --verbose
else
echo "π Running in LIVE mode..."
bunx buddy-bot update-check --verbose
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUDDY_BOT_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN }}
- name: Create check summary
if: always()
run: |
echo "## π Check Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry run**: ${{ github.event.inputs.dry_run || 'false' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Time**: $(date)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "β° **Scheduled Check**: Automatically checks every 20 minutes" >> $GITHUB_STEP_SUMMARY
else
echo "π±οΈ **Manual Check**: Manually triggered from Actions tab" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "π View detailed logs above for check results (rebase requests, auto-closing, and branch cleanup)." >> $GITHUB_STEP_SUMMARY
# Dependency update job
dependency-update:
runs-on: ubuntu-latest
needs: [determine-jobs, setup]
if: ${{ needs.determine-jobs.outputs.run_update == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: true
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup PHP and Composer (if needed)
if: ${{ hashFiles('composer.json') != '' }}
uses: shivammathur/setup-php@2.35.5
with:
php-version: '8.4'
tools: composer
coverage: none
- name: Install Composer dependencies (if needed)
if: ${{ hashFiles('composer.json') != '' }}
run: composer install --prefer-dist --optimize-autoloader
- name: Install dependencies
run: bun install
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Display update configuration
run: |
echo "π§ͺ **Buddy Bot Update Mode**"
echo "Strategy: ${{ github.event.inputs.strategy || 'patch' }}"
echo "Dry Run: ${{ github.event.inputs.dry_run || 'false' }}"
echo "Packages: ${{ github.event.inputs.packages || 'all' }}"
echo "Verbose: ${{ github.event.inputs.verbose || 'true' }}"
echo "Triggered by: ${{ github.event_name }}"
echo "Repository: ${{ github.repository }}"
echo "Branch: ${{ github.ref_name }}"
- name: Run Buddy dependency updates
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
STRATEGY="${{ github.event.inputs.strategy || 'patch' }}"
PACKAGES="${{ github.event.inputs.packages }}"
VERBOSE="${{ github.event.inputs.verbose || 'true' }}"
echo "π Running dependency updates..."
echo "This will create/update PRs if outdated dependencies are found"
echo ""
set -e # Exit on any error
if [ "$PACKAGES" != "" ]; then
if [ "$VERBOSE" = "true" ]; then
bunx buddy-bot update --packages "$PACKAGES" --verbose
else
bunx buddy-bot update --packages "$PACKAGES"
fi
else
if [ "$VERBOSE" = "true" ]; then
bunx buddy-bot update --strategy "$STRATEGY" --verbose
else
bunx buddy-bot update --strategy "$STRATEGY"
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUDDY_BOT_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN }}
- name: Dry run notification
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "βΉοΈ **Dry Run Mode** - No changes were made"
echo "To apply updates, run this workflow again with 'Dry run' set to false"
- name: Create update summary
if: always()
run: |
echo "## π Dependency Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Strategy**: ${{ github.event.inputs.strategy || 'patch' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry run**: ${{ github.event.inputs.dry_run || 'false' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Packages**: ${{ github.event.inputs.packages || 'all' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Verbose**: ${{ github.event.inputs.verbose || 'true' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Time**: $(date)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "β° **Scheduled Run**: This was triggered automatically every 2 hours" >> $GITHUB_STEP_SUMMARY
echo "π‘ **Tip**: Use 'Actions' tab to manually trigger with custom settings" >> $GITHUB_STEP_SUMMARY
else
echo "π±οΈ **Manual Trigger**: This was triggered manually from the Actions tab" >> $GITHUB_STEP_SUMMARY
echo "β° **Auto-Schedule**: This workflow also runs every 2 hours" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "π View detailed logs above for scan and update results." >> $GITHUB_STEP_SUMMARY
# Dashboard update job
dashboard-update:
runs-on: ubuntu-latest
needs: [determine-jobs, setup, dependency-update]
if: ${{ needs.determine-jobs.outputs.run_dashboard == 'true' && always() }}
steps:
- name: Checkout repository
uses: actions/checkout@v5.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Display dashboard configuration
run: |
echo "π **Buddy Bot Dashboard Management**"
echo "Pin Dashboard: ${{ github.event.inputs.pin || 'true' }}"
echo "Custom Title: ${{ github.event.inputs.title || 'default' }}"
echo "Issue Number: ${{ github.event.inputs.issue_number || 'auto-detect' }}"
echo "Verbose: ${{ github.event.inputs.verbose || 'true' }}"
echo "Dry Run: ${{ github.event.inputs.dry_run || 'false' }}"
echo "Triggered by: ${{ github.event_name }}"
echo "Repository: ${{ github.repository }}"
echo "Branch: ${{ github.ref_name }}"
- name: Pre-flight dashboard check
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
echo "π Pre-flight check: Looking for existing dashboard issues..."
# Check for existing dashboard issues to prevent duplicates
if command -v gh &> /dev/null; then
EXISTING_DASHBOARDS=$(gh issue list --label "dashboard,dependencies" --state open --json number,title,url --jq length 2>/dev/null || echo "0")
echo "Found $EXISTING_DASHBOARDS existing dashboard issue(s)"
if [ "$EXISTING_DASHBOARDS" -gt 1 ]; then
echo "β οΈ WARNING: Multiple dashboard issues detected!"
gh issue list --label "dashboard,dependencies" --state open --json number,title,url --jq '.[] | " - #\(.number): \(.title) - \(.url)"' 2>/dev/null || true
echo ""
echo "π§ Buddy Bot will attempt to update the most recent one and may close duplicates"
elif [ "$EXISTING_DASHBOARDS" -eq 1 ]; then
DASHBOARD_INFO=$(gh issue list --label "dashboard,dependencies" --state open --json number,title,url --jq '.[0] | "#\(.number): \(.title) - \(.url)"' 2>/dev/null || echo "Found 1 dashboard")
echo "β
Found existing dashboard: $DASHBOARD_INFO"
else
echo "βΉοΈ No existing dashboard found - a new one will be created"
fi
else
echo "β οΈ GitHub CLI not available - cannot perform pre-flight check"
fi
- name: Update Dependency Dashboard
run: |
PIN="${{ github.event.inputs.pin || 'true' }}"
TITLE="${{ github.event.inputs.title }}"
ISSUE_NUMBER="${{ github.event.inputs.issue_number }}"
VERBOSE="${{ github.event.inputs.verbose || 'true' }}"
DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}"
echo "π Updating dependency dashboard..."
echo "Pin: $PIN"
echo "Title: ${TITLE:-default}"
echo "Issue Number: ${ISSUE_NUMBER:-auto-detect}"
echo "Verbose: $VERBOSE"
echo "Dry Run: $DRY_RUN"
echo ""
set -e # Exit on any error
# Build the command
COMMAND="bunx buddy-bot dashboard"
if [ "$TITLE" != "" ]; then
COMMAND="$COMMAND --title \"$TITLE\""
fi
if [ "$ISSUE_NUMBER" != "" ]; then
COMMAND="$COMMAND --issue-number \"$ISSUE_NUMBER\""
fi
if [ "$VERBOSE" = "true" ]; then
COMMAND="$COMMAND --verbose"
fi
if [ "$DRY_RUN" = "true" ]; then
echo "π DRY RUN MODE - Command that would be executed:"
echo "$COMMAND"
echo ""
echo "βΉοΈ In dry run mode, dashboard content would be generated but no issue would be created/updated"
# Run scan to show what would be included
echo "π Scanning for dependencies that would be included:"
if [ "$VERBOSE" = "true" ]; then
bunx buddy-bot scan --verbose
else
bunx buddy-bot scan
fi
else
echo "π Executing dashboard update:"
echo "$COMMAND"
echo ""
eval "$COMMAND"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUDDY_BOT_TOKEN: ${{ secrets.BUDDY_BOT_TOKEN }}
- name: Dry run notification
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "βΉοΈ **Dry Run Mode** - Dashboard preview completed"
echo "To actually update the dashboard, run this workflow again with 'Dry run' set to false"
- name: Check dashboard status
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
echo "β
Dashboard update completed"
echo "π Check your repository issues for the updated dependency dashboard"
# Try to find and link to the dashboard issue
echo "π Looking for dependency dashboard issue..."
# Use GitHub CLI to find the dashboard issue
if command -v gh &> /dev/null; then
DASHBOARD_URL=$(gh issue list --label "dashboard,dependencies" --state open --limit 1 --json url --jq '.[0].url' 2>/dev/null || echo "")
if [ "$DASHBOARD_URL" != "null" ] && [ "$DASHBOARD_URL" != "" ]; then
echo "π― Dashboard found: $DASHBOARD_URL"
else
echo "π Dashboard issue not found via CLI, check issues manually"
fi
else
echo "π‘ Check your issues tab for the dependency dashboard"
fi
- name: Create dashboard summary
if: always()
run: |
echo "## π Dependency Dashboard Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Pin Dashboard**: ${{ github.event.inputs.pin || 'true' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Custom Title**: ${{ github.event.inputs.title || 'default' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Issue Number**: ${{ github.event.inputs.issue_number || 'auto-detect' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Triggered by**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry run**: ${{ github.event.inputs.dry_run || 'false' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Verbose**: ${{ github.event.inputs.verbose || 'true' }}" >> $GITHUB_STEP_SUMMARY
echo "- **Time**: $(date)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event_name }}" = "schedule" ]; then
echo "β° **Scheduled Update**: This was triggered automatically" >> $GITHUB_STEP_SUMMARY
echo "π **Schedule**: Every 2 hours, 15 minutes after dependency updates" >> $GITHUB_STEP_SUMMARY
echo "π‘ **Tip**: Use 'Actions' tab to manually trigger with custom settings" >> $GITHUB_STEP_SUMMARY
else
echo "π±οΈ **Manual Trigger**: This was triggered manually from the Actions tab" >> $GITHUB_STEP_SUMMARY
echo "β° **Auto-Schedule**: This workflow also runs automatically on schedule" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "π **Dry Run**: No changes were made. Dashboard content was previewed only." >> $GITHUB_STEP_SUMMARY
else
echo "β
**Dashboard Updated**: Check your repository issues for the updated dependency dashboard." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "π View detailed logs above for dashboard update results." >> $GITHUB_STEP_SUMMARY