chore: auto-merge sync PR when no conflicts
This commit is contained in:
parent
44d96c3d4b
commit
49b1d054f3
1 changed files with 34 additions and 17 deletions
51
.github/workflows/sync-fork.yml
vendored
51
.github/workflows/sync-fork.yml
vendored
|
|
@ -18,26 +18,43 @@ jobs:
|
|||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Create PR from main to my-custom-setup
|
||||
- name: Create and auto-merge PR from main to my-custom-setup
|
||||
run: |
|
||||
# Check if main has commits not in my-custom-setup
|
||||
BEHIND=$(gh api repos/${{ github.repository }}/compare/my-custom-setup...main --jq '.ahead_by')
|
||||
if [ "$BEHIND" -le 0 ] 2>/dev/null; then
|
||||
echo "No new upstream commits — nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if there's already an open PR from main to my-custom-setup
|
||||
EXISTING=$(gh pr list --repo ${{ github.repository }} --base my-custom-setup --head main --state open --json number --jq '.[0].number')
|
||||
if [ -n "$EXISTING" ]; then
|
||||
echo "PR #$EXISTING already open — skipping."
|
||||
EXISTING=$(gh pr list --repo ${{ github.repository }} --base my-custom-setup --head main --state open --json number,mergeable --jq '.[0]')
|
||||
PR_NUM=$(echo "$EXISTING" | jq -r '.number // empty')
|
||||
|
||||
if [ -z "$PR_NUM" ]; then
|
||||
# Create the PR
|
||||
PR_URL=$(gh pr create \
|
||||
--repo ${{ github.repository }} \
|
||||
--base my-custom-setup \
|
||||
--head main \
|
||||
--title "Sync upstream changes into my-custom-setup" \
|
||||
--body "Automated PR to merge latest upstream changes from \`main\` into \`my-custom-setup\`.")
|
||||
PR_NUM=$(echo "$PR_URL" | grep -oP '\d+$')
|
||||
echo "Created PR #$PR_NUM"
|
||||
else
|
||||
# Check if main has commits not in my-custom-setup
|
||||
BEHIND=$(gh api repos/${{ github.repository }}/compare/my-custom-setup...main --jq '.ahead_by')
|
||||
if [ "$BEHIND" -gt 0 ] 2>/dev/null; then
|
||||
gh pr create \
|
||||
--repo ${{ github.repository }} \
|
||||
--base my-custom-setup \
|
||||
--head main \
|
||||
--title "Sync upstream changes into my-custom-setup" \
|
||||
--body "Automated PR to merge latest upstream changes from \`main\` into \`my-custom-setup\`."
|
||||
echo "PR created."
|
||||
else
|
||||
echo "No new upstream commits — skipping PR."
|
||||
fi
|
||||
echo "PR #$PR_NUM already open."
|
||||
fi
|
||||
|
||||
# Wait a moment for GitHub to compute mergeability
|
||||
sleep 10
|
||||
|
||||
# Check if the PR is mergeable (no conflicts)
|
||||
MERGEABLE=$(gh pr view "$PR_NUM" --repo ${{ github.repository }} --json mergeable --jq '.mergeable')
|
||||
if [ "$MERGEABLE" = "MERGEABLE" ]; then
|
||||
gh pr merge "$PR_NUM" --repo ${{ github.repository }} --merge --auto
|
||||
echo "PR #$PR_NUM auto-merged."
|
||||
else
|
||||
echo "PR #$PR_NUM has conflicts (status: $MERGEABLE) — leaving open for manual resolution."
|
||||
fi
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue