|
| 1 | +--- |
| 2 | +name: Cherry-pick Commit to Branch |
| 3 | + |
| 4 | +'on': |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + commit_id: |
| 8 | + description: 'Commit SHA or ID to cherry-pick' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + target_branch: |
| 12 | + description: 'Target branch name to cherry-pick into' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + cherry-pick: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Install GitHub CLI |
| 22 | + run: | |
| 23 | + sudo apt update |
| 24 | + sudo apt install -y gh |
| 25 | +
|
| 26 | + - name: Authenticate GitHub CLI |
| 27 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token |
| 28 | + |
| 29 | + - name: Clone repository |
| 30 | + env: |
| 31 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + run: | |
| 33 | + gh auth setup-git |
| 34 | + gh repo clone "${{ github.repository }}" repo |
| 35 | + cd repo |
| 36 | + git fetch origin |
| 37 | +
|
| 38 | + - name: Configure Git |
| 39 | + working-directory: ./repo |
| 40 | + run: | |
| 41 | + git config user.name "React-Native-Windows Bot" |
| 42 | + git config user.email "53619745+rnbot@users.noreply.github.com" |
| 43 | +
|
| 44 | + - name: Checkout target branch |
| 45 | + working-directory: ./repo |
| 46 | + run: | |
| 47 | + git checkout "${{ github.event.inputs.target_branch }}" |
| 48 | + git pull origin "${{ github.event.inputs.target_branch }}" |
| 49 | +
|
| 50 | + - name: Cherry-pick commit |
| 51 | + working-directory: ./repo |
| 52 | + run: | |
| 53 | + COMMIT_ID="${{ github.event.inputs.commit_id }}" |
| 54 | + TARGET_BRANCH="${{ github.event.inputs.target_branch }}" |
| 55 | +
|
| 56 | + echo "🍒 Cherry-picking commit $COMMIT_ID into branch $TARGET_BRANCH" |
| 57 | +
|
| 58 | + if git cherry-pick "$COMMIT_ID"; then |
| 59 | + echo "✅ Cherry-pick successful" |
| 60 | + else |
| 61 | + echo "❌ Cherry-pick failed with conflicts" |
| 62 | + echo "Conflict details:" |
| 63 | + git status |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: Push changes |
| 68 | + working-directory: ./repo |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + run: | |
| 72 | + COMMIT_ID="${{ github.event.inputs.commit_id }}" |
| 73 | + TARGET_BRANCH="${{ github.event.inputs.target_branch }}" |
| 74 | +
|
| 75 | + echo "📤 Pushing cherry-picked commit to $TARGET_BRANCH" |
| 76 | + REPO_URL="https://x-access-token:${GH_TOKEN}@github.com" |
| 77 | + REPO_URL="${REPO_URL}/${{ github.repository }}.git" |
| 78 | + git push "$REPO_URL" "$TARGET_BRANCH" |
| 79 | + echo "✅ Successfully cherry-picked $COMMIT_ID to $TARGET_BRANCH" |
0 commit comments