fix(ci): enqueue merge queue as seahaven-bot

This commit is contained in:
Adam Moussa 2026-08-24 11:04:42 -04:00
parent f7d47d7ae8
commit a11cee3a04
No known key found for this signature in database

View file

@ -4,14 +4,15 @@ on:
pull_request:
types: [opened, ready_for_review, reopened, synchronize]
branches: [main]
pull_request_review:
types: [submitted]
concurrency:
group: enable-auto-merge-${{ github.event.pull_request.number }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
contents: read
jobs:
enable:
@ -20,25 +21,47 @@ jobs:
&& github.event.pull_request.head.repo.full_name == github.repository
&& github.event.pull_request.user.login != 'dependabot[bot]'
&& github.event.pull_request.user.login != 'renovate[bot]'
&& (github.event_name != 'pull_request_review' || github.event.review.state == 'approved')
runs-on: ubuntu-latest
steps:
- name: Enable squash auto-merge
- name: Mint seahaven-bot token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: ${{ secrets.SEAHAVEN_BOT_APP_ID }}
private-key: ${{ secrets.SEAHAVEN_BOT_PRIVATE_KEY }}
owner: Sea-Haven-Industries
repositories: ${{ github.event.repository.name }}
- name: Enqueue or arm auto-merge
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
PR_NODE_ID: ${{ github.event.pull_request.node_id }}
run: |
set -euo pipefail
if [ "$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest != null')" = "true" ]; then
echo "auto-merge already enabled"
in_queue="$(gh api graphql -f query='query($id:ID!) { node(id:$id) { ... on PullRequest { isInMergeQueue } } }' -f id="$PR_NODE_ID" --jq '.data.node.isInMergeQueue')"
if [ "$in_queue" = "true" ]; then
echo "already in merge queue"
exit 0
fi
if ! out=$(gh pr merge "$PR" --repo "$REPO" --auto 2>&1); then
echo "$out"
set +e
out="$(gh api graphql -f query='mutation($id:ID!) { enqueuePullRequest(input:{pullRequestId:$id}) { mergeQueueEntry { state } } }' -f id="$PR_NODE_ID" 2>&1)"
status=$?
set -e
if [ "$status" -eq 0 ]; then
printf '%s\n' "$out"
exit 0
fi
echo "$out"
# Re-arm as seahaven-bot. A leftover GITHUB_TOKEN auto-merge would
# enqueue without starting merge_group.
gh pr merge "$PR" --repo "$REPO" --disable-auto || true
if ! gh pr merge "$PR" --repo "$REPO" --auto; then
if [ "$(gh pr view "$PR" --repo "$REPO" --json autoMergeRequest --jq '.autoMergeRequest != null')" = "true" ]; then
echo "auto-merge already enabled"
exit 0
fi
exit 1
fi
printf '%s\n' "$out"