mirror of
https://github.com/Sea-Haven-Industries/procurement-ingest.git
synced 2026-09-30 11:53:13 +00:00
fix(ci): enqueue merge queue as seahaven-bot
This commit is contained in:
parent
8d6384d08a
commit
e58af4313a
1 changed files with 32 additions and 9 deletions
41
.github/workflows/auto-merge.yaml
vendored
41
.github/workflows/auto-merge.yaml
vendored
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue