From cd95cc59b24c9c97a8189085265dae82a91fb879 Mon Sep 17 00:00:00 2001 From: watermann420 <130854822+watermann420@users.noreply.github.com> Date: Mon, 2 Feb 2026 21:53:39 +0100 Subject: [PATCH] Enable auto-merge for main/master PRs --- .github/workflows/auto-merge.yml | 72 ++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 3 ++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/auto-merge.yml diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..91f4e94 --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,72 @@ +name: Auto-merge + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + check_suite: + types: + - completed + workflow_run: + workflows: ["CI"] + types: + - completed + +permissions: + contents: write + pull-requests: write + +jobs: + enable-auto-merge: + if: ${{ github.event.pull_request.draft == false || github.event_name != 'pull_request' }} + runs-on: ubuntu-latest + steps: + - name: Enable auto-merge for eligible PRs + uses: actions/github-script@v7 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const pr = + context.payload.pull_request ?? + (context.payload.check_suite?.pull_requests?.[0] ?? null); + + if (!pr) { + core.info("No pull request in event payload."); + return; + } + + if (pr.draft) { + core.info(`PR #${pr.number} is draft; skipping auto-merge.`); + return; + } + + const allowedBases = new Set(["main", "master"]); + if (!allowedBases.has(pr.base?.ref)) { + core.info(`PR #${pr.number} targets ${pr.base?.ref}; only main/master are auto-merged.`); + return; + } + + if (pr.head?.repo?.fork) { + core.info(`PR #${pr.number} comes from a fork; skipping auto-merge.`); + return; + } + + const mutation = ` + mutation($prId: ID!) { + enablePullRequestAutoMerge(input: { pullRequestId: $prId, mergeMethod: SQUASH }) { + pullRequest { + number + autoMergeRequest { + enabledAt + } + } + } + } + `; + + core.info(`Enabling auto-merge for PR #${pr.number}.`); + await github.graphql(mutation, { prId: pr.node_id }); diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c83f4bf..8a46fd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,9 @@ jobs: dotnet-version: '10.0.x' include-prerelease: true + - name: Install Windows Desktop workload + run: dotnet workload install windowsdesktop + - name: Cache NuGet packages uses: actions/cache@v4 with: