[CI] Add cherry-pick workflow#7721
Conversation
|
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7721.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
There was a problem hiding this comment.
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 -->" |
There was a problem hiding this comment.
注释中提到使用 COPY-FROM 标记来复制示例代码,但这个注释似乎与当前的 cherry-pick 工作流无关,可能是从其他地方复制过来的。这个 devPR 注释是用于 CI 检查的,应该明确说明其目的,避免混淆。
| devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER <!-- For pass CI -->" | |
| devPR:https://github.com/PaddlePaddle/docs/pull/$PR_NUMBER (供 CI 关联对应的开发分支 PR,请勿删除此行)" |
| @@ -0,0 +1,190 @@ | |||
| name: Cherry Pick | |||
There was a problem hiding this comment.
标题格式符合仓库规范([CI] Add cherry-pick workflow),但描述过于简略。建议补充以下信息:1) 如何配置 CHERRY_PICK_BOT_TOKEN secret;2) bot 账号的用户名和邮箱应该如何设置;3) 是否需要创建 fork 仓库;4) 使用示例(如何通过添加 label 触发 cherry-pick)。
| BOT_USERNAME: ShigureNyako | ||
| BOT_EMAIL: shigure_nyako@outlook.com | ||
| REPO_NAME: ShigureNyako/paddle-docs |
There was a problem hiding this comment.
这里硬编码了个人用户名和邮箱(ShigureNyako 和 shigure_nyako@outlook.com),应该使用组织的 bot 账号或者从 GitHub App/Token 中动态获取,避免使用个人账户信息。
| 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 }} |
| 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 |
There was a problem hiding this comment.
建议添加仓库检查条件(类似 .github/workflows/codestyle-check.yml:20 中的 github.repository_owner == 'PaddlePaddle'),确保工作流只在官方仓库中运行,避免在 fork 仓库中意外触发。
| 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') |
There was a problem hiding this comment.
在 line 158 检查 PR 是否存在时,使用了 --head "$NEW_BRANCH",但如果 cherry-pick 是推送到 fork 仓库,应该使用 --head "${BOT_USERNAME}:${NEW_BRANCH}" 来正确匹配。这与 line 155 的 HEAD_REF 设置应该保持一致。
| MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }} | ||
| BOT_USERNAME: ShigureNyako | ||
| BOT_EMAIL: shigure_nyako@outlook.com | ||
| REPO_NAME: ShigureNyako/paddle-docs |
There was a problem hiding this comment.
这里硬编码了个人用户名和仓库名(ShigureNyako/paddle-docs),应该使用 ${{ github.repository }} 来动态获取当前仓库的名称,确保工作流可以在正确的仓库中运行。
| REPO_NAME: ShigureNyako/paddle-docs | |
| REPO_NAME: ${{ github.repository }} |
| persist-credentials: false | ||
|
|
||
| - name: Cherry Pick | ||
| env: |
There was a problem hiding this comment.
使用了自定义的 secret CHERRY_PICK_BOT_TOKEN,但在 PR 描述中没有说明如何配置此 token。建议在 PR 描述中补充说明:1) 需要创建这个 secret;2) token 需要哪些权限(例如 contents: write, pull-requests: write);3) 是否需要是 GitHub App token 或 PAT。
| 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 中。 |
| # Construct authenticated URL for the fork | ||
| FORK_URL_AUTH="https://${BOT_USERNAME}:${GH_TOKEN}@github.com/${REPO_NAME}.git" |
There was a problem hiding this comment.
这里将 bot 的用户名和 fork 的仓库名拼接成认证 URL,但由于 REPO_NAME 被硬编码为 ShigureNyako/paddle-docs,这会导致推送到错误的仓库。应该使用 ${{ github.repository_owner }}/${{ github.event.repository.name }} 或直接使用 ${{ github.repository }} 来构建正确的 URL。
| # 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" |
| # Prepare head ref for PR creation (owner:branch) | ||
| HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}" |
There was a problem hiding this comment.
这里使用了 HEAD_REF="${BOT_USERNAME}:${NEW_BRANCH}" 来创建从 fork 到上游的 PR,但实际上如果 bot 账号不是 fork 的 owner,而是直接推送到主仓库的分支,这个格式会出错。应该明确这个工作流是推送到 fork 还是主仓库,并相应调整 HEAD_REF 的格式。如果推送到主仓库,应该使用 HEAD_REF="${NEW_BRANCH}"。
| # 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}" |
| 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 -->" |
There was a problem hiding this comment.
在处理 PR body 时,直接将 $PR_BODY 嵌入到 shell 脚本中可能存在命令注入风险。如果 PR 的 body 中包含特殊字符(如 backticks、dollar signs),可能会被意外执行。建议使用更安全的方式处理,例如将 body 写入临时文件或使用适当的引号和转义。
同 PaddlePaddle/Paddle#77160,可通过添加 label 实现自动 cherry-pick