-
Notifications
You must be signed in to change notification settings - Fork 4
747 lines (617 loc) · 33.7 KB
/
Copy pathcreate-pr.yml
File metadata and controls
747 lines (617 loc) · 33.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
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
name: Auto PR Creation
on:
push:
branches:
- "dev/*"
- "develop"
- "test"
- "ai/dev/*"
- "ai/test/*"
- "ai/checklist/*"
permissions:
contents: write
pull-requests: write
jobs:
pr-to-develop:
name: Create/Update PR from dev/* → develop
if: startsWith(github.ref, 'refs/heads/dev/') && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base develop --head ${{ github.ref_name }} --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if develop branch exists
id: check-branch
run: |
git fetch origin --prune
if git ls-remote --heads origin develop | grep -q "refs/heads/develop"; then
echo "Develop branch exists on remote"
echo "needs_branch_creation=false" >> $GITHUB_OUTPUT
else
echo "Develop branch doesn't exist → needs creation"
echo "needs_branch_creation=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create develop branch if it doesn't exist
if: steps.check-branch.outputs.needs_branch_creation == 'true' && steps.check-pr.outputs.pr_exists == '0'
run: |
# Try to create develop branch from main, fallback to current branch if main doesn't exist
if git ls-remote --heads origin main | grep -q "refs/heads/main"; then
git fetch origin main:main
git checkout -b develop main
echo "Created develop branch from main"
else
echo "Main branch doesn't exist, creating develop from current branch"
git checkout -b develop
fi
git push origin develop
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
# Now check for differences between current dev branch and develop (develop branch should exist now)
# Switch back to the original dev branch first
git checkout ${{ github.ref_name }}
# Fetch develop branch without checking it out
git fetch origin develop
COMMITS_AHEAD=$(git rev-list --count origin/develop..HEAD)
COMMITS_BEHIND=$(git rev-list --count HEAD..origin/develop)
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "${{ github.ref_name }} is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind develop"
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
# Count TODOs in the codebase
TODO_COUNT=$(grep -r " TODO:" \
--include="*.ts" --include="*.js" --include="*.tsx" --include="*.jsx" \
--include="*.vue" --include="*.py" --include="*.java" --include="*.cs" \
--include="*.go" --include="*.rs" --include="*.cpp" --include="*.c" \
--include="*.h" . | wc -l || echo "0")
echo "todo_count=$TODO_COUNT" >> $GITHUB_OUTPUT
echo "Found $TODO_COUNT TODOs in the codebase"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base develop \
--head ${{ github.ref_name }} \
--title "🔄 Auto-PR: Merge \`${{ github.ref_name }}\` → \`develop\`" \
--body "**Automated Pull Request** 🤖
This PR was automatically created to merge changes from \`${{ github.ref_name }}\` into \`develop\`.
**Changes:**
- Commits ahead of develop: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind develop: ${{ steps.check-diff.outputs.commits_behind }}
- TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}
**Review:** Please review the changes before merging."
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Skip PR creation - no changes
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'false'
run: |
echo "⏭️ Skipping PR creation - no new commits in ${{ github.ref_name }} compared to develop"
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
echo "PR from ${{ github.ref_name }} to develop already exists. Updating with latest info..."
# Get the PR number
PR_NUMBER=$(gh pr list --base develop --head ${{ github.ref_name }} --state open --json number --jq '.[0].number')
# Update PR body with current stats
gh pr edit $PR_NUMBER --body "**Automated Pull Request** 🤖
This PR was automatically created to merge changes from \`${{ github.ref_name }}\` into \`develop\`.
**Changes:**
- Commits ahead of develop: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind develop: ${{ steps.check-diff.outputs.commits_behind }}
- TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}
**Review:** Please review the changes before merging.
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
echo "Updated PR #$PR_NUMBER with latest commit and TODO counts"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
pr-to-test:
name: Create/Update PR from develop → test
if: github.ref == 'refs/heads/develop' && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base test --head develop --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if test branch exists
id: check-branch
run: |
git fetch origin --prune
if git ls-remote --heads origin test | grep -q "refs/heads/test"; then
echo "Test branch exists on remote"
echo "needs_branch_creation=false" >> $GITHUB_OUTPUT
else
echo "Test branch doesn't exist → needs creation"
echo "needs_branch_creation=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create test branch if it doesn't exist
if: steps.check-branch.outputs.needs_branch_creation == 'true' && steps.check-pr.outputs.pr_exists == '0'
run: |
# Try to create test branch from main, fallback to develop if main doesn't exist
if git ls-remote --heads origin main | grep -q "refs/heads/main"; then
git fetch origin main:main
git checkout -b test main
echo "Created test branch from main"
else
echo "Main branch doesn't exist, creating test from develop"
git checkout -b test develop
fi
git push origin test
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
# Now check for differences between develop and test (test branch should exist now)
# Switch back to develop branch first
git checkout develop
# Fetch test branch without checking it out
git fetch origin test
COMMITS_AHEAD=$(git rev-list --count origin/test..HEAD)
COMMITS_BEHIND=$(git rev-list --count HEAD..origin/test)
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "Develop is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind test"
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
# Count TODOs in the codebase
TODO_COUNT=$(grep -r " TODO:" --include="*.ts" --include="*.js" --include="*.tsx" --include="*.jsx" --include="*.vue" --include="*.py" --include="*.java" --include="*.cs" --include="*.go" --include="*.rs" --include="*.cpp" --include="*.c" --include="*.h" . | wc -l || echo "0")
echo "todo_count=$TODO_COUNT" >> $GITHUB_OUTPUT
echo "Found $TODO_COUNT TODOs in the codebase"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base test \
--head develop \
--title "🧪 Auto-PR: Merge \`develop\` → \`test\`" \
--body "**Automated Pull Request** 🤖
Commits ahead of test: ${{ steps.check-diff.outputs.commits_ahead }}
Commits behind test: ${{ steps.check-diff.outputs.commits_behind }}
TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Skip PR creation – no changes
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'false'
run: echo "⏭️ No new commits in develop compared to test"
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
echo "PR from develop to test already exists. Updating with latest info..."
# Get the PR number
PR_NUMBER=$(gh pr list --base test --head develop --state open --json number --jq '.[0].number')
# Update PR body with current stats
gh pr edit $PR_NUMBER --body "**Automated Pull Request** 🤖
Commits ahead of test: ${{ steps.check-diff.outputs.commits_ahead }}
Commits behind test: ${{ steps.check-diff.outputs.commits_behind }}
TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
echo "Updated PR #$PR_NUMBER with latest commit and TODO counts"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
pr-to-main:
name: Create/Update PR from test → main
if: github.ref == 'refs/heads/test' && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base main --head test --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
# Fetch all branches to ensure we have the latest refs
git fetch origin --prune
# Check if main branch exists on remote
if git ls-remote --heads origin main | grep -q "refs/heads/main"; then
echo "Main branch exists on remote"
git fetch origin main:main
# Check if there are any commits between main and test
COMMITS_AHEAD=$(git rev-list --count main..test)
COMMITS_BEHIND=$(git rev-list --count test..main)
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "Branch test is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind main"
# Only create PR if we have commits to contribute
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
else
echo "Main branch doesn't exist on remote, this will be the first PR to create main"
echo "commits_ahead=1" >> $GITHUB_OUTPUT
echo "commits_behind=0" >> $GITHUB_OUTPUT
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
# Count TODOs in the codebase
TODO_COUNT=$(grep -r " TODO:" --include="*.ts" --include="*.js" --include="*.tsx" --include="*.jsx" --include="*.vue" --include="*.py" --include="*.java" --include="*.cs" --include="*.go" --include="*.rs" --include="*.cpp" --include="*.c" --include="*.h" . | wc -l || echo "0")
echo "todo_count=$TODO_COUNT" >> $GITHUB_OUTPUT
echo "Found $TODO_COUNT TODOs in the codebase"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base main \
--head test \
--title "🚀 Auto-PR: Merge \`test\` → \`main\`" \
--body "**Automated Pull Request** 🤖
This PR was automatically created to merge changes from \`test\` into \`main\`.
**Changes:**
- Commits ahead of main: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind main: ${{ steps.check-diff.outputs.commits_behind }}
- TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}
**Review:** Please review the changes before merging."
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Skip PR creation - no changes
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'false'
run: |
echo "⏭️ Skipping PR creation - no new commits in test compared to main"
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
echo "PR from test to main already exists. Updating with latest info..."
# Get the PR number
PR_NUMBER=$(gh pr list --base main --head test --state open --json number --jq '.[0].number')
# Update PR body with current stats
gh pr edit $PR_NUMBER --body "**Automated Pull Request** 🤖
This PR was automatically created to merge changes from \`test\` into \`main\`.
**Changes:**
- Commits ahead of main: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind main: ${{ steps.check-diff.outputs.commits_behind }}
- TODOs remaining in codebase: ${{ steps.check-diff.outputs.todo_count }}
**Review:** Please review the changes before merging.
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
echo "Updated PR #$PR_NUMBER with latest commit and TODO counts"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
ai-dev-to-ai-test:
name: Create/Update PR from ai/dev/* → ai/test/*
if: startsWith(github.ref, 'refs/heads/ai/dev/') && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract branch name
id: extract-branch
run: |
# Extract the branch name after ai/dev/
BRANCH_NAME=${{ github.ref_name }}
TARGET_BRANCH="ai/test/${BRANCH_NAME#ai/dev/}"
echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT
echo "Target branch: $TARGET_BRANCH"
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if target branch exists
id: check-branch
run: |
git fetch origin --prune
if git ls-remote --heads origin ${{ steps.extract-branch.outputs.target_branch }} | grep -q "refs/heads/${{ steps.extract-branch.outputs.target_branch }}"; then
echo "Target branch exists on remote"
echo "needs_branch_creation=false" >> $GITHUB_OUTPUT
else
echo "Target branch doesn't exist → needs creation"
echo "needs_branch_creation=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create target branch if it doesn't exist
if: steps.check-branch.outputs.needs_branch_creation == 'true' && steps.check-pr.outputs.pr_exists == '0'
run: |
# Create target ai/test branch from current ai/dev branch
git checkout -b ${{ steps.extract-branch.outputs.target_branch }}
git push origin ${{ steps.extract-branch.outputs.target_branch }}
echo "Created ${{ steps.extract-branch.outputs.target_branch }} branch from current ai/dev branch"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
git checkout ${{ github.ref_name }}
git fetch origin ${{ steps.extract-branch.outputs.target_branch }}
COMMITS_AHEAD=$(git rev-list --count origin/${{ steps.extract-branch.outputs.target_branch }}..HEAD)
COMMITS_BEHIND=$(git rev-list --count HEAD..origin/${{ steps.extract-branch.outputs.target_branch }})
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "${{ github.ref_name }} is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind ${{ steps.extract-branch.outputs.target_branch }}"
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base ${{ steps.extract-branch.outputs.target_branch }} \
--head ${{ github.ref_name }} \
--title "🤖 AI-PR: Merge \`${{ github.ref_name }}\` → \`${{ steps.extract-branch.outputs.target_branch }}\`" \
--body "**AI-Generated Pull Request** 🤖
This PR was automatically created to merge AI-enhanced changes from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-generated code - please review carefully before merging."
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
PR_NUMBER=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq '.[0].number')
gh pr edit $PR_NUMBER --body "**AI-Generated Pull Request** 🤖
This PR was automatically created to merge AI-enhanced changes from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-generated code - please review carefully before merging.
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
ai-test-to-dev:
name: Create/Update PR from ai/test/* → dev/*
if: startsWith(github.ref, 'refs/heads/ai/test/') && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract branch name
id: extract-branch
run: |
# Extract the branch name after ai/test/
BRANCH_NAME=${{ github.ref_name }}
TARGET_BRANCH="dev/${BRANCH_NAME#ai/test/}"
echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT
echo "Target branch: $TARGET_BRANCH"
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if target branch exists
id: check-branch
run: |
git fetch origin --prune
if git ls-remote --heads origin ${{ steps.extract-branch.outputs.target_branch }} | grep -q "refs/heads/${{ steps.extract-branch.outputs.target_branch }}"; then
echo "Target branch exists on remote"
echo "needs_branch_creation=false" >> $GITHUB_OUTPUT
else
echo "Target branch doesn't exist → needs creation"
echo "needs_branch_creation=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create target branch if it doesn't exist
if: steps.check-branch.outputs.needs_branch_creation == 'true' && steps.check-pr.outputs.pr_exists == '0'
run: |
# Create target dev branch from develop if it exists, otherwise from main
if git ls-remote --heads origin develop | grep -q "refs/heads/develop"; then
git fetch origin develop:develop
git checkout -b ${{ steps.extract-branch.outputs.target_branch }} develop
echo "Created ${{ steps.extract-branch.outputs.target_branch }} branch from develop"
elif git ls-remote --heads origin main | grep -q "refs/heads/main"; then
git fetch origin main:main
git checkout -b ${{ steps.extract-branch.outputs.target_branch }} main
echo "Created ${{ steps.extract-branch.outputs.target_branch }} branch from main"
else
echo "Neither develop nor main exists, creating from current branch"
git checkout -b ${{ steps.extract-branch.outputs.target_branch }}
fi
git push origin ${{ steps.extract-branch.outputs.target_branch }}
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
git checkout ${{ github.ref_name }}
git fetch origin ${{ steps.extract-branch.outputs.target_branch }}
COMMITS_AHEAD=$(git rev-list --count origin/${{ steps.extract-branch.outputs.target_branch }}..HEAD)
COMMITS_BEHIND=$(git rev-list --count HEAD..origin/${{ steps.extract-branch.outputs.target_branch }})
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "${{ github.ref_name }} is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind ${{ steps.extract-branch.outputs.target_branch }}"
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base ${{ steps.extract-branch.outputs.target_branch }} \
--head ${{ github.ref_name }} \
--title "🧪 AI-Test-PR: Merge \`${{ github.ref_name }}\` → \`${{ steps.extract-branch.outputs.target_branch }}\`" \
--body "**AI Test → Dev Pull Request** 🧪
This PR was automatically created to merge AI-generated test changes from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-generated tests and code - please review test coverage and implementation."
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
PR_NUMBER=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq '.[0].number')
gh pr edit $PR_NUMBER --body "**AI Test → Dev Pull Request** 🧪
This PR was automatically created to merge AI-generated test changes from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-generated tests and code - please review test coverage and implementation.
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
ai-checklist-to-ai-dev:
name: Create/Update PR from ai/checklist/* → ai/dev/*
if: startsWith(github.ref, 'refs/heads/ai/checklist/') && !contains(github.event.head_commit.message, '🔄 Update version') && !contains(github.event.head_commit.message, '🤖 Update client APIs') && !contains(github.event.head_commit.message, 'proxy-smart-releaser')
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract branch name
id: extract-branch
run: |
# Extract the branch name after ai/checklist/
BRANCH_NAME=${{ github.ref_name }}
TARGET_BRANCH="ai/dev/${BRANCH_NAME#ai/checklist/}"
echo "target_branch=$TARGET_BRANCH" >> $GITHUB_OUTPUT
echo "Target branch: $TARGET_BRANCH"
- name: Check if PR already exists
id: check-pr
run: |
PR_EXISTS=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq length)
echo "pr_exists=$PR_EXISTS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if target branch exists
id: check-branch
run: |
git fetch origin --prune
if git ls-remote --heads origin ${{ steps.extract-branch.outputs.target_branch }} | grep -q "refs/heads/${{ steps.extract-branch.outputs.target_branch }}"; then
echo "Target branch exists on remote"
echo "needs_branch_creation=false" >> $GITHUB_OUTPUT
else
echo "Target branch doesn't exist → needs creation"
echo "needs_branch_creation=true" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Create target branch if it doesn't exist
if: steps.check-branch.outputs.needs_branch_creation == 'true' && steps.check-pr.outputs.pr_exists == '0'
run: |
# Create target ai/dev branch from current ai/checklist branch
git checkout -b ${{ steps.extract-branch.outputs.target_branch }}
git push origin ${{ steps.extract-branch.outputs.target_branch }}
echo "Created ${{ steps.extract-branch.outputs.target_branch }} branch from ${{ github.ref_name }}"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Check if branches differ
id: check-diff
run: |
git checkout ${{ github.ref_name }}
git fetch origin ${{ steps.extract-branch.outputs.target_branch }}
COMMITS_AHEAD=$(git rev-list --count origin/${{ steps.extract-branch.outputs.target_branch }}..HEAD)
COMMITS_BEHIND=$(git rev-list --count HEAD..origin/${{ steps.extract-branch.outputs.target_branch }})
echo "commits_ahead=$COMMITS_AHEAD" >> $GITHUB_OUTPUT
echo "commits_behind=$COMMITS_BEHIND" >> $GITHUB_OUTPUT
echo "${{ github.ref_name }} is $COMMITS_AHEAD commits ahead and $COMMITS_BEHIND commits behind ${{ steps.extract-branch.outputs.target_branch }}"
if [ "$COMMITS_AHEAD" -gt 0 ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check-pr.outputs.pr_exists == '0' && steps.check-diff.outputs.has_changes == 'true'
run: |
gh pr create \
--base ${{ steps.extract-branch.outputs.target_branch }} \
--head ${{ github.ref_name }} \
--title "✅ AI-Checklist-PR: Merge \`${{ github.ref_name }}\` → \`${{ steps.extract-branch.outputs.target_branch }}\`" \
--body "**AI Checklist → Test Pull Request** ✅
This PR was automatically created to merge AI-implemented checklist items from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-implemented checklist features - please review implementation and prepare for testing."
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
- name: Update existing PR
if: steps.check-pr.outputs.pr_exists != '0'
run: |
PR_NUMBER=$(gh pr list --base ${{ steps.extract-branch.outputs.target_branch }} --head ${{ github.ref_name }} --state open --json number --jq '.[0].number')
gh pr edit $PR_NUMBER --body "**AI Checklist → Test Pull Request** ✅
This PR was automatically created to merge AI-implemented checklist items from \`${{ github.ref_name }}\` into \`${{ steps.extract-branch.outputs.target_branch }}\`.
**Changes:**
- Commits ahead of target: ${{ steps.check-diff.outputs.commits_ahead }}
- Commits behind target: ${{ steps.check-diff.outputs.commits_behind }}
**Review:** AI-implemented checklist features - please review implementation and prepare for testing.
_Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')_"
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}