Skip to content

Auto Merge All PRs

Auto Merge All PRs #3

name: Auto Merge All PRs
on:
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
merge-prs:
runs-on: ubuntu-latest
steps:
- name: Checkout base branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: merge-playground
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh jq
- name: Authenticate GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Merge all open PRs
run: |
set -e
BASE_BRANCH="merge-playground"
git config user.name "ved"
git config user.email "ved.pawar2024@nst.rishihood.edu.in"
# Ensure base branch is up to date
git checkout $BASE_BRANCH
git pull origin $BASE_BRANCH
# Get list of open PR numbers
prs=$(gh pr list --state open --json number --jq '.[].number')
for pr in $prs; do
echo "Merging PR #$pr..."
# Create a local branch for the PR
gh pr checkout $pr
# Capture the branch name
pr_branch=$(git rev-parse --abbrev-ref HEAD)
# Switch back to base branch
git checkout $BASE_BRANCH
# Merge PR branch with union strategy (keeps both sides of conflict)
git merge "$pr_branch" -m "Auto-merged PR #$pr" -X union --allow-unrelated-histories || true
# Push after each merge
git push origin $BASE_BRANCH
done