Skip to content

Commit c89f72d

Browse files
authored
update dependabot autocommit (#416)
Use an app for the source of the token Rather than issuing a merge command to dependabot set the PR to auto squash Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 262a159 commit c89f72d

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,33 @@ permissions:
1010
contents: write
1111
pull-requests: write
1212

13+
# This workflow uses a GitHub App token to approve and merge Dependabot PRs
14+
# The token is created using the `actions/create-github-app-token` action
15+
# The token is used so that the updates are made by the GitHub App instead of Github Actions
16+
# and will show up as such in the PR comments and history
17+
# In addition, the token is scoped to only the permissions needed for this workflow
18+
# see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow for details
19+
1320
jobs:
1421
auto-merge-dependabot:
1522
runs-on: ubuntu-latest
1623
steps:
24+
25+
# Gets the GitHub App token
26+
- uses: actions/create-github-app-token@v2
27+
id: get-app-token
28+
with:
29+
# required
30+
app-id: ${{ secrets.DEPENDABOT_APP_ID }}
31+
private-key: ${{ secrets.DEPENDABOT_APP_KEY }}
32+
permission-pull-requests: write
33+
permission-contents: write
34+
1735
- name: Checkout code
1836
uses: actions/checkout@v4
37+
with:
38+
token: ${{ steps.get-app-token.outputs.token }}
39+
persist-credentials: false
1940

2041
- name: Setup GitHub CLI
2142
run: |
@@ -27,5 +48,5 @@ jobs:
2748

2849
- name: Run auto approve script
2950
env:
30-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
GITHUB_TOKEN: ${{ steps.get-app-token.outputs.token }}
3152
run: ./dev/auto-approve-dependabot.sh ${{ github.repository }}

dev/auto-approve-dependabot.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,19 @@ echo "$dependabot_prs" | jq -c '.[]' | while read -r pr; do
111111
fi
112112

113113
if [ "$has_pending_checks" = true ] || [ "$all_checks_pass" = true ]; then
114-
echo " ✅ Adding merge comment to PR #$pr_number"
115-
gh pr comment "$pr_number" -R "$REPO" -b "@dependabot merge"
116-
echo " ✅ Merge command issued for PR #$pr_number"
114+
# Check if PR is up-to-date with base branch
115+
merge_status=$(gh pr view "$pr_number" -R "$REPO" --json mergeStateStatus -q '.mergeStateStatus')
116+
117+
if [ "$merge_status" != "CLEAN" ]; then
118+
echo " ⚠️ PR #$pr_number is not up to date (status: $merge_status)"
119+
else
120+
echo " ✅ PR #$pr_number is up to date with base branch"
121+
fi
122+
123+
# Enable auto-merge with squash strategy
124+
echo " ✅ Enabling auto-merge (squash strategy) for PR #$pr_number"
125+
gh pr merge "$pr_number" -R "$REPO" --auto --squash
126+
echo " ✅ Auto-merge enabled for PR #$pr_number"
117127
fi
118128

119129
done

0 commit comments

Comments
 (0)