Created
November 23, 2024 23:10
-
-
Save castrojo/2f3a7b2a5422663efe1a2247cd3ee0b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
name: Cherry Pick Commit | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'The branch containing the commit to cherry-pick' | |
required: true | |
commit: | |
description: 'The commit hash to cherry-pick' | |
required: true | |
jobs: | |
cherry-pick: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch all history to enable cherry-picking | |
# Step 2: Set up Git configuration | |
- name: Configure Git | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
# Step 3: Fetch the branch containing the commit | |
- name: Fetch branch | |
run: git fetch origin ${{ inputs.branch }} | |
# Step 4: Switch to the main branch | |
- name: Checkout main branch | |
run: | | |
git checkout main | |
git pull origin main | |
# Step 5: Cherry-pick the specified commit | |
- name: Cherry-pick commit | |
run: | | |
git cherry-pick ${{ inputs.branch }} ${{ inputs.commit }} | |
# Step 6: Push the changes to main | |
- name: Push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: git push origin main | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment