Skip to content

[CI] Add cherry-pick workflow#7721

Merged
sunzhongkai588 merged 1 commit intoPaddlePaddle:developfrom
cattidea:ci/add-cherry-pick-workflow
Feb 4, 2026
Merged

[CI] Add cherry-pick workflow#7721
sunzhongkai588 merged 1 commit intoPaddlePaddle:developfrom
cattidea:ci/add-cherry-pick-workflow

Conversation

@SigureMo
Copy link
Member

@SigureMo SigureMo commented Feb 4, 2026

PaddlePaddle/Paddle#77160,可通过添加 label 实现自动 cherry-pick

Copilot AI review requested due to automatic review settings February 4, 2026 04:45
@paddle-bot
Copy link

paddle-bot bot commented Feb 4, 2026

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7721.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

此 PR 添加了一个 GitHub Actions 工作流,用于自动化 cherry-pick 流程,允许通过在已合并的 PR 上添加 cherry-pick:<branch> 标签来自动创建 cherry-pick PR 到目标分支。这与 PaddlePaddle/Paddle#77160 的实现类似。

Changes:

  • 添加了 .github/workflows/cherry-pick.yml 工作流文件,实现自动 cherry-pick 功能
  • 工作流在 PR 合并后通过 label 触发,支持 cherry-pick 到多个目标分支
  • 包含错误处理、PR 创建、评论通知等完整流程


Cherry-pick of #$PR_NUMBER (authored by @${PR_AUTHOR}) to \`$TARGET_BRANCH\`.

devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER <!-- For pass CI -->"
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中提到使用 COPY-FROM 标记来复制示例代码,但这个注释似乎与当前的 cherry-pick 工作流无关,可能是从其他地方复制过来的。这个 devPR 注释是用于 CI 检查的,应该明确说明其目的,避免混淆。

Suggested change
devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER <!-- For pass CI -->"
devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER (供 CI 关联对应的开发分支 PR,请勿删除此行)"

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,190 @@
name: Cherry Pick
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标题格式符合仓库规范([CI] Add cherry-pick workflow),但描述过于简略。建议补充以下信息:1) 如何配置 CHERRY_PICK_BOT_TOKEN secret;2) bot 账号的用户名和邮箱应该如何设置;3) 是否需要创建 fork 仓库;4) 使用示例(如何通过添加 label 触发 cherry-pick)。

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +41 to +43
BOT_USERNAME: ShigureNyako
BOT_EMAIL: shigure_nyako@outlook.com
REPO_NAME: ShigureNyako/paddle-docs
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里硬编码了个人用户名和邮箱(ShigureNyakoshigure_nyako@outlook.com),应该使用组织的 bot 账号或者从 GitHub App/Token 中动态获取,避免使用个人账户信息。

Suggested change
BOT_USERNAME: ShigureNyako
BOT_EMAIL: shigure_nyako@outlook.com
REPO_NAME: ShigureNyako/paddle-docs
BOT_USERNAME: ${{ secrets.CHERRY_PICK_BOT_USERNAME }}
BOT_EMAIL: ${{ secrets.CHERRY_PICK_BOT_EMAIL }}
REPO_NAME: ${{ github.repository }}

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +25
cherry-pick:
if: >
github.event.pull_request.merged == true &&
(
github.event.action == 'labeled' ||
contains(join(github.event.pull_request.labels.*.name, ' '), 'cherry-pick')
)
runs-on: ubuntu-latest
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议添加仓库检查条件(类似 .github/workflows/codestyle-check.yml:20 中的 github.repository_owner == 'PaddlePaddle'),确保工作流只在官方仓库中运行,避免在 fork 仓库中意外触发。

Copilot uses AI. Check for mistakes.
HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}"

# Check if PR already exists
EXISTING_PR=$(gh pr list --base "$TARGET_BRANCH" --head "$NEW_BRANCH" --json url --jq '.[0].url')
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 line 158 检查 PR 是否存在时,使用了 --head "$NEW_BRANCH",但如果 cherry-pick 是推送到 fork 仓库,应该使用 --head "${BOT_USERNAME}:${NEW_BRANCH}" 来正确匹配。这与 line 155 的 HEAD_REF 设置应该保持一致。

Copilot uses AI. Check for mistakes.
MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
BOT_USERNAME: ShigureNyako
BOT_EMAIL: shigure_nyako@outlook.com
REPO_NAME: ShigureNyako/paddle-docs
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里硬编码了个人用户名和仓库名(ShigureNyako/paddle-docs),应该使用 ${{ github.repository }} 来动态获取当前仓库的名称,确保工作流可以在正确的仓库中运行。

Suggested change
REPO_NAME: ShigureNyako/paddle-docs
REPO_NAME: ${{ github.repository }}

Copilot uses AI. Check for mistakes.
persist-credentials: false

- name: Cherry Pick
env:
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用了自定义的 secret CHERRY_PICK_BOT_TOKEN,但在 PR 描述中没有说明如何配置此 token。建议在 PR 描述中补充说明:1) 需要创建这个 secret;2) token 需要哪些权限(例如 contents: write, pull-requests: write);3) 是否需要是 GitHub App token 或 PAT。

Suggested change
env:
env:
# 注意:这里使用的是自定义 secret `CHERRY_PICK_BOT_TOKEN`,需要在仓库或组织的 Secrets 中预先创建。
# 建议配置方式:
# 1. 可以使用 GitHub App 安装 token,或具备最小权限的 PAT(不推荐复用个人主力账号的 PAT)。
# 2. 需要至少具备以下权限,以满足本工作流中 `contents: write`、`pull-requests: write` 的需求:
# - 对仓库代码(contents):write
# - 对 Pull Request(pull-requests):write
# 3. 将该 token 以名称 `CHERRY_PICK_BOT_TOKEN` 存入当前仓库(或组织)的 Repository Secret 中。

Copilot uses AI. Check for mistakes.
Comment on lines +132 to +133
# Construct authenticated URL for the fork
FORK_URL_AUTH="https://${BOT_USERNAME}:${GH_TOKEN}@github.com/${REPO_NAME}.git"
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里将 bot 的用户名和 fork 的仓库名拼接成认证 URL,但由于 REPO_NAME 被硬编码为 ShigureNyako/paddle-docs,这会导致推送到错误的仓库。应该使用 ${{ github.repository_owner }}/${{ github.event.repository.name }} 或直接使用 ${{ github.repository }} 来构建正确的 URL。

Suggested change
# Construct authenticated URL for the fork
FORK_URL_AUTH="https://${BOT_USERNAME}:${GH_TOKEN}@github.com/${REPO_NAME}.git"
# Construct authenticated URL for the fork using the current repository
FORK_URL_AUTH="https://${BOT_USERNAME}:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +155
# Prepare head ref for PR creation (owner:branch)
HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}"
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用了 HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}" 来创建从 fork 到上游的 PR,但实际上如果 bot 账号不是 fork 的 owner,而是直接推送到主仓库的分支,这个格式会出错。应该明确这个工作流是推送到 fork 还是主仓库,并相应调整 HEAD_REF 的格式。如果推送到主仓库,应该使用 HEAD_REF="${NEW_BRANCH}"

Suggested change
# Prepare head ref for PR creation (owner:branch)
HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}"
# Prepare head ref for PR creation (same-repo branch)
HEAD_REF="${NEW_BRANCH}"

Copilot uses AI. Check for mistakes.
Comment on lines +146 to +152
NEW_BODY="$PR_BODY

---

Cherry-pick of #$PR_NUMBER (authored by @${PR_AUTHOR}) to \`$TARGET_BRANCH\`.

devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER <!-- For pass CI -->"
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在处理 PR body 时,直接将 $PR_BODY 嵌入到 shell 脚本中可能存在命令注入风险。如果 PR 的 body 中包含特殊字符(如 backticks、dollar signs),可能会被意外执行。建议使用更安全的方式处理,例如将 body 写入临时文件或使用适当的引号和转义。

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, 牛啊

@sunzhongkai588 sunzhongkai588 merged commit 38105d1 into PaddlePaddle:develop Feb 4, 2026
10 checks passed
@SigureMo SigureMo deleted the ci/add-cherry-pick-workflow branch February 4, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants