Created
December 13, 2025 23:53
-
-
Save tamadon/4d04aa5a76c2b5ff2e5d9e7a593edad1 to your computer and use it in GitHub Desktop.
(Manual) Cherry-Pick to Release Branch
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
| # 手動でcherry-pickを実行してreleaseブランチへPRを作成する | |
| name: (Manual) Cherry-Pick to Release Branch | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| merge_commit_sha: | |
| # [CUSTOMIZE] 説明文は必要に応じて変更してください | |
| description: 'cherry-pickしたいマージコミットのハッシュ値' | |
| required: true | |
| type: string | |
| pr_number: | |
| description: '【optional】マージコミットが含まれるPullRequestの番号' | |
| required: false | |
| type: string | |
| jobs: | |
| cherry-pick: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Git user | |
| # [CUSTOMIZE] コミット作成者の名前とメールアドレスを設定してください | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Cherry-pick to release branches and create PRs | |
| env: | |
| MERGE_COMMIT: ${{ inputs.merge_commit_sha }} | |
| PR_NUMBER: ${{ inputs.pr_number }} | |
| # [CUSTOMIZE] GITHUB_TOKENで作成したPRはCIが自動起動しない場合があります | |
| # CIを自動起動させたい場合はPATに変更してください | |
| # 例: GITHUB_TOKEN: ${{ secrets.YOUR_PAT_SECRET_NAME }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| MERGE_COMMIT_SHORT=$(echo "$MERGE_COMMIT" | cut -c1-7) | |
| failure_occurred=false | |
| # PR番号の表示(オプショナル) | |
| if [[ -n "$PR_NUMBER" ]]; then | |
| echo "🍒 Starting cherry-pick for commit $MERGE_COMMIT_SHORT from PR #$PR_NUMBER" | |
| PR_REF=" (from PR #$PR_NUMBER)" | |
| else | |
| echo "🍒 Starting cherry-pick for commit $MERGE_COMMIT_SHORT" | |
| PR_REF="" | |
| fi | |
| git fetch --all | |
| # [CUSTOMIZE] cherry-pick対象ブランチのパターンを変更してください | |
| # 例: 'origin/release/[0-9]+\.[0-9]+\.[0-9]+' は release/1.2.3 形式にマッチ | |
| # 複数パターン: 'origin/release/.*|origin/hotfix/.*' | |
| TARGET_BRANCHES=$(git branch -r | grep -E 'origin/release/[0-9]+\.[0-9]+\.[0-9]+' | sed 's/^\s*//' | sed 's/origin\///') | |
| if [[ -z "$TARGET_BRANCHES" ]]; then | |
| echo "No release branches found. Exiting." | |
| exit 0 | |
| fi | |
| readarray -t branches <<< "$TARGET_BRANCHES" | |
| for BRANCH in "${branches[@]}"; do | |
| echo "----------------------------------------" | |
| echo "📌 Processing: $BRANCH" | |
| git checkout main | |
| # cherry-pick用ブランチを作成('/'を'-'に置換) | |
| NEW_BRANCH="cherry-pick/${BRANCH//\//-}/$MERGE_COMMIT_SHORT" | |
| git checkout "$BRANCH" | |
| git pull origin "$BRANCH" | |
| git checkout -b "$NEW_BRANCH" | |
| # cherry-pick実行(-m 1 はマージコミットの親を指定) | |
| if ! git cherry-pick -m 1 "$MERGE_COMMIT"; then | |
| echo "::error::❌ Cherry-pick to '$BRANCH' failed (conflict). Skipping." | |
| failure_occurred=true | |
| git cherry-pick --abort | |
| continue | |
| fi | |
| echo "✅ Cherry-pick successful" | |
| git push origin "$NEW_BRANCH" | |
| # [CUSTOMIZE] PRのタイトルと本文は必要に応じて変更してください | |
| gh pr create \ | |
| --title "🍒 Cherry-pick $MERGE_COMMIT_SHORT to $BRANCH$PR_REF" \ | |
| --body "Automated cherry-pick of commit \`$MERGE_COMMIT_SHORT\` to \`$BRANCH\`$PR_REF" \ | |
| --head "$NEW_BRANCH" \ | |
| --base "$BRANCH" | |
| echo "✅ PR created for $BRANCH" | |
| done | |
| echo "----------------------------------------" | |
| if [[ "$failure_occurred" == "true" ]]; then | |
| echo "::warning::Some cherry-picks failed. Please resolve conflicts manually." | |
| exit 1 | |
| fi | |
| echo "🎉 All cherry-picks completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment