Skip to content

Add auto merge #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/auto_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Auto Approve and Merge

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch: # Add manual trigger for testing

jobs:
debug-context:
runs-on: ubuntu-latest
# Always run this job to see what's happening
steps:
- name: Debug PR Context
run: |
echo "Event Name: ${{ github.event_name }}"
echo "PR Title: ${{ github.event.pull_request.title }}"
echo "PR Number: ${{ github.event.pull_request.number }}"
echo "PR State: ${{ github.event.pull_request.state }}"
echo "Is Draft: ${{ github.event.pull_request.draft }}"
echo "Base Branch: ${{ github.event.pull_request.base.ref }}"
echo "Head Branch: ${{ github.event.pull_request.head.ref }}"
echo "Contains check: ${{ contains(github.event.pull_request.title, 'Auto-merge workflow') }}"

auto-approve-merge:
runs-on: ubuntu-latest
# TODO: restore condition
if: contains(github.event.pull_request.title, 'Auto-merge workflow')

steps:
- name: Check conditions
run: |
echo "🔍 Checking if should auto-merge..."
echo "PR Title: '${{ github.event.pull_request.title }}'"

if [[ "${{ github.event.pull_request.title }}" == *"Auto-merge workflow"* ]]; then
echo "✅ Title contains 'Auto-merge workflow' - proceeding"
else
echo "❌ Title does not contain 'Auto-merge workflow' - would skip"
exit 0 # Don't fail, just skip
fi

- name: Auto approve and merge
if: contains(github.event.pull_request.title, 'Auto-merge workflow')
run: |
echo "Auto-merging PR #${{ github.event.pull_request.number }}"

# Approve
gh pr review ${{ github.event.pull_request.number }} --approve

# Enable auto-merge
gh pr merge ${{ github.event.pull_request.number }} --auto --merge --delete-branch
env:
GH_TOKEN: ${{ secrets.AUTO_MERGE_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/test_auto_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Create Test PR
on:
workflow_dispatch:
push:
branches: [auto-approve-merge]

jobs:
create-test-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Create test PR
run: |
# Configure git identity
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

# Create branch with test file
BRANCH_NAME="test-auto-merge-${{ github.run_number }}"
git checkout -b $BRANCH_NAME
echo "Test $(date)" > test.txt
git add test.txt
git commit -m "test: auto-merge"
git push origin $BRANCH_NAME

# Create PR
gh pr create \
--base auto-approve-merge \
--title "Test: Auto-merge workflow" \
--body "Testing auto-merge functionality"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}