Skip to content

Truly independent web browser

CI: Add a /backport comment command for release branches

Jelle Raaijmakers788c245e9efb
diff --git a/.github/workflows/backport.yml b/.github/workflows/backport.yml
new file mode 100644
index 00000000000..922e1492320
--- /dev/null
+++ b/.github/workflows/backport.yml
@@ -0,0 +1,108 @@
+name: Backport
+
+# Commenting `/backport release/2026.11 [release/2026.10 ...]` on a merged PR cherry-picks its commits onto each of
+# those release branches with `git cherry-pick -x`, and opens a PR against each of them from a branch named
+# `backport/<PR>-to-<release branch>`, titled `[Backport <release branch>] <PR title>`. These PRs are opened by a bot,
+# not by the commenter, and run CI like any other PR. A cherry-pick that conflicts still gets a PR, as a draft with the
+# conflict committed; resolve it on that PR's branch. The original PR gets a comment with the outcome.
+
+on:
+ issue_comment:
+ types: [created]
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.issue.number }}
+ cancel-in-progress: false
+
+jobs:
+ prepare:
+ if: >-
+ github.repository == 'LadybirdBrowser/ladybird'
+ && github.event.issue.pull_request
+ && startsWith(github.event.comment.body, '/backport')
+ runs-on: blacksmith-2vcpu-ubuntu-2404
+
+ permissions:
+ pull-requests: read
+
+ outputs:
+ branches: ${{ steps.parse.outputs.branches }}
+
+ steps:
+ - name: 'Check who asked, and for which release branches'
+ id: parse
+ shell: bash
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ PR: ${{ github.event.issue.number }}
+ COMMENTER: ${{ github.event.comment.user.login }}
+ BODY: ${{ github.event.comment.body }}
+ run: |
+ set -euo pipefail
+ read -r command arguments <<< "$(printf '%s\n' "$BODY" | head -n1 | tr -d '\r')" || true
+ if [ "$command" != /backport ]; then
+ echo "Not a /backport command."
+ exit 0
+ fi
+
+ case "$(gh api "repos/${REPO}/collaborators/${COMMENTER}/permission" --jq .permission)" in
+ admin|maintain|write) ;;
+ *)
+ echo "::error::Backports need write access to this repository, which ${COMMENTER} doesn't have."
+ exit 1
+ ;;
+ esac
+ if [ "$(gh api "repos/${REPO}/pulls/${PR}" --jq .merged)" != true ]; then
+ echo "::error::#${PR} isn't merged, so there is nothing to backport yet."
+ exit 1
+ fi
+
+ read -r -a requested <<< "${arguments:-}"
+ branches=()
+ for branch in "${requested[@]}"; do
+ if ! [[ "$branch" =~ ^release/[0-9]{4}\.([1-9]|1[0-2])$ ]]; then
+ echo "::error::${branch} isn't a release branch, such as release/2026.11."
+ exit 1
+ fi
+ if ! gh api "repos/${REPO}/branches/${branch}" --silent 2> /dev/null; then
+ echo "::error::${branch} doesn't exist."
+ exit 1
+ fi
+ branches+=("$branch")
+ done
+ if [ "${#branches[@]}" -eq 0 ]; then
+ echo "::error::Name the release branches to backport to, such as: /backport release/2026.11"
+ exit 1
+ fi
+ echo "branches=${branches[*]}" >> "$GITHUB_OUTPUT"
+ echo "Backporting #${PR} to ${branches[*]}, for ${COMMENTER}." >> "$GITHUB_STEP_SUMMARY"
+
+ backport:
+ needs: prepare
+ if: needs.prepare.outputs.branches != ''
+ runs-on: blacksmith-2vcpu-ubuntu-2404
+
+ permissions: {}
+
+ steps:
+ - name: 'Create a token for the Ladybird Backport app'
+ id: app-token
+ uses: actions/[email protected]
+ with:
+ client-id: ${{ vars.BACKPORT_APP_CLIENT_ID }}
+ private-key: ${{ secrets.BACKPORT_APP_PRIVATE_KEY }}
+
+ - name: 'Checkout ladybird'
+ uses: actions/[email protected]
+ with:
+ token: ${{ steps.app-token.outputs.token }}
+
+ - name: 'Create the backport PRs'
+ uses: korthout/[email protected]
+ with:
+ github_token: ${{ steps.app-token.outputs.token }}
+ label_pattern: ''
+ target_branches: ${{ needs.prepare.outputs.branches }}
+ branch_name: backport/${pull_number}-to-${target_branch}
+ experimental: '{"conflict_resolution": "draft_commit_conflicts"}'