From c6303efe780628fbf138a0cdf4952e1fb785fd94 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 08:25:12 +0000 Subject: [PATCH 01/18] auto-add-milestone --- .github/scripts/auto-add-milestone.sh | 53 ++++++++++++++++++++++++ .github/workflows/auto-add-milestone.yml | 44 ++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100755 .github/scripts/auto-add-milestone.sh create mode 100644 .github/workflows/auto-add-milestone.yml diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh new file mode 100755 index 000000000000..2537d658e1a8 --- /dev/null +++ b/.github/scripts/auto-add-milestone.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + echo "Example: $0 12345 apache/druid" + exit 1 +fi + +PR_NUMBER="$1" +REPOSITORY="$2" + +# Extract version from pom.xml +VERSION=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='version']/text()" pom.xml | sed 's/-SNAPSHOT//') + +if [ -z "$VERSION" ]; then + echo "Error: Could not extract version from pom.xml" + exit 1 +fi + +echo "Extracted version: $VERSION" + +# Check if milestone exists +MILESTONE_NUMBER=$(gh api "repos/$REPOSITORY/milestones" --jq ".[] | select(.title==\"$VERSION\") | .number") + +# Create milestone if it doesn't exist +if [ -z "$MILESTONE_NUMBER" ]; then + echo "Creating milestone: $VERSION" + MILESTONE_NUMBER=$(gh api "repos/$REPOSITORY/milestones" -f title="$VERSION" --jq '.number') +else + echo "Milestone $VERSION already exists (number: $MILESTONE_NUMBER)" +fi + +# Add PR to milestone +echo "Adding PR #$PR_NUMBER to milestone $VERSION" +gh api "repos/$REPOSITORY/issues/$PR_NUMBER" -f milestone="$MILESTONE_NUMBER" -X PATCH +echo "Successfully added PR #$PR_NUMBER to milestone $VERSION" diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml new file mode 100644 index 000000000000..751a98035228 --- /dev/null +++ b/.github/workflows/auto-add-milestone.yml @@ -0,0 +1,44 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: "Auto Add Milestone to Merged PRs" + +on: + pull_request: + types: [closed] + branches: + - master + +jobs: + add-milestone: + if: github.event.pull_request.merged == true && github.event.pull_request.milestone == null + permissions: + contents: read + pull-requests: write + issues: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Add milestone to PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + .github/scripts/auto-add-milestone.sh "${{ github.event.pull_request.number }}" "${{ github.repository }}" From a148a7b2d5e4a0ca98b653fd1b2401931a5d0fb7 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 08:35:20 +0000 Subject: [PATCH 02/18] install libxml2 --- .github/workflows/auto-add-milestone.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index 751a98035228..c2873cec2817 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -37,6 +37,11 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Install xmllint + run: | + sudo apt-get update + sudo apt-get install -y libxml2-utils + - name: Add milestone to PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a7f52af295cc9a5096752d5baf763a5ce313ae64 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 08:44:07 +0000 Subject: [PATCH 03/18] only run on apache --- .github/workflows/auto-add-milestone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index c2873cec2817..1951151d2b87 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -27,7 +27,7 @@ on: jobs: add-milestone: - if: github.event.pull_request.merged == true && github.event.pull_request.milestone == null + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.milestone == null permissions: contents: read pull-requests: write From 001f3cc34036899ded490acb67ea6e67bc4197d2 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 09:45:39 +0000 Subject: [PATCH 04/18] up --- .github/scripts/auto-add-milestone.sh | 50 +++++++++++++++++++----- .github/workflows/auto-add-milestone.yml | 2 +- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 2537d658e1a8..9b5451a8db45 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -17,6 +17,33 @@ set -e +get_milestone_number() { + local milestone_title="$1" + local number=$(gh api "repos/$REPOSITORY/milestones" --jq ".[] | select(.title==\"$milestone_title\") | .number") + + if [ -z "$number" ]; then + echo "Creating milestone: $milestone_title" + number=$(gh api "repos/$REPOSITORY/milestones" -f title="$milestone_title" --jq '.number') + fi + + echo "$number" +} + +create_backport_issue() { + local pr_number="$1" + local pr_title="$2" + local target_milestone="$3" + + local milestone_number=$(get_milestone_number "$target_milestone") + local body="Backport #$pr_number to release branch for version $target_milestone" + + gh api "repos/$REPOSITORY/issues" \ + -f title="[Backport] $pr_title" \ + -f body="$body" \ + -f milestone="$milestone_number" \ + --jq '.number' +} + if [ "$#" -ne 2 ]; then echo "Usage: $0 " echo "Example: $0 12345 apache/druid" @@ -26,7 +53,6 @@ fi PR_NUMBER="$1" REPOSITORY="$2" -# Extract version from pom.xml VERSION=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='version']/text()" pom.xml | sed 's/-SNAPSHOT//') if [ -z "$VERSION" ]; then @@ -36,18 +62,22 @@ fi echo "Extracted version: $VERSION" -# Check if milestone exists -MILESTONE_NUMBER=$(gh api "repos/$REPOSITORY/milestones" --jq ".[] | select(.title==\"$VERSION\") | .number") +EXISTING_MILESTONE=$(gh api "repos/$REPOSITORY/issues/$PR_NUMBER" --jq '.milestone.title // empty') + +if [ -n "$EXISTING_MILESTONE" ] && [ "$EXISTING_MILESTONE" != "$VERSION" ]; then + echo "PR #$PR_NUMBER has milestone $EXISTING_MILESTONE, but should be $VERSION" -# Create milestone if it doesn't exist -if [ -z "$MILESTONE_NUMBER" ]; then - echo "Creating milestone: $VERSION" - MILESTONE_NUMBER=$(gh api "repos/$REPOSITORY/milestones" -f title="$VERSION" --jq '.number') -else - echo "Milestone $VERSION already exists (number: $MILESTONE_NUMBER)" + PR_TITLE=$(gh api "repos/$REPOSITORY/issues/$PR_NUMBER" --jq '.title') + BACKPORT_ISSUE=$(create_backport_issue "$PR_NUMBER" "$PR_TITLE" "$EXISTING_MILESTONE") + + echo "Created backport issue #$BACKPORT_ISSUE for milestone $EXISTING_MILESTONE" +elif [ -n "$EXISTING_MILESTONE" ]; then + echo "PR #$PR_NUMBER already has correct milestone: $EXISTING_MILESTONE" + exit 0 fi -# Add PR to milestone +MILESTONE_NUMBER=$(get_milestone_number "$VERSION") + echo "Adding PR #$PR_NUMBER to milestone $VERSION" gh api "repos/$REPOSITORY/issues/$PR_NUMBER" -f milestone="$MILESTONE_NUMBER" -X PATCH echo "Successfully added PR #$PR_NUMBER to milestone $VERSION" diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index 1951151d2b87..8e4143bc07c1 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -27,7 +27,7 @@ on: jobs: add-milestone: - if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.milestone == null + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true permissions: contents: read pull-requests: write From 9c9653df93cc490513bb48d16958edd6cc6faae7 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 09:51:24 +0000 Subject: [PATCH 05/18] label --- .github/scripts/auto-add-milestone.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 9b5451a8db45..6cc3d02bcb1f 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -41,6 +41,7 @@ create_backport_issue() { -f title="[Backport] $pr_title" \ -f body="$body" \ -f milestone="$milestone_number" \ + -f labels[]="backport" \ --jq '.number' } From 74ccd80de75744ce6c7088581b96d7bc0be77f4f Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 10:33:17 +0000 Subject: [PATCH 06/18] update --- .github/scripts/auto-add-milestone.sh | 7 ++- .github/scripts/backport-pr.sh | 42 +++++++++++++++ .github/workflows/auto-backport.yml | 77 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/backport-pr.sh create mode 100644 .github/workflows/auto-backport.yml diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 6cc3d02bcb1f..2c4a3557e412 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -35,10 +35,13 @@ create_backport_issue() { local target_milestone="$3" local milestone_number=$(get_milestone_number "$target_milestone") - local body="Backport #$pr_number to release branch for version $target_milestone" + local body="Source-PR: #$pr_number +Target-Version: $target_milestone + +Backport #$pr_number to release branch for version $target_milestone" gh api "repos/$REPOSITORY/issues" \ - -f title="[Backport] $pr_title" \ + -f title="[$target_milestone] $pr_title" \ -f body="$body" \ -f milestone="$milestone_number" \ -f labels[]="backport" \ diff --git a/.github/scripts/backport-pr.sh b/.github/scripts/backport-pr.sh new file mode 100755 index 000000000000..f31bca4b487c --- /dev/null +++ b/.github/scripts/backport-pr.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then + echo "Usage: $0 [body]" + echo "Example: $0 abc123def456 37.0.0 'Fix bug in query engine' 'Closes #12345'" + exit 1 +fi + +COMMIT_HASH="$1" +TARGET_BRANCH="$2" +PR_TITLE="$3" +BODY="${4:-Automatic backport to $TARGET_BRANCH}" + +BACKPORT_BRANCH="backport-$COMMIT_HASH-to-$TARGET_BRANCH" + +git fetch origin "$TARGET_BRANCH" +git checkout -b "$BACKPORT_BRANCH" "origin/$TARGET_BRANCH" +git cherry-pick -x "$COMMIT_HASH" +git push origin "$BACKPORT_BRANCH" + +gh pr create \ + --base "$TARGET_BRANCH" \ + --head "$BACKPORT_BRANCH" \ + --title "[$TARGET_BRANCH] $PR_TITLE" \ + --body "$BODY" diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml new file mode 100644 index 000000000000..6a4b56dd40bf --- /dev/null +++ b/.github/workflows/auto-backport.yml @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +name: "Auto Backport PR" + +on: + issues: + types: [opened] + +env: + ISSUE_NUMBER: ${{ github.event.issue.number }} + ISSUE_BODY: ${{ github.event.issue.body }} + ISSUE_TITLE: ${{ github.event.issue.title }} + +jobs: + backport: + if: github.repository == 'apache/druid' && contains(github.event.issue.labels.*.name, 'backport') + permissions: + contents: write + pull-requests: write + issues: write + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Parse issue and create backport PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + SOURCE_PR=$(echo "$ISSUE_BODY" | grep "^Source-PR:" | sed 's/Source-PR: #//') + TARGET_VERSION=$(echo "$ISSUE_BODY" | grep "^Target-Version:" | sed 's/Target-Version: //') + + if [ -z "$SOURCE_PR" ] || [ -z "$TARGET_VERSION" ]; then + echo "Error: Could not extract Source-PR or Target-Version from issue body" + exit 1 + fi + + MERGE_COMMIT=$(gh api "repos/${{ github.repository }}/pulls/$SOURCE_PR" --jq '.merge_commit_sha') + + if [ -z "$MERGE_COMMIT" ]; then + echo "Error: Could not find merge commit for PR #$SOURCE_PR" + exit 1 + fi + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + BODY="Closes #$ISSUE_NUMBER" + + .github/scripts/backport-pr.sh "$MERGE_COMMIT" "$TARGET_VERSION" "[Backport] $ISSUE_TITLE" "$BODY" + + - name: Comment on failure + if: failure() + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api "repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments" \ + -f body="❌ Automatic backport failed. See workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" From 18c44eca60825442fb023921293b08de7ed37c96 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 10:46:21 +0000 Subject: [PATCH 07/18] update --- .github/scripts/auto-add-milestone.sh | 5 +---- .github/workflows/auto-backport.yml | 11 ++--------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 2c4a3557e412..afa4d74487b8 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -35,10 +35,7 @@ create_backport_issue() { local target_milestone="$3" local milestone_number=$(get_milestone_number "$target_milestone") - local body="Source-PR: #$pr_number -Target-Version: $target_milestone - -Backport #$pr_number to release branch for version $target_milestone" + local body=$(printf '{"source_pr": %d, "target_version": "%s"}' "$pr_number" "$target_milestone") gh api "repos/$REPOSITORY/issues" \ -f title="[$target_milestone] $pr_title" \ diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index 6a4b56dd40bf..f204514da432 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -25,8 +25,9 @@ on: env: ISSUE_NUMBER: ${{ github.event.issue.number }} - ISSUE_BODY: ${{ github.event.issue.body }} ISSUE_TITLE: ${{ github.event.issue.title }} + SOURCE_PR: ${{ fromJson(github.event.issue.body).source_pr }} + TARGET_VERSION: ${{ fromJson(github.event.issue.body).target_version }} jobs: backport: @@ -46,14 +47,6 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - SOURCE_PR=$(echo "$ISSUE_BODY" | grep "^Source-PR:" | sed 's/Source-PR: #//') - TARGET_VERSION=$(echo "$ISSUE_BODY" | grep "^Target-Version:" | sed 's/Target-Version: //') - - if [ -z "$SOURCE_PR" ] || [ -z "$TARGET_VERSION" ]; then - echo "Error: Could not extract Source-PR or Target-Version from issue body" - exit 1 - fi - MERGE_COMMIT=$(gh api "repos/${{ github.repository }}/pulls/$SOURCE_PR" --jq '.merge_commit_sha') if [ -z "$MERGE_COMMIT" ]; then From 9784ff47dbe47654f517149ece57d5813cbb3b85 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 10:48:51 +0000 Subject: [PATCH 08/18] use-jq --- .github/scripts/auto-add-milestone.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index afa4d74487b8..8b3628ff6cf7 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -35,7 +35,7 @@ create_backport_issue() { local target_milestone="$3" local milestone_number=$(get_milestone_number "$target_milestone") - local body=$(printf '{"source_pr": %d, "target_version": "%s"}' "$pr_number" "$target_milestone") + local body=$(jq -n --arg source_pr "$pr_number" --arg target_version "$target_milestone" '$ARGS.named') gh api "repos/$REPOSITORY/issues" \ -f title="[$target_milestone] $pr_title" \ From 6b2b2eccb8fec5952b7f0375ff0e811a02c93d73 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 10:50:22 +0000 Subject: [PATCH 09/18] remove-apache-restr --- .github/workflows/auto-add-milestone.yml | 2 +- .github/workflows/auto-backport.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index 8e4143bc07c1..245af10cb052 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -27,7 +27,7 @@ on: jobs: add-milestone: - if: github.repository == 'apache/druid' && github.event.pull_request.merged == true + if: github.event.pull_request.merged == true permissions: contents: read pull-requests: write diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index f204514da432..30939eb20707 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -31,7 +31,7 @@ env: jobs: backport: - if: github.repository == 'apache/druid' && contains(github.event.issue.labels.*.name, 'backport') + if: contains(github.event.issue.labels.*.name, 'backport') permissions: contents: write pull-requests: write From 50a9316b93db3a93a5b0141abfb6dae2581a6265 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 10:57:44 +0000 Subject: [PATCH 10/18] move (cherry picked from commit 4cd17e874914514625c6100ff3bdf27d5dc60b1e) --- .github/workflows/auto-backport.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index 30939eb20707..0cc9d63b8d9a 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -26,8 +26,6 @@ on: env: ISSUE_NUMBER: ${{ github.event.issue.number }} ISSUE_TITLE: ${{ github.event.issue.title }} - SOURCE_PR: ${{ fromJson(github.event.issue.body).source_pr }} - TARGET_VERSION: ${{ fromJson(github.event.issue.body).target_version }} jobs: backport: @@ -46,6 +44,8 @@ jobs: - name: Parse issue and create backport PR env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE_PR: ${{ fromJson(github.event.issue.body).source_pr }} + TARGET_VERSION: ${{ fromJson(github.event.issue.body).target_version }} run: | MERGE_COMMIT=$(gh api "repos/${{ github.repository }}/pulls/$SOURCE_PR" --jq '.merge_commit_sha') From 9fc85968926030374607d90b77ae06acf98baaeb Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 11:21:44 +0000 Subject: [PATCH 11/18] update --- .github/scripts/auto-add-milestone.sh | 3 ++- .github/workflows/auto-backport.yml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 8b3628ff6cf7..0ca17d103911 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -35,7 +35,8 @@ create_backport_issue() { local target_milestone="$3" local milestone_number=$(get_milestone_number "$target_milestone") - local body=$(jq -n --arg source_pr "$pr_number" --arg target_version "$target_milestone" '$ARGS.named') + local message="Backport #$pr_number to release branch for version $target_milestone" + local body=$(jq -n --arg source_pr "$pr_number" --arg target_version "$target_milestone" --arg message "$message" '$ARGS.named') gh api "repos/$REPOSITORY/issues" \ -f title="[$target_milestone] $pr_title" \ diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index 0cc9d63b8d9a..8b73585e1549 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -21,7 +21,7 @@ name: "Auto Backport PR" on: issues: - types: [opened] + types: [labeled] env: ISSUE_NUMBER: ${{ github.event.issue.number }} @@ -29,7 +29,7 @@ env: jobs: backport: - if: contains(github.event.issue.labels.*.name, 'backport') + if: github.repository == 'apache/druid' && github.event.label.name == 'approved' && contains(github.event.issue.labels.*.name, 'backport') permissions: contents: write pull-requests: write From b47c04dcd2aff30baf20bdf5110566ea1418aefe Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 11:28:44 +0000 Subject: [PATCH 12/18] limit to apache --- .github/workflows/auto-add-milestone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index 245af10cb052..8e4143bc07c1 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -27,7 +27,7 @@ on: jobs: add-milestone: - if: github.event.pull_request.merged == true + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true permissions: contents: read pull-requests: write From 2932b7028790f8a3a9c05cb36af385a4d72f4dbe Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 11:39:42 +0000 Subject: [PATCH 13/18] remove dup --- .github/scripts/backport-pr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/backport-pr.sh b/.github/scripts/backport-pr.sh index f31bca4b487c..d90d2a2aed07 100755 --- a/.github/scripts/backport-pr.sh +++ b/.github/scripts/backport-pr.sh @@ -38,5 +38,5 @@ git push origin "$BACKPORT_BRANCH" gh pr create \ --base "$TARGET_BRANCH" \ --head "$BACKPORT_BRANCH" \ - --title "[$TARGET_BRANCH] $PR_TITLE" \ + --title "$PR_TITLE" \ --body "$BODY" From 473e5651530d0b05c640b2563a0aac70053fdb19 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 11:47:54 +0000 Subject: [PATCH 14/18] up --- .github/scripts/backport-pr.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/scripts/backport-pr.sh b/.github/scripts/backport-pr.sh index d90d2a2aed07..a738a605f472 100755 --- a/.github/scripts/backport-pr.sh +++ b/.github/scripts/backport-pr.sh @@ -33,6 +33,9 @@ BACKPORT_BRANCH="backport-$COMMIT_HASH-to-$TARGET_BRANCH" git fetch origin "$TARGET_BRANCH" git checkout -b "$BACKPORT_BRANCH" "origin/$TARGET_BRANCH" git cherry-pick -x "$COMMIT_HASH" +git commit --amend -m "$(git log -1 --pretty=%B) + +$BODY" git push origin "$BACKPORT_BRANCH" gh pr create \ From 7f14ceb296798b4a5a52f321971ec11bfbfb7d9b Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 12:10:04 +0000 Subject: [PATCH 15/18] x --- .github/scripts/backport-pr.sh | 8 +++---- .github/workflows/auto-add-milestone.yml | 27 +++++++++++++++++++++--- .github/workflows/auto-backport.yml | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/scripts/backport-pr.sh b/.github/scripts/backport-pr.sh index a738a605f472..1d7599674bcd 100755 --- a/.github/scripts/backport-pr.sh +++ b/.github/scripts/backport-pr.sh @@ -19,7 +19,7 @@ set -e if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then echo "Usage: $0 [body]" - echo "Example: $0 abc123def456 37.0.0 'Fix bug in query engine' 'Closes #12345'" + echo "Example: $0 abc123def456 37.0.0 'Fix bug in query engine' '{\"backport_issue\": \"12345\"}'" exit 1 fi @@ -33,13 +33,11 @@ BACKPORT_BRANCH="backport-$COMMIT_HASH-to-$TARGET_BRANCH" git fetch origin "$TARGET_BRANCH" git checkout -b "$BACKPORT_BRANCH" "origin/$TARGET_BRANCH" git cherry-pick -x "$COMMIT_HASH" -git commit --amend -m "$(git log -1 --pretty=%B) - -$BODY" git push origin "$BACKPORT_BRANCH" gh pr create \ --base "$TARGET_BRANCH" \ --head "$BACKPORT_BRANCH" \ --title "$PR_TITLE" \ - --body "$BODY" + --body "$BODY" \ + --label "backport" diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/auto-add-milestone.yml index 8e4143bc07c1..2bd03211768d 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/auto-add-milestone.yml @@ -22,12 +22,33 @@ name: "Auto Add Milestone to Merged PRs" on: pull_request: types: [closed] - branches: - - master jobs: + close-backport-issue: + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'backport') + permissions: + issues: write + runs-on: ubuntu-latest + steps: + - name: Close backport issue + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BACKPORT_ISSUE: ${{ fromJson(github.event.pull_request.body).backport_issue }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + if [ -n "$BACKPORT_ISSUE" ]; then + gh api "repos/${{ github.repository }}/issues/$BACKPORT_ISSUE/comments" \ + -f body="✅ Backport completed in #$PR_NUMBER" + + gh api "repos/${{ github.repository }}/issues/$BACKPORT_ISSUE" \ + -f state="closed" \ + -X PATCH + + echo "Closed backport issue #$BACKPORT_ISSUE" + fi + add-milestone: - if: github.repository == 'apache/druid' && github.event.pull_request.merged == true + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' && !contains(github.event.pull_request.labels.*.name, 'backport') permissions: contents: read pull-requests: write diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index 8b73585e1549..3b6fa92494d8 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -57,7 +57,7 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - BODY="Closes #$ISSUE_NUMBER" + BODY=$(jq -n --arg backport_issue "$ISSUE_NUMBER" '$ARGS.named') .github/scripts/backport-pr.sh "$MERGE_COMMIT" "$TARGET_VERSION" "[Backport] $ISSUE_TITLE" "$BODY" From a97c58a814a24efb9d98270279d42a7a34575c30 Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 12:12:32 +0000 Subject: [PATCH 16/18] rename --- .github/workflows/{auto-add-milestone.yml => pr-merged.yml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{auto-add-milestone.yml => pr-merged.yml} (95%) diff --git a/.github/workflows/auto-add-milestone.yml b/.github/workflows/pr-merged.yml similarity index 95% rename from .github/workflows/auto-add-milestone.yml rename to .github/workflows/pr-merged.yml index 2bd03211768d..370fc0bc88e2 100644 --- a/.github/workflows/auto-add-milestone.yml +++ b/.github/workflows/pr-merged.yml @@ -17,7 +17,7 @@ # under the License. # -name: "Auto Add Milestone to Merged PRs" +name: "PR Merged" on: pull_request: @@ -48,7 +48,7 @@ jobs: fi add-milestone: - if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' && !contains(github.event.pull_request.labels.*.name, 'backport') + if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' permissions: contents: read pull-requests: write From ba28d4b0a65781292a5ad41c990ed5b746b6a9ad Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 12:26:45 +0000 Subject: [PATCH 17/18] enough --- .github/scripts/auto-add-milestone.sh | 3 ++- .github/workflows/auto-backport.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/auto-add-milestone.sh b/.github/scripts/auto-add-milestone.sh index 0ca17d103911..7b1dacdc2a98 100755 --- a/.github/scripts/auto-add-milestone.sh +++ b/.github/scripts/auto-add-milestone.sh @@ -36,7 +36,8 @@ create_backport_issue() { local milestone_number=$(get_milestone_number "$target_milestone") local message="Backport #$pr_number to release branch for version $target_milestone" - local body=$(jq -n --arg source_pr "$pr_number" --arg target_version "$target_milestone" --arg message "$message" '$ARGS.named') + local note="Add the \`approved\` label to start the automatic backport process." + local body=$(jq -n --arg source_pr "$pr_number" --arg target_version "$target_milestone" --arg message "$message" --arg note "$note" '$ARGS.named') gh api "repos/$REPOSITORY/issues" \ -f title="[$target_milestone] $pr_title" \ diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/auto-backport.yml index 3b6fa92494d8..f1e2e0acadb1 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/auto-backport.yml @@ -57,7 +57,8 @@ jobs: git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - BODY=$(jq -n --arg backport_issue "$ISSUE_NUMBER" '$ARGS.named') + MESSAGE="Backport for #$ISSUE_NUMBER" + BODY=$(jq -n --arg backport_issue "$ISSUE_NUMBER" --arg message "$MESSAGE" '$ARGS.named') .github/scripts/backport-pr.sh "$MERGE_COMMIT" "$TARGET_VERSION" "[Backport] $ISSUE_TITLE" "$BODY" From 75b20c050bf926088a8fed52bcf4202392bb3cfa Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Wed, 21 Jan 2026 12:27:57 +0000 Subject: [PATCH 18/18] update --- .../{auto-backport.yml => backport.yml} | 2 +- .github/workflows/pr-merged.yml | 23 ------------------- 2 files changed, 1 insertion(+), 24 deletions(-) rename .github/workflows/{auto-backport.yml => backport.yml} (99%) diff --git a/.github/workflows/auto-backport.yml b/.github/workflows/backport.yml similarity index 99% rename from .github/workflows/auto-backport.yml rename to .github/workflows/backport.yml index f1e2e0acadb1..757ce3768c4c 100644 --- a/.github/workflows/auto-backport.yml +++ b/.github/workflows/backport.yml @@ -17,7 +17,7 @@ # under the License. # -name: "Auto Backport PR" +name: "Backport PR" on: issues: diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml index 370fc0bc88e2..9e62d726706d 100644 --- a/.github/workflows/pr-merged.yml +++ b/.github/workflows/pr-merged.yml @@ -24,29 +24,6 @@ on: types: [closed] jobs: - close-backport-issue: - if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'backport') - permissions: - issues: write - runs-on: ubuntu-latest - steps: - - name: Close backport issue - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - BACKPORT_ISSUE: ${{ fromJson(github.event.pull_request.body).backport_issue }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - if [ -n "$BACKPORT_ISSUE" ]; then - gh api "repos/${{ github.repository }}/issues/$BACKPORT_ISSUE/comments" \ - -f body="✅ Backport completed in #$PR_NUMBER" - - gh api "repos/${{ github.repository }}/issues/$BACKPORT_ISSUE" \ - -f state="closed" \ - -X PATCH - - echo "Closed backport issue #$BACKPORT_ISSUE" - fi - add-milestone: if: github.repository == 'apache/druid' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master' permissions: