World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#9889] improvement(build): Use safer implementation for cherry-pick workflow (#9890)
roryqi437f46a2e0c6
diff --git a/.github/workflows/auto-cherry-pick.yml b/.github/workflows/auto-cherry-pick.ymlindex 9e7f26783b..b3f8786985 100644--- a/.github/workflows/auto-cherry-pick.yml+++ b/.github/workflows/auto-cherry-pick.yml@@ -1,65 +1,110 @@name: Automatically cherry-pick merged PR to different brancheson:- pull_request_target:+ push:branches:- main- types: ["closed"]jobs:- cherry_pick_branch_1_0:+ detect-cherry-pick-labels:runs-on: ubuntu-latest- name: Cherry pick into branch_1.0- if: ${{ contains(github.event.pull_request.labels.*.name, 'branch-1.0') && github.event.pull_request.merged == true }}+ name: Detect cherry-pick labels from merged PR+ outputs:+ branch-1-0: ${{ steps.check-labels.outputs.branch-1-0 }}+ branch-1-1: ${{ steps.check-labels.outputs.branch-1-1 }}+ branch-1-2: ${{ steps.check-labels.outputs.branch-1-2 }}+ commit-sha: ${{ steps.get-commit.outputs.commit-sha }}+ commit-message: ${{ steps.get-commit.outputs.commit-message }}steps:- name: Checkoutuses: actions/checkout@v4with:fetch-depth: 0- - name: Cherry pick into branch-1.0- uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3- with:- branch: branch-1.0- labels: |- cherry-pick- reviewers: |- jerryshao- cherry_pick_branch_1_1:- runs-on: ubuntu-latest- name: Cherry pick into branch_1.1- if: ${{ contains(github.event.pull_request.labels.*.name, 'branch-1.1') && github.event.pull_request.merged == true }}- steps:- - name: Checkout- uses: actions/checkout@v4- with:- fetch-depth: 0- - name: Cherry pick into branch-1.1- uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3- with:- branch: branch-1.1- labels: |- cherry-pick- reviewers: |- jerryshao+ - name: Get commit info+ id: get-commit+ run: |+ # Get the commit message and extract PR number if available+ COMMIT_MESSAGE=$(git log -1 --pretty=%B ${{ github.sha }})+ COMMIT_SUBJECT=$(git log -1 --pretty=%s ${{ github.sha }})+ echo "Commit: $COMMIT_SUBJECT"++ # Try to extract PR number for later use+ PR_NUMBER=$(echo "$COMMIT_MESSAGE" | grep -oE '#[0-9]+' | head -1 | sed 's/#//')++ if [ -z "$PR_NUMBER" ]; then+ echo "No PR number found, will skip label check"+ echo "pr-number=" >> $GITHUB_OUTPUT+ else+ echo "Found PR number: $PR_NUMBER"+ echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT+ fi++ # Save commit info+ echo "commit-sha=${{ github.sha }}" >> $GITHUB_OUTPUT+ {+ echo "commit-message<<EOF"+ echo "$COMMIT_SUBJECT"+ echo "EOF"+ } >> $GITHUB_OUTPUT- cherry_pick_branch_1_2:- runs-on: ubuntu-latest- name: Cherry pick into branch_1.2- if: ${{ contains(github.event.pull_request.labels.*.name, 'branch-1.2') && github.event.pull_request.merged == true }}- steps:- - name: Checkout- uses: actions/checkout@v4- with:- fetch-depth: 0- - name: Cherry pick into branch-1.2- uses: carloscastrojumo/github-cherry-pick-action@503773289f4a459069c832dc628826685b75b4b3- with:- branch: branch-1.2- labels: |- cherry-pick- reviewers: |- jerryshao+ - name: Check PR labels+ id: check-labels+ if: steps.get-commit.outputs.pr-number != ''+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ run: |+ PR_NUMBER=${{ steps.get-commit.outputs.pr-number }}++ # Get PR labels using GitHub CLI+ LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name' || echo "")+ echo "PR #$PR_NUMBER labels: $LABELS"++ # Check for each branch label+ if echo "$LABELS" | grep -q "branch-1.0"; then+ echo "branch-1-0=true" >> $GITHUB_OUTPUT+ else+ echo "branch-1-0=false" >> $GITHUB_OUTPUT+ fi++ if echo "$LABELS" | grep -q "branch-1.1"; then+ echo "branch-1-1=true" >> $GITHUB_OUTPUT+ else+ echo "branch-1-1=false" >> $GITHUB_OUTPUT+ fi++ if echo "$LABELS" | grep -q "branch-1.2"; then+ echo "branch-1-2=true" >> $GITHUB_OUTPUT+ else+ echo "branch-1-2=false" >> $GITHUB_OUTPUT+ fi++ cherry-pick-branch-1-0:+ needs: detect-cherry-pick-labels+ if: needs.detect-cherry-pick-labels.outputs.branch-1-0 == 'true'+ uses: ./.github/workflows/cherry-pick-branch.yml+ with:+ target-branch: branch-1.0+ commit-sha: ${{ needs.detect-cherry-pick-labels.outputs.commit-sha }}+ commit-message: ${{ needs.detect-cherry-pick-labels.outputs.commit-message }}+ secrets: inherit++ cherry-pick-branch-1-1:+ needs: detect-cherry-pick-labels+ if: needs.detect-cherry-pick-labels.outputs.branch-1-1 == 'true'+ uses: ./.github/workflows/cherry-pick-branch.yml+ with:+ target-branch: branch-1.1+ commit-sha: ${{ needs.detect-cherry-pick-labels.outputs.commit-sha }}+ commit-message: ${{ needs.detect-cherry-pick-labels.outputs.commit-message }}+ secrets: inherit-env:- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ cherry-pick-branch-1-2:+ needs: detect-cherry-pick-labels+ if: needs.detect-cherry-pick-labels.outputs.branch-1-2 == 'true'+ uses: ./.github/workflows/cherry-pick-branch.yml+ with:+ target-branch: branch-1.2+ commit-sha: ${{ needs.detect-cherry-pick-labels.outputs.commit-sha }}+ commit-message: ${{ needs.detect-cherry-pick-labels.outputs.commit-message }}+ secrets: inheritdiff --git a/.github/workflows/cherry-pick-branch.yml b/.github/workflows/cherry-pick-branch.ymlnew file mode 100644index 0000000000..d5a3b89e87--- /dev/null+++ b/.github/workflows/cherry-pick-branch.yml@@ -0,0 +1,131 @@+#+# 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: Cherry-pick to branch++on:+ workflow_call:+ inputs:+ target-branch:+ description: 'Target branch to cherry-pick to'+ required: true+ type: string+ commit-sha:+ description: 'Commit SHA to cherry-pick'+ required: true+ type: string+ commit-message:+ description: 'Original commit message'+ required: true+ type: string++jobs:+ cherry-pick:+ runs-on: ubuntu-latest+ name: Cherry-pick to ${{ inputs.target-branch }}+ steps:+ - name: Checkout+ uses: actions/checkout@v4+ with:+ fetch-depth: 0+ token: ${{ secrets.GITHUB_TOKEN }}++ - name: Set up Git+ run: |+ git config user.name "github-actions[bot]"+ git config user.email "github-actions[bot]@users.noreply.github.com"++ - name: Cherry-pick commit+ id: cherry-pick+ run: |+ # Fetch all branches+ git fetch origin++ # Checkout target branch+ git checkout ${{ inputs.target-branch }}++ # Create a new branch for the cherry-pick (use short SHA)+ SHORT_SHA=$(echo "${{ inputs.commit-sha }}" | cut -c1-8)+ BRANCH_NAME="cherry-pick-${SHORT_SHA}-to-${{ inputs.target-branch }}"+ git checkout -b $BRANCH_NAME++ # Cherry-pick the commit+ if git cherry-pick ${{ inputs.commit-sha }}; then+ echo "Cherry-pick successful"+ echo "success=true" >> $GITHUB_OUTPUT+ echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT+ else+ echo "Cherry-pick failed, creating conflict PR"+ echo "success=false" >> $GITHUB_OUTPUT+ echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT++ # Add all files (including conflicts)+ git add .+ git commit --no-edit || git commit -m "Cherry-pick ${{ inputs.commit-sha }} to ${{ inputs.target-branch }} (with conflicts)"+ fi++ - name: Push branch+ if: steps.cherry-pick.outputs.branch-name != ''+ run: |+ git push origin ${{ steps.cherry-pick.outputs.branch-name }}++ - name: Create Pull Request+ if: steps.cherry-pick.outputs.branch-name != ''+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ COMMIT_MESSAGE: ${{ inputs.commit-message }}+ TARGET_BRANCH: ${{ inputs.target-branch }}+ COMMIT_SHA: ${{ inputs.commit-sha }}+ SUCCESS: ${{ steps.cherry-pick.outputs.success }}+ run: |+ # Use original commit message with branch prefix+ TITLE="[Cherry-pick to ${TARGET_BRANCH}] ${COMMIT_MESSAGE}"++ # Prepare body with cherry-pick info+ if [ "${SUCCESS}" = "true" ]; then+ BODY=$(cat <<'EOF'+ **Cherry-pick Information:**+ - Original commit: ${COMMIT_SHA}+ - Target branch: `${TARGET_BRANCH}`+ - Status: ✅ Clean cherry-pick (no conflicts)+ EOF+ )+ else+ BODY=$(cat <<'EOF'+ **Cherry-pick Information:**+ - Original commit: ${COMMIT_SHA}+ - Target branch: `${TARGET_BRANCH}`+ - Status: ⚠️ **Has conflicts - manual resolution required**++ Please review and resolve the conflicts before merging.+ EOF+ )+ fi++ # Replace placeholders with actual values+ BODY="${BODY//\$\{COMMIT_SHA\}/${COMMIT_SHA}}"+ BODY="${BODY//\$\{TARGET_BRANCH\}/${TARGET_BRANCH}}"++ gh pr create \+ --title "$TITLE" \+ --body "$BODY" \+ --base ${{ inputs.target-branch }} \+ --head ${{ steps.cherry-pick.outputs.branch-name }} \+ --label cherry-pick \+ --reviewer jerryshao || echo "Failed to create PR, may already exist"