feat(merge-queue): add action serializing merges of queued PRs #1

Merged
aurelien merged 1 commit from feat/merge-queue into main 2026-10-22 11:33:43 +02:00
Owner

Adds a merge-queue composite action that serializes merges of labelled PRs on top of the existing repository rules (rebase-merge style, "block merge if outdated", required checks).

Each run advances the queue by one step. The queue is the open PRs targeting the default branch that carry the queue label, oldest first. The head of the queue is rebased on the base branch through the API when it is outdated, then scheduled with "merge when checks succeed". A head whose rebase conflicts, whose checks failed or whose merge Forgejo refuses is removed from the queue with a comment, and the next PR is tried. Calls that fail for reasons unrelated to one PR (auth, network) fail the job instead of draining the queue.

Usage, in .forgejo/workflows/merge-queue.yml:

name: merge-queue

on:
  push:
    branches: [main]
  pull_request_target:
    types: [labeled]
  schedule:
    - cron: "*/10 * * * *"
  workflow_dispatch:

jobs:
  advance:
    runs-on: ubuntu-latest
    steps:
      - uses: https://git.bosscorp.fr/aurelien/forgejo-actions/merge-queue@v1
        with:
          token: ${{ secrets.MERGE_QUEUE_TOKEN }}

The token must be a personal access token (repository and issue read/write): the rebase it pushes has to trigger the PR checks. The schedule is what dequeues a PR whose checks failed, since no event fires on check completion.

Verified end to end on a sandbox repository (Forgejo 15.0.10, runner image with jq 1.6) with the same branch protection as the other repositories:

  • 3 PRs queued at once while their CI was running: all merged one after another, each rebased on the updated base and retested.
  • 5 PRs queued at once, including one with failing CI and one conflicting with an earlier PR: 3 merged, the failing one dequeued by the scheduled run, the conflicting one dequeued at rebase, no spurious comment, no failed queue run.
Adds a `merge-queue` composite action that serializes merges of labelled PRs on top of the existing repository rules (rebase-merge style, "block merge if outdated", required checks). Each run advances the queue by one step. The queue is the open PRs targeting the default branch that carry the `queue` label, oldest first. The head of the queue is rebased on the base branch through the API when it is outdated, then scheduled with "merge when checks succeed". A head whose rebase conflicts, whose checks failed or whose merge Forgejo refuses is removed from the queue with a comment, and the next PR is tried. Calls that fail for reasons unrelated to one PR (auth, network) fail the job instead of draining the queue. Usage, in `.forgejo/workflows/merge-queue.yml`: ```yaml name: merge-queue on: push: branches: [main] pull_request_target: types: [labeled] schedule: - cron: "*/10 * * * *" workflow_dispatch: jobs: advance: runs-on: ubuntu-latest steps: - uses: https://git.bosscorp.fr/aurelien/forgejo-actions/merge-queue@v1 with: token: ${{ secrets.MERGE_QUEUE_TOKEN }} ``` The token must be a personal access token (repository and issue read/write): the rebase it pushes has to trigger the PR checks. The schedule is what dequeues a PR whose checks failed, since no event fires on check completion. Verified end to end on a sandbox repository (Forgejo 15.0.10, runner image with jq 1.6) with the same branch protection as the other repositories: - 3 PRs queued at once while their CI was running: all merged one after another, each rebased on the updated base and retested. - 5 PRs queued at once, including one with failing CI and one conflicting with an earlier PR: 3 merged, the failing one dequeued by the scheduled run, the conflicting one dequeued at rebase, no spurious comment, no failed queue run.
Sign in to join this conversation.
No reviewers
No labels
queue
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aurelien/forgejo-actions!1
No description provided.