From 755a05fe3438f908b3f4569ecbba9ad89956a933 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 15 May 2026 13:31:11 +0200 Subject: [PATCH] Add merge-backport workflow to automate PR backports after successful builds Signed-off-by: Chaoscaot --- .gitea/workflows/pull-request-build.yml | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.gitea/workflows/pull-request-build.yml b/.gitea/workflows/pull-request-build.yml index e2902e04..2387a7b2 100644 --- a/.gitea/workflows/pull-request-build.yml +++ b/.gitea/workflows/pull-request-build.yml @@ -39,3 +39,33 @@ jobs: echo "$SW_MAVEN_CREDENTIALS" > steamwar.properties - name: Build with Gradle run: ./gradlew build --no-daemon + + merge-backport: + name: Merge backport + runs-on: ubuntu-latest + needs: build + if: ${{ startsWith(github.event.pull_request.base.ref, 'version/') && startsWith(github.event.pull_request.head.ref, 'backport/pr-') }} + permissions: + contents: write + pull-requests: write + steps: + - name: Merge successful backport PR + shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + set -euo pipefail + + pr_number="$(jq -r '.number' "$GITHUB_EVENT_PATH")" + target_branch="$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")" + payload="$(jq -n \ + --arg title "Merge backport #${pr_number} into ${target_branch}" \ + '{Do: "merge", MergeTitleField: $title, MergeMessageField: "Automatic CommonCore backport after successful build.", delete_branch_after_merge: true}')" + + curl --fail --silent --show-error \ + -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + --data "$payload" \ + "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${pr_number}/merge"