1
0
Fork 0
mirror of https://github.com/elementor/hello-theme.git synced 2026-07-27 14:01:37 +08:00
hello-theme/.github/workflows/cherry-pick-pr.yml
Hein van Vlastuin 533baa6f7f
Some checks failed
Build / Build theme (push) Failing after 0s
Lint / ESLint (push) Failing after 1s
Lint / PHPCS (push) Failing after 0s
PHPUnit / File Diff (push) Failing after 1s
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 7.4 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.0 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.1 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.2 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.5 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress 6.6 - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress latest - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - WordPress nightly - PHP version 8.3 (push) Has been skipped
PHPUnit / PHPUnit - Test Results (push) Successful in 2s
Update cherry pick workflow (#629)
2026-05-12 10:01:24 +02:00

152 lines
6.3 KiB
YAML

name: Cherry Pick Merged PR
on:
pull_request_target:
types:
- closed
- labeled
permissions:
contents: write
pull-requests: write
actions: write
jobs:
cherry-pick:
if: ${{ github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository && (github.event.action == 'closed' || (github.event.action == 'labeled' && startsWith(github.event.label.name, 'cp_'))) }}
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
persist-credentials: true
- name: Get branch labels
id: get_labels
run: |
LABELS=$(jq -r '.[].name' <<< '${{ toJSON(github.event.pull_request.labels) }}' | grep '^cp_' | paste -sd ',' || echo "")
echo "filtered_labels_csv=$LABELS" >> "$GITHUB_OUTPUT"
shell: bash
- name: Fetch all branches
run: git fetch --all
shell: bash
- name: Cherry-Pick and Create PRs
if: ${{ steps.get_labels.outputs.filtered_labels_csv != '' }}
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_USER_LOGIN: ${{ github.event.pull_request.user.login }}
LABEL_NAME: ${{ github.event.label.name }}
SOURCE_REPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
MERGE_SHA="${{ github.event.pull_request.merge_commit_sha }}"
ORIG_URL="${{ github.event.pull_request.html_url }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
IFS=',' read -ra BRANCHES <<< "${{ steps.get_labels.outputs.filtered_labels_csv }}"
for lbl in "${BRANCHES[@]}"; do
TARGET=${lbl#cp_}
ORIGINAL_BRANCH="${{ github.event.pull_request.head.ref }}"
BRANCH=$(bash "${GITHUB_WORKSPACE}/.github/scripts/cherry-picking/generate-branch-name.sh" "$PR_NUMBER" "$TARGET" "$ORIGINAL_BRANCH")
CONFLICT_BRANCH="${BRANCH}_conflicts"
echo "Processing cherry-pick for branch: $TARGET"
if ! git checkout -b "$BRANCH" "origin/$TARGET"; then
echo "::warning:: Branch $TARGET does not exist - skipping"
continue
fi
if ! git cherry-pick -m 1 "$MERGE_SHA"; then
echo "::error:: Cherry-pick conflicts detected for PR #${PR_NUMBER} on branch ${TARGET}"
git add .
git commit -m "Cherry-pick PR #${PR_NUMBER} with conflicts - manual resolution needed"
if git push --force-with-lease origin "$BRANCH:$CONFLICT_BRANCH"; then
if ! gh pr list --head "$CONFLICT_BRANCH" --base "$TARGET" --state open | grep -q .; then
CONFLICT_TITLE=$(bash "${GITHUB_WORKSPACE}/.github/scripts/cherry-picking/generate-pr-title.sh" "$PR_TITLE" "$PR_NUMBER" "$TARGET")
CONFLICT_TITLE="${CONFLICT_TITLE} with conflicts"
CONFLICT_TRIGGER_INFO=""
if [ "${{ github.event.action }}" = "labeled" ]; then
CONFLICT_TRIGGER_INFO="
**Trigger:** Label \`${LABEL_NAME}\` added to closed PR"
fi
gh pr create \
--base "$TARGET" \
--head "$CONFLICT_BRANCH" \
--title "$CONFLICT_TITLE" \
--body "**Manual Resolution Required**
This cherry-pick of [#${PR_NUMBER}](${ORIG_URL}) to \`${TARGET}\` branch has conflicts that need manual resolution.
**Theme-Specific Conflict Resolution:**
- **Version Conflicts**: Check \`style.css\` header for version mismatches
- **Schema Conflicts**: Validate \`theme.json\` structure changes
- **Function Conflicts**: Resolve \`functions.php\` function name collisions
**Resolution Steps:**
1. Check out this branch: \`git checkout $CONFLICT_BRANCH\`
2. Resolve conflicts in the marked files
3. Stage resolved files: \`git add <resolved-files>\`
4. Amend the commit: \`git commit --amend\`
5. Push changes: \`git push --force-with-lease\`
6. Mark this PR as ready for review
**Automatic Validation:**
Once you push resolved changes, the following workflows will run automatically:
- Build validation (\`build.yml\`)
- JavaScript linting (\`lint.yml\`)
- Cherry-pick validation (\`cherry-pick-validation.yml\`)
- Additional CI workflows as configured
**Original PR:** [#${PR_NUMBER}](${ORIG_URL})${CONFLICT_TRIGGER_INFO}" \
--draft
fi
else
git cherry-pick --abort
fi
continue
fi
if ! git push --force-with-lease origin "$BRANCH"; then
echo "::error:: Failed to push branch $BRANCH"
exit 1
fi
if gh pr list --head "$BRANCH" --base "$TARGET" --state open | grep -q .; then
echo "PR already exists for branch $BRANCH -> $TARGET, skipping creation"
else
PR_TITLE_GENERATED=$(bash "${GITHUB_WORKSPACE}/.github/scripts/cherry-picking/generate-pr-title.sh" "$PR_TITLE" "$PR_NUMBER" "$TARGET")
TRIGGER_INFO=""
if [ "${{ github.event.action }}" = "labeled" ]; then
TRIGGER_INFO="
**Trigger:** Label \`${LABEL_NAME}\` added to closed PR"
fi
gh pr create \
--base "$TARGET" \
--head "$BRANCH" \
--title "$PR_TITLE_GENERATED" \
--body "Automatic cherry-pick of [#${PR_NUMBER}](${ORIG_URL}) to \`${TARGET}\` branch.
**Source:** ${SOURCE_REPO}
**Original Author:** @${PR_USER_LOGIN}${TRIGGER_INFO}"
fi
done
shell: bash