8484 needs : [load-env]
8585 runs-on : ubuntu-latest
8686 permissions :
87+ contents : write # Required: Enable auto-merge on PRs
8788 pull-requests : write # Required: Update and merge Dependabot PRs
8889 issues : write # Required: Comment on related dependency issues
89- # Note: contents write not needed - gh CLI uses token directly
9090 outputs :
9191 dependency-names : ${{ steps.metadata.outputs.dependency-names }}
9292 update-type : ${{ steps.metadata.outputs.update-type }}
@@ -387,6 +387,15 @@ jobs:
387387 DEPENDENCY="${{ steps.metadata.outputs.dependency-names }}"
388388 VERSION_CHANGE="${{ steps.metadata.outputs.previous-version }} → ${{ steps.metadata.outputs.new-version }}"
389389
390+ # Check token availability
391+ if [[ -n "${{ secrets.GH_PAT_TOKEN }}" ]]; then
392+ echo "🔑 Using Personal Access Token for enhanced permissions"
393+ TOKEN_TYPE="PAT"
394+ else
395+ echo "⚠️ Using default GITHUB_TOKEN - auto-merge may fail for Dependabot PRs"
396+ TOKEN_TYPE="GITHUB_TOKEN"
397+ fi
398+
390399 # Determine approval message based on action type
391400 case "$ACTION" in
392401 "auto-merge-patch")
@@ -407,13 +416,26 @@ jobs:
407416 esac
408417
409418 # Approve the PR
410- gh pr review --approve "$PR_URL" \
411- --body "$APPROVAL_MSG: $DEPENDENCY ($VERSION_CHANGE)"
419+ echo "📝 Approving PR..."
420+ if ! gh pr review --approve "$PR_URL" --body "$APPROVAL_MSG: $DEPENDENCY ($VERSION_CHANGE)"; then
421+ echo "❌ Failed to approve PR"
422+ exit 1
423+ fi
412424
413- # Enable auto-merge
414- gh pr merge --auto --squash "$PR_URL"
425+ # Attempt to enable auto-merge
426+ echo "🚀 Attempting to enable auto-merge..."
427+ if gh pr merge --auto --squash "$PR_URL"; then
428+ echo "✅ Successfully enabled auto-merge for $ACTION"
429+ else
430+ echo "⚠️ Auto-merge failed (likely permissions issue)"
431+ echo "💡 Tip: Ensure GH_PAT_TOKEN is set with repo permissions for Dependabot PRs"
432+
433+ # Fallback: Set up for manual merge
434+ echo "🔄 PR has been approved and is ready for manual merge"
435+ echo "action_result=approved-ready-for-merge" >> $GITHUB_OUTPUT
415436
416- echo "✅ Enabled auto-merge for $ACTION"
437+ # Don't exit with error - the PR is still approved
438+ fi
417439 env :
418440 PR_URL : ${{ github.event.pull_request.html_url }}
419441 GH_TOKEN : ${{ secrets.GH_PAT_TOKEN || secrets.GITHUB_TOKEN }}
@@ -519,6 +541,9 @@ jobs:
519541 "auto-merge-security")
520542 ACTION_DESC="🔒 Auto-merged (security update)"
521543 ;;
544+ "approved-ready-for-merge")
545+ ACTION_DESC="✅ Approved and ready for manual merge (auto-merge failed)"
546+ ;;
522547 "alert-major")
523548 ACTION_DESC="⚠️ Manual review required (major update)"
524549 ;;
@@ -577,6 +602,9 @@ jobs:
577602 auto-merge-*)
578603 echo "✅ Action: Auto-merge enabled"
579604 ;;
605+ approved-ready-for-merge)
606+ echo "✅ Action: Approved and ready for manual merge"
607+ ;;
580608 alert-*)
581609 echo "⚠️ Action: Alert sent, manual review required"
582610 ;;
0 commit comments