Skip to content

create-cherrypick-pr #18

create-cherrypick-pr

create-cherrypick-pr #18

name: create-cherrypick-pr
on:
workflow_dispatch:
inputs:
sourceCommit:
description: 'Source commit to cherry-pick from'
required: true
type: string
targetBranch:
description: 'Target branch to create PR against'
required: true
type: string
targetCommit:
description: 'Target commit/reference to base the PR on'
required: true
type: string
charts:
description: 'Comma-separated list of charts to include'
required: true
type: string
memorableName:
description: 'A easy-to-remember name to recognize the PR by'
required: true
type: string
jobs:
pick:
runs-on: ubuntu-24.04
steps:
- name: test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SOURCE_COMMIT: ${{ inputs.sourceCommit }}
TARGET_BRANCH: ${{ inputs.targetBranch }}
TARGET_COMMIT: ${{ inputs.targetCommit }}
CHARTS: ${{ inputs.charts }}
MEMORABLE_NAME: ${{ inputs.memorableName }}
shell: bash
run: |
set -eo pipefail
git config --global --add safe.directory "$PWD"
# Clone source repo at HEAD to get latest scripts
git clone https://x-access-token:"${GITHUB_TOKEN}"@github.com/${{ github.repository }} source-repo
# Clone target repo to create PR from
git clone https://x-access-token:"${GITHUB_TOKEN}"@github.com/${{ github.repository }} target-repo
PR_BRANCH="cherry-pick-${TARGET_BRANCH}-$(date '+%Y%m%d%H%M%S')"
echo "PR branch: $PR_BRANCH"
cd target-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git reset --hard "$TARGET_COMMIT"
git checkout -b "$PR_BRANCH"
../source-repo/.github/scripts/cherrypick.py "$TARGET_COMMIT" "$SOURCE_COMMIT" "$CHARTS" \
| jq > ./build.json
git add build.json
git commit -m "Pick $CHARTS from ${SOURCE_COMMIT:0:8}"
# Create PR body
PR_BODY="This PR picks the following helm charts from https://github.com/${{ github.repository }}/commit/${SOURCE_COMMIT}:"
PR_BODY+=$'\n\n'
for chart in $(echo "$CHARTS" | tr ',' ' '); do
PR_BODY+="- \`$chart\`"
PR_BODY+=$'\n'
done
PR_BODY+=$'\n**Memorable name:** '"$MEMORABLE_NAME"
PR_BODY+=$'\n\nYou can create PRs like this with the [release-manager](https://release-manager.ops.zinfra.io/) app or via the `create-cherrypick-pr` workflow'
# Count charts and push branch and create PR
CHART_COUNT=$(echo "$CHARTS" | tr ',' '\n' | wc -l)
git push origin "$PR_BRANCH"
gh pr create --base "$TARGET_BRANCH" --head "$PR_BRANCH" \
--title "Pick $CHART_COUNT chart(s) from ${SOURCE_COMMIT:0:8} to $TARGET_BRANCH" \
--body "$PR_BODY"