Skip to content

Commit 4691d0b

Browse files
committed
Merge Dependabot PRs instead of closing
This PR changes the way Dependabot PR's appear in a repository history. Currently their changes are applied only to the base branch and the PR itself is closed. Instead of closing the PR we can reset its branch to the updated base branch. Github will detect this change and mark the PR as "merged" instead of "closed". This technique has been tested on my personal repo: https://github.com/copernik-eu/log4j-plugins/actions/runs/7219181183
1 parent 6aa28cb commit 4691d0b

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

.github/workflows/merge-dependabot-reusable.yaml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,12 @@ jobs:
5555
DEPENDENCY_NAMES: ${{ steps.dependabot-metadata.outputs.dependency-names }}
5656
DEPENDENCY_VERSION: ${{ steps.dependabot-metadata.outputs.new-version }}
5757

58-
- name: Download patch
59-
shell: bash
60-
run: wget "$PATCH_URL" -O /tmp/patch
61-
env:
62-
PATCH_URL: ${{ github.event.pull_request.patch_url }}
63-
6458
- name: Checkout repository
6559
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1
6660
with:
67-
ref: ${{ steps.dependabot-metadata.outputs.target-branch }}
68-
69-
- name: Apply patch
70-
shell: bash
71-
run: git apply /tmp/patch
61+
ref: ${{ github.head_ref }}
62+
# Must include the merge-base between head and target branch.
63+
depth: 32
7264

7365
- name: Set up Java & GPG
7466
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # 4.0.0
@@ -83,6 +75,18 @@ jobs:
8375
server-password: NEXUS_PASSWORD
8476
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
8577

78+
- name: Rebase onto ${{ github.base_ref }}
79+
shell: bash
80+
run: |
81+
git config user.name "ASF Logging Services RM"
82+
git config user.email private@logging.apache.org
83+
# Prepare commit
84+
git fetch origin "+refs/heads/$BASE:refs/remotes/origin/$BASE"
85+
git rebase "origin/$BASE"
86+
git reset HEAD~1
87+
env:
88+
BASE: ${{ github.base_ref }}
89+
8690
- name: Find the release version major
8791
shell: bash
8892
run: |
@@ -127,18 +131,10 @@ jobs:
127131
- name: Add & commit changes
128132
shell: bash
129133
run: |
130-
git add .
131-
git config user.name "ASF Logging Services RM"
132-
git config user.email private@logging.apache.org
133-
git commit -S -a -m "Update \`$DEPENDENCY_NAME\` to version \`$DEPENDENCY_VERSION\` (#$PR_ID)"
134-
git push origin
135-
COMMIT_ID=$(git rev-parse HEAD)
136-
echo "COMMIT_ID=$COMMIT_ID" >> $GITHUB_ENV
134+
git commit -S --amend -a -m "Update \`$DEPENDENCY_NAME\` to version \`$DEPENDENCY_VERSION\` (#$PR_ID)"
135+
# First push to base branch
136+
git push origin "HEAD:$BASE"
137+
# Update PR branch: Github will close it and mark as merged
138+
git push -f
137139
env:
138-
PR_ID: ${{ github.event.pull_request.number }}
139-
140-
- name: Close the PR
141-
run: gh pr close "$PR_URL" -c "Changes are applied by CI in $COMMIT_ID"
142-
env:
143-
PR_URL: ${{ github.event.pull_request.html_url }}
144-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140+
BASE: ${{ github.base_ref }}

0 commit comments

Comments
 (0)