Skip to content

Commit 88961d6

Browse files
committed
Fix: Add PR branch update before auto-merge to prevent base branch conflicts
1 parent 171f9a2 commit 88961d6

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/dependabot-auto-merge.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ jobs:
3030
PR_URL: ${{ github.event.pull_request.html_url }}
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3232

33+
- name: Update PR branch
34+
run: |
35+
# Update the PR branch with the latest from base branch
36+
gh pr update-branch "$PR_URL" || echo "Branch already up to date or cannot be updated"
37+
env:
38+
PR_URL: ${{ github.event.pull_request.html_url }}
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
3341
- name: Enable auto-merge for Dependabot PRs
3442
run: gh pr merge --auto --squash "$PR_URL"
3543
env:
@@ -82,6 +90,15 @@ jobs:
8290
console.log(`PR #${prNumber} is from Dependabot: ${isDependabot}`);
8391
return isDependabot;
8492
93+
- name: Update PR branch
94+
if: steps.check-dependabot.outputs.result == 'true'
95+
env:
96+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
run: |
98+
PR_NUMBER=${{ steps.pr.outputs.result }}
99+
# Update the PR branch with the latest from base branch
100+
gh pr update-branch $PR_NUMBER --repo ${{ github.repository }} || echo "Branch already up to date or cannot be updated"
101+
85102
- name: Merge PR
86103
if: steps.check-dependabot.outputs.result == 'true'
87104
env:

.github/workflows/dependabot-automerge.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ jobs:
3131
wait-interval: 30
3232
allowed-conclusions: success,skipped,neutral
3333

34+
- name: Update PR branch
35+
if: |
36+
steps.wait-for-checks.outcome == 'success' &&
37+
(steps.metadata.outputs.update-type == 'version-update:semver-patch' ||
38+
steps.metadata.outputs.update-type == 'version-update:semver-minor')
39+
run: |
40+
# Update the PR branch with the latest from base branch
41+
gh pr update-branch "$PR_URL" || echo "Branch already up to date or cannot be updated"
42+
env:
43+
PR_URL: ${{ github.event.pull_request.html_url }}
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
3446
- name: Enable auto-merge for Dependabot PRs
3547
if: |
3648
steps.wait-for-checks.outcome == 'success' &&

0 commit comments

Comments
 (0)