Skip to content

Commit 85cb3ee

Browse files
Pr creating cherrypick (#15385)
* Raise PR for protected branch * Update .github/workflows/cherry-pick-commit.yml Co-authored-by: Copilot <[email protected]> * Update .github/workflows/README.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent d9f58de commit 85cb3ee

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

.github/workflows/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This directory contains GitHub Actions workflows for the React Native Windows re
88

99
**File:** `cherry-pick-commit.yml`
1010

11-
Cherry-picks a specific commit into a target branch.
11+
Cherry-picks a specific commit into a target branch. You can choose to either apply the cherry-pick directly to the target branch or create a Pull Request for review.
1212

1313
**Usage:**
1414

@@ -18,14 +18,23 @@ Cherry-picks a specific commit into a target branch.
1818
4. Enter the required inputs:
1919
- **Commit SHA or ID**: The full commit hash or short SHA of the commit to cherry-pick
2020
- **Target branch name**: The branch where you want to cherry-pick the commit
21+
- **Create a PR instead of direct cherry-pick**: Check this box to create a Pull Request instead of directly applying the cherry-pick
22+
23+
**Workflow Options:**
24+
25+
- **Direct Cherry-pick** (checkbox unchecked): The commit will be cherry-picked and pushed directly to the target branch
26+
- **Pull Request** (checkbox checked): Creates a new branch with the cherry-picked commit and opens a Pull Request to the target branch for review
2127

2228
**Example:**
2329

2430
- Commit ID: `d1a95351e5203a6c0651cf73885cd7ea99e7d2b9`
2531
- Target branch: `0.79-stable`
32+
- Create PR: ✅ (checked) - Creates a PR for review
33+
- Create PR: ❌ (unchecked) - Applies cherry-pick directly
2634

2735
**Notes:**
2836

2937
- The workflow will fail if there are merge conflicts during cherry-pick
3038
- If conflicts occur, you'll need to resolve them manually
31-
- The commit will be pushed directly to the target branch after successful cherry-pick
39+
- When creating a PR, the branch name will be automatically generated as `cherry-pick-<commit-id>-to-<target-branch>`, where `<commit-id>` is the full commit hash (e.g., `cherry-pick-d1a95351e5203a6c0651cf73885cd7ea99e7d2b9-to-0.79-stable`). This may result in long branch names.
40+
- When creating a PR, the title and description will include details about the original commit and target branch

.github/workflows/cherry-pick-commit.yml

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ name: Cherry-pick Commit to Branch
1212
description: 'Target branch name to cherry-pick into'
1313
required: true
1414
type: string
15+
create_pr:
16+
description: 'Create a PR instead of direct cherry-pick'
17+
required: false
18+
type: boolean
19+
default: false
1520

1621
permissions:
1722
contents: write
@@ -51,6 +56,16 @@ jobs:
5156
git checkout "${{ github.event.inputs.target_branch }}"
5257
git pull origin "${{ github.event.inputs.target_branch }}"
5358
59+
- name: Create cherry-pick branch (if creating PR)
60+
if: github.event.inputs.create_pr == 'true'
61+
working-directory: ./repo
62+
run: |
63+
COMMIT_ID="${{ github.event.inputs.commit_id }}"
64+
SHORT_COMMIT_ID="${COMMIT_ID:0:8}"
65+
BRANCH_NAME="cherry-pick-$SHORT_COMMIT_ID-to-${{ github.event.inputs.target_branch }}"
66+
git checkout -b "$BRANCH_NAME"
67+
echo "CHERRY_PICK_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV
68+
5469
- name: Cherry-pick commit
5570
working-directory: ./repo
5671
run: |
@@ -68,16 +83,51 @@ jobs:
6883
exit 1
6984
fi
7085
71-
- name: Push changes
86+
- name: Push changes directly to target branch
87+
if: github.event.inputs.create_pr == 'false'
7288
working-directory: ./repo
7389
env:
7490
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7591
run: |
7692
COMMIT_ID="${{ github.event.inputs.commit_id }}"
7793
TARGET_BRANCH="${{ github.event.inputs.target_branch }}"
7894
79-
echo "📤 Pushing cherry-picked commit to $TARGET_BRANCH"
95+
echo "📤 Pushing cherry-picked commit directly to $TARGET_BRANCH"
8096
REPO_URL="https://x-access-token:${GH_TOKEN}@github.com"
8197
REPO_URL="${REPO_URL}/${{ github.repository }}.git"
8298
git push "$REPO_URL" "$TARGET_BRANCH"
8399
echo "✅ Successfully cherry-picked $COMMIT_ID to $TARGET_BRANCH"
100+
101+
- name: Push cherry-pick branch and create PR
102+
if: github.event.inputs.create_pr == 'true'
103+
working-directory: ./repo
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
run: |
107+
COMMIT_ID="${{ github.event.inputs.commit_id }}"
108+
TARGET_BRANCH="${{ github.event.inputs.target_branch }}"
109+
BRANCH_NAME="${CHERRY_PICK_BRANCH}"
110+
111+
echo "📤 Pushing cherry-pick branch $BRANCH_NAME"
112+
REPO_URL="https://x-access-token:${GH_TOKEN}@github.com"
113+
REPO_URL="${REPO_URL}/${{ github.repository }}.git"
114+
git push "$REPO_URL" "$BRANCH_NAME"
115+
116+
echo "📋 Creating Pull Request"
117+
ORIGINAL_COMMIT_MSG=$(git log --format=%s -n 1 "$COMMIT_ID")
118+
PR_TITLE="Cherry-pick $COMMIT_ID to $TARGET_BRANCH: $ORIGINAL_COMMIT_MSG"
119+
PR_BODY="This PR cherry-picks commit $COMMIT_ID to the $TARGET_BRANCH branch.
120+
121+
**Original commit:** $COMMIT_ID
122+
**Target branch:** $TARGET_BRANCH
123+
**Original commit message:** $ORIGINAL_COMMIT_MSG
124+
125+
Please review the changes before merging."
126+
127+
gh pr create \
128+
--title "$PR_TITLE" \
129+
--body "$PR_BODY" \
130+
--base "$TARGET_BRANCH" \
131+
--head "$BRANCH_NAME"
132+
133+
echo "✅ Successfully created PR for cherry-pick of $COMMIT_ID to $TARGET_BRANCH"

0 commit comments

Comments
 (0)