Skip to content

Cherry pick commit(s) to a branch #1

Cherry pick commit(s) to a branch

Cherry pick commit(s) to a branch #1

Workflow file for this run

---
name: "Cherry pick commit(s) to a branch"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
inputs:
cherrypick_commits:
description: "List of space delimited commits to cherry pick"
required: false
default: ""
workflow_call:
inputs:
branch:
required: true
type: string
commits:
required: true
type: string
jobs:
cherry_pick:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Set env
run: |
echo "CHERRYPICK_COMMITS=$([ -n "${{ inputs.commits }}" ] && echo "${{ inputs.commits }}" || echo "${{ github.event.inputs.cherrypick_commits }}")" >> "$GITHUB_ENV"
echo "BRANCH=$([ -n "${{ inputs.branch }}" ] && echo "${{ inputs.branch }}" || echo "${{ github.ref_name }}")" >> "$GITHUB_ENV"
- name: Check for protected branch
if: ${{ env.BRANCH == 'main' }}
run: |
echo "Cannot cherry pick to protected branch"
exit 1
- name: Check for commit(s)
if: ${{ env.CHERRYPICK_COMMITS == '' }}
run: |
echo "No commits specified to cherry pick"
exit 1
- name: Checkout repo
uses: actions/checkout@v4
- name: Cherry pick to patch branch
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git fetch --all
git switch ${{ env.BRANCH }}
git cherry-pick ${{ env.CHERRYPICK_COMMITS }}
git push -u origin ${{ env.BRANCH }}