diff --git a/.github/workflows/auto-merge.yaml b/.github/workflows/auto-merge.yaml index aa8fdcc..f0ef235 100644 --- a/.github/workflows/auto-merge.yaml +++ b/.github/workflows/auto-merge.yaml @@ -2,10 +2,15 @@ name: Enable auto-merge on: pull_request: - types: [opened, ready_for_review, reopened] + types: [opened, ready_for_review, reopened, synchronize] branches: [main] +concurrency: + group: enable-auto-merge-${{ github.event.pull_request.number }} + cancel-in-progress: true + permissions: + contents: write pull-requests: write jobs: @@ -28,4 +33,12 @@ jobs: echo "auto-merge already enabled" exit 0 fi - gh pr merge "$PR" --repo "$REPO" --auto + if ! out=$(gh pr merge "$PR" --repo "$REPO" --auto 2>&1); then + echo "$out" + 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"