Skip to content

Auto-merge Bot PRs #355

Auto-merge Bot PRs

Auto-merge Bot PRs #355

Workflow file for this run

# Copyright Contributors to the KubeOpenCode project
name: Auto-merge Bot PRs
on:
# Daily schedule to process any pending bot PRs
schedule:
- cron: '0 0 * * *' # Every day at midnight UTC
# Trigger on approval for kubeopencode-dev PRs
pull_request_review:
types: [submitted]
# Manual trigger for batch processing
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
auto-merge:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Auto-merge bot PRs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
merge_pr() {
local pr_number=$1
local pr_title=$2
echo "Processing PR #$pr_number: $pr_title"
# Direct merge - squash commits and delete branch
if gh pr merge "$pr_number" --squash --delete-branch; then
echo "Successfully merged PR #$pr_number"
else
echo "Failed to merge PR #$pr_number"
fi
}
# Handle pull_request_review event (approval for kubeopencode-dev PRs)
if [ "${{ github.event_name }}" = "pull_request_review" ]; then
if [ "${{ github.event.review.state }}" != "approved" ]; then
echo "Not an approval, skipping"
exit 0
fi
PR_NUMBER=${{ github.event.pull_request.number }}
AUTHOR="${{ github.event.pull_request.user.login }}"
TITLE="${{ github.event.pull_request.title }}"
# Only process kubeopencode-dev PRs on approval
if [[ "$AUTHOR" == "kubeopencode-dev[bot]" ]]; then
echo "kubeopencode-dev PR #$PR_NUMBER approved, checking CI status..."
# Check if all checks passed
CHECKS_PASSED=$(gh pr view "$PR_NUMBER" --json statusCheckRollup --jq '[.statusCheckRollup[] | select(.conclusion != "SUCCESS" and .conclusion != "NEUTRAL" and .conclusion != "SKIPPED" and .conclusion != null and .name != "auto-merge")] | length == 0')
if [ "$CHECKS_PASSED" = "true" ]; then
merge_pr "$PR_NUMBER" "$TITLE"
else
echo "CI checks not passed yet, skipping"
fi
else
echo "Not a kubeopencode-dev PR, skipping"
fi
exit 0
fi
# schedule or workflow_dispatch: batch process all open bot PRs
echo "Batch processing all open bot PRs..."
# Dependabot PRs: merge all with passing checks
echo "Processing Dependabot PRs..."
gh pr list --author "app/dependabot" --state open --json number,title,statusCheckRollup | jq -c '.[] | select([.statusCheckRollup[] | select(.conclusion != "SUCCESS" and .conclusion != "NEUTRAL" and .conclusion != "SKIPPED" and .conclusion != null and .name != "auto-merge")] | length == 0)' | while read -r pr; do
number=$(echo "$pr" | jq -r '.number')
title=$(echo "$pr" | jq -r '.title')
merge_pr "$number" "$title"
done
# kubeopencode-dev PRs: merge approved ones with passing checks
echo "Processing kubeopencode-dev PRs..."
gh pr list --author "app/kubeopencode-dev" --state open --json number,title,reviews,statusCheckRollup | jq -c '.[] | select([.reviews[] | select(.state == "APPROVED")] | length > 0) | select([.statusCheckRollup[] | select(.conclusion != "SUCCESS" and .conclusion != "NEUTRAL" and .conclusion != "SKIPPED" and .conclusion != null and .name != "auto-merge")] | length == 0)' | while read -r pr; do
number=$(echo "$pr" | jq -r '.number')
title=$(echo "$pr" | jq -r '.title')
merge_pr "$number" "$title"
done
echo "Batch processing complete"