This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 5472c62e47 [MINOR] ci: Open auto cherry-pick PRs from the merging
committer's fork (#15061)
5472c62e47 is described below
commit 5472c62e472b67796b4522e02fae6c3eb4aac67e
Author: Jerry Shao <[email protected]>
AuthorDate: Wed Nov 18 15:57:11 2026 +0800
[MINOR] ci: Open auto cherry-pick PRs from the merging committer's fork
(#15061)
### What changes were proposed in this pull request?
For target branches that have Fork CI (currently `branch-2.0`), auto
cherry-pick now opens its PR from a committer's fork instead of from a
branch in apache/gravitino:
- `auto-cherry-pick.yml` passes the login of the committer who merged
the original PR (`merged-by`) to `cherry-pick-branch.yml`.
- `cherry-pick-branch.yml` picks a token: the merger's
`CHERRY_PICK_TOKEN_<LOGIN>` secret (login uppercased, `-` → `_`),
falling back to `CHERRY_PICK_TOKEN_JERRYSHAO` (the fallback login can be
changed with the `CHERRY_PICK_FALLBACK_LOGIN` variable).
- Each token is checked before use: it belongs to that login,
`<login>/gravitino` is a fork of apache/gravitino, and its `fork-ci.yml`
is not disabled. Skipped tokens and the reason are listed in the job
summary; the job fails if no token is usable.
- The branch is pushed to `<login>/gravitino` and the PR is opened with
head `<login>:<branch>`, so Fork CI runs on that fork's runners and the
existing status publisher mirrors the result.
- A re-run keeps an existing fork branch (it may hold conflict fixes)
and accepts an already open PR; any other `gh pr create` failure now
fails the job.
- Target branches without Fork CI (`branch-1.3`) keep the previous
behavior.
### Why are the changes needed?
Auto cherry-pick branches were pushed to apache/gravitino with
`GITHUB_TOKEN` (`CHERRY_PICK_TOKEN` is not configured), so Fork CI never
started for those PRs, and any CI they did get ran on the scarce ASF
runners. Using the merging committer's fork spreads the load across
forks instead of making one fork's concurrency limit the bottleneck.
### Does this PR introduce _any_ user-facing change?
No. Committers who want cherry-pick PRs opened from their own fork need:
1. A personal-account fork of apache/gravitino named `gravitino`, with
workflows enabled in its Actions tab.
2. A classic PAT with the `public_repo` and `workflow` scopes.
3. A repository secret `CHERRY_PICK_TOKEN_<LOGIN>` in apache/gravitino
holding that token.
### How was this patch tested?
- YAML parses and every `run` script passes `bash -n`; the Fork CI
script tests pass (`node --test .github/scripts/tests/*.test.cjs`).
- Ran the head-resolution step locally for `branch-2.0` (fork mode),
`branch-1.3` (upstream mode) and an invalid login.
- Ran the token check against the GitHub API with a valid matching
token, a token of another user, a missing token and an invalid token;
checked the existing-PR lookup, the `fork-ci.yml` state lookup,
`ls-remote` detection and the PR body for clean and conflict
cherry-picks.
- Not yet run end to end in Actions; the first `branch-2.0` cherry-pick
after merge will exercise it.
Known limitation (pre-existing): cherry-picks that change `.github/`
cannot get a green Fork CI on a release branch, because trusted runs are
only allowed for the default branch.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.github/workflows/auto-cherry-pick.yml | 8 ++
.github/workflows/cherry-pick-branch.yml | 151 +++++++++++++++++++++++++++----
2 files changed, 141 insertions(+), 18 deletions(-)
diff --git a/.github/workflows/auto-cherry-pick.yml
b/.github/workflows/auto-cherry-pick.yml
index 60ef41d51c..4fbedb52cf 100644
--- a/.github/workflows/auto-cherry-pick.yml
+++ b/.github/workflows/auto-cherry-pick.yml
@@ -17,6 +17,7 @@ jobs:
branch-2-0: ${{ steps.check-labels.outputs.branch-2-0 }}
commit-sha: ${{ steps.get-commit.outputs.commit-sha }}
commit-message: ${{ steps.get-commit.outputs.commit-message }}
+ merged-by: ${{ steps.check-labels.outputs.merged-by }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -65,6 +66,11 @@ jobs:
# Get PR labels using GitHub CLI
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name'
|| echo "")
echo "PR #$PR_NUMBER labels: $LABELS"
+
+ # The committer who merged the PR opens the cherry-pick PRs from
their fork.
+ MERGED_BY=$(gh pr view $PR_NUMBER --json mergedBy --jq
'.mergedBy.login // ""' || echo "")
+ echo "PR #$PR_NUMBER merged by: ${MERGED_BY:-unknown}"
+ echo "merged-by=$MERGED_BY" >> $GITHUB_OUTPUT
# Check for each branch label
if echo "$LABELS" | grep -q "branch-1.3"; then
@@ -87,6 +93,7 @@ jobs:
target-branch: branch-1.3
commit-sha: ${{ needs.detect-cherry-pick-labels.outputs.commit-sha }}
commit-message: ${{
needs.detect-cherry-pick-labels.outputs.commit-message }}
+ merged-by: ${{ needs.detect-cherry-pick-labels.outputs.merged-by }}
secrets: inherit
cherry-pick-branch-2-0:
@@ -97,4 +104,5 @@ jobs:
target-branch: branch-2.0
commit-sha: ${{ needs.detect-cherry-pick-labels.outputs.commit-sha }}
commit-message: ${{
needs.detect-cherry-pick-labels.outputs.commit-message }}
+ merged-by: ${{ needs.detect-cherry-pick-labels.outputs.merged-by }}
secrets: inherit
diff --git a/.github/workflows/cherry-pick-branch.yml
b/.github/workflows/cherry-pick-branch.yml
index 3b5aaa8d41..25846ac7ff 100644
--- a/.github/workflows/cherry-pick-branch.yml
+++ b/.github/workflows/cherry-pick-branch.yml
@@ -34,6 +34,11 @@ on:
description: 'Original commit message'
required: true
type: string
+ merged-by:
+ description: 'Login of the committer who merged the original PR'
+ required: false
+ type: string
+ default: ''
jobs:
cherry-pick:
@@ -87,20 +92,108 @@ jobs:
git commit --no-edit || git commit -m "Cherry-pick ${{
inputs.commit-sha }} to ${{ inputs.target-branch }} (with conflicts)"
fi
- - name: Push branch
+ # Target branches with Fork CI get their cherry-pick PR from a
committer's fork, so CI runs on
+ # that fork's runners instead of apache/gravitino's. The merging
committer's token is preferred
+ # and the fallback committer's token is used when it is missing or
unusable.
+ - name: Resolve pull request head
+ id: head
if: steps.cherry-pick.outputs.branch-name != ''
+ env:
+ TARGET_BRANCH: ${{ inputs.target-branch }}
+ MERGED_BY: ${{ inputs.merged-by }}
+ FALLBACK_LOGIN: ${{ vars.CHERRY_PICK_FALLBACK_LOGIN || 'jerryshao' }}
run: |
- git push origin ${{ steps.cherry-pick.outputs.branch-name }}
+ secret_name() {
+ # Secret names allow only letters, digits and underscores; logins
never contain '_'.
+ if [[ "$1" =~ ^[A-Za-z0-9-]+$ ]]; then
+ echo "CHERRY_PICK_TOKEN_$(echo "$1" | tr 'a-z-' 'A-Z_')"
+ fi
+ }
+ if git cat-file -e
"origin/${TARGET_BRANCH}:.github/workflows/fork-ci.yml" 2>/dev/null; then
+ echo "mode=fork" >> "$GITHUB_OUTPUT"
+ else
+ echo "mode=upstream" >> "$GITHUB_OUTPUT"
+ fi
+ echo "merger-secret=$(secret_name "${MERGED_BY}")" >>
"$GITHUB_OUTPUT"
+ echo "fallback-secret=$(secret_name "${FALLBACK_LOGIN}")" >>
"$GITHUB_OUTPUT"
- - name: Create Pull Request
+ - name: Push branch and create pull request
if: steps.cherry-pick.outputs.branch-name != ''
env:
- GH_TOKEN: ${{ secrets.CHERRY_PICK_TOKEN || secrets.GITHUB_TOKEN }}
+ MODE: ${{ steps.head.outputs.mode }}
+ BRANCH_NAME: ${{ steps.cherry-pick.outputs.branch-name }}
+ MERGED_BY: ${{ inputs.merged-by }}
+ FALLBACK_LOGIN: ${{ vars.CHERRY_PICK_FALLBACK_LOGIN || 'jerryshao' }}
+ MERGER_TOKEN: ${{ steps.head.outputs.merger-secret &&
secrets[steps.head.outputs.merger-secret] || '' }}
+ FALLBACK_TOKEN: ${{ steps.head.outputs.fallback-secret &&
secrets[steps.head.outputs.fallback-secret] || '' }}
+ UPSTREAM_TOKEN: ${{ secrets.CHERRY_PICK_TOKEN ||
secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: ${{ inputs.commit-message }}
TARGET_BRANCH: ${{ inputs.target-branch }}
COMMIT_SHA: ${{ inputs.commit-sha }}
SUCCESS: ${{ steps.cherry-pick.outputs.success }}
run: |
+ set -euo pipefail
+
+ # Prints the token owner when it can open the PR from
"$2/gravitino"; otherwise fails.
+ usable_fork() {
+ local token="$1" login="$2" actual fork actions
+ if [ -z "$token" ] || [ -z "$login" ]; then
+ echo "- \`${login:-?}\`: no token secret" >>
"$GITHUB_STEP_SUMMARY"
+ return 1
+ fi
+ actual=$(GH_TOKEN="$token" gh api user --jq .login 2>/dev/null) ||
actual=""
+ if [ "${actual,,}" != "${login,,}" ]; then
+ echo "- \`${login}\`: token is invalid, expired or belongs to
\`${actual:-nobody}\`" >> "$GITHUB_STEP_SUMMARY"
+ return 1
+ fi
+ fork=$(GH_TOKEN="$token" gh api "repos/${actual}/gravitino" \
+ --jq '"\(.fork) \(.parent.full_name // "")"' 2>/dev/null) ||
fork=""
+ if [ "$fork" != "true apache/gravitino" ]; then
+ echo "- \`${login}\`: \`${actual}/gravitino\` does not exist or
is not a fork of apache/gravitino" \
+ "(the fork must be named gravitino)" >> "$GITHUB_STEP_SUMMARY"
+ return 1
+ fi
+ # A fork whose workflows were never enabled or were disabled would
never run Fork CI.
+ # The workflow is unknown (404) until the fork has been synced;
accept that case.
+ actions=$(GH_TOKEN="$token" gh api
"repos/${actual}/gravitino/actions/workflows/fork-ci.yml" \
+ --jq .state 2>/dev/null) || actions=""
+ if [ -n "$actions" ] && [ "$actions" != "active" ]; then
+ echo "- \`${login}\`: Fork CI is \`${actions}\` in
\`${actual}/gravitino\`; enable it in the fork's Actions tab" \
+ >> "$GITHUB_STEP_SUMMARY"
+ return 1
+ fi
+ echo "$actual"
+ }
+
+ if [ "${MODE}" = "fork" ]; then
+ echo "### Cherry-pick PR head" >> "$GITHUB_STEP_SUMMARY"
+ if HEAD_OWNER=$(usable_fork "${MERGER_TOKEN}" "${MERGED_BY}"); then
+ PR_TOKEN="${MERGER_TOKEN}"
+ elif HEAD_OWNER=$(usable_fork "${FALLBACK_TOKEN}"
"${FALLBACK_LOGIN}"); then
+ PR_TOKEN="${FALLBACK_TOKEN}"
+ else
+ echo "::error::No usable committer token for a fork PR; see the
job summary."
+ exit 1
+ fi
+ echo "- Using \`${HEAD_OWNER}/gravitino\`" >>
"$GITHUB_STEP_SUMMARY"
+ # Drop the checkout credentials so git authenticates with the
committer's token.
+
FORK_URL="https://x-access-token:${PR_TOKEN}@github.com/${HEAD_OWNER}/gravitino.git"
+ if git -c http.https://github.com/.extraheader= ls-remote
--exit-code --heads \
+ "${FORK_URL}" "${BRANCH_NAME}" >/dev/null; then
+ # A re-run must not replace the branch: someone may have pushed
conflict fixes to it.
+ echo "::notice::${HEAD_OWNER}/gravitino already has
${BRANCH_NAME}; keeping it."
+ else
+ git -c http.https://github.com/.extraheader= push "${FORK_URL}"
"HEAD:refs/heads/${BRANCH_NAME}"
+ fi
+ HEAD_REF="${HEAD_OWNER}:${BRANCH_NAME}"
+ else
+ git push origin "${BRANCH_NAME}"
+ PR_TOKEN="${UPSTREAM_TOKEN}"
+ HEAD_OWNER=""
+ HEAD_REF="${BRANCH_NAME}"
+ fi
+ export GH_TOKEN="${PR_TOKEN}"
+
# Use original commit message with branch prefix
TITLE="[Cherry-pick to ${TARGET_BRANCH}] ${COMMIT_MESSAGE}"
LABELS=(cherry-pick)
@@ -111,7 +204,7 @@ jobs:
**Cherry-pick Information:**
- Original commit: ${COMMIT_SHA}
- Target branch: `${TARGET_BRANCH}`
- - Status: ✅ Clean cherry-pick (no conflicts)
+ - Status: ✅ Clean cherry-pick (no conflicts)${FORK_CI}
EOF
)
else
@@ -123,7 +216,7 @@ jobs:
**Cherry-pick Information:**
- Original commit: ${COMMIT_SHA}
- Target branch: `${TARGET_BRANCH}`
- - Status: ⚠️ **Has conflicts - manual resolution required**
+ - Status: ⚠️ **Has conflicts - manual resolution required**${FORK_CI}
**Do not merge** until conflict markers are resolved and the
`cherry-pick-conflict` label is removed.
@@ -136,17 +229,20 @@ jobs:
# Replace placeholders with actual values
BODY="${BODY//\$\{COMMIT_SHA\}/${COMMIT_SHA}}"
BODY="${BODY//\$\{TARGET_BRANCH\}/${TARGET_BRANCH}}"
+ FORK_CI=""
+ if [ -n "${HEAD_OWNER}" ]; then
+ FORK_CI=$'\n'"- Fork CI: runs in \`${HEAD_OWNER}/gravitino\`;
re-run it there or push to this PR branch"
+ fi
+ BODY="${BODY//\$\{FORK_CI\}/${FORK_CI}}"
- # Ensure labels exist (forks may not have them yet).
- gh label create cherry-pick \
+ # Create the labels if they are missing; existing labels are left as
they are.
+ gh label create cherry-pick --repo "${{ github.repository }}" \
--description "Automatically opened cherry-pick PR" \
- --color 1D76DB \
- --force >/dev/null 2>&1 || true
+ --color 1D76DB >/dev/null 2>&1 || true
if [ "${SUCCESS}" != "true" ]; then
- gh label create cherry-pick-conflict \
+ gh label create cherry-pick-conflict --repo "${{ github.repository
}}" \
--description "Cherry-pick has conflicts; needs human resolution
before merge" \
- --color B60205 \
- --force >/dev/null 2>&1 || true
+ --color B60205 >/dev/null 2>&1 || true
fi
LABEL_ARGS=()
@@ -155,14 +251,33 @@ jobs:
done
CREATE_ARGS=(
+ --repo "${{ github.repository }}"
--title "$TITLE"
--body "$BODY"
- --base "${{ inputs.target-branch }}"
- --head "${{ steps.cherry-pick.outputs.branch-name }}"
+ --base "${TARGET_BRANCH}"
+ --head "${HEAD_REF}"
"${LABEL_ARGS[@]}"
)
- # Reviewer is only valid on apache/gravitino.
+ # Reviewer is only valid on apache/gravitino, and a PR author cannot
review their own PR.
if [ "${{ github.repository }}" = "apache/gravitino" ]; then
- CREATE_ARGS+=(--reviewer jerryshao)
+ AUTHOR="${HEAD_OWNER:-}"
+ if [ "${AUTHOR,,}" != "jerryshao" ]; then
+ CREATE_ARGS+=(--reviewer jerryshao)
+ # Bot and app logins (e.g. "name[bot]") cannot be requested as
reviewers.
+ elif [[ "${MERGED_BY}" =~ ^[A-Za-z0-9-]+$ ]] && [ "${MERGED_BY,,}"
!= "${AUTHOR,,}" ]; then
+ CREATE_ARGS+=(--reviewer "${MERGED_BY}")
+ fi
+ fi
+ if ! gh pr create "${CREATE_ARGS[@]}"; then
+ # A re-run finds the PR it opened before; any other failure must
fail the job.
+ OWNER="${HEAD_OWNER:-${{ github.repository_owner }}}"
+ EXISTING=$(gh pr list --repo "${{ github.repository }}" --head
"${BRANCH_NAME}" --state open \
+ --json url,headRepositoryOwner \
+ --jq ".[] | select((.headRepositoryOwner.login | ascii_downcase)
== \"${OWNER,,}\") | .url" \
+ ) || EXISTING=""
+ if [ -z "${EXISTING}" ]; then
+ echo "::error::Failed to create the cherry-pick PR for
${HEAD_REF}."
+ exit 1
+ fi
+ echo "Cherry-pick PR already exists: ${EXISTING}"
fi
- gh pr create "${CREATE_ARGS[@]}" || echo "Failed to create PR, may
already exist"