mirror of
https://github.com/Sea-Haven-Industries/syslog-server.git
synced 2026-09-30 08:53:16 +00:00
67 lines
2.5 KiB
YAML
67 lines
2.5 KiB
YAML
name: Enable auto-merge
|
|
|
|
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: read
|
|
|
|
jobs:
|
|
enable:
|
|
if: >-
|
|
github.event.pull_request.draft == false
|
|
&& 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: 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: ${{ 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
|
|
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
|
|
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
|