Skip to content

ci(docs-stage): 让 fork PR 也能预览(label 门控 + 只覆盖 md/html)#1635

Open
chenglu wants to merge 1 commit into
mainfrom
preview-fork-prs-with-label-gate
Open

ci(docs-stage): 让 fork PR 也能预览(label 门控 + 只覆盖 md/html)#1635
chenglu wants to merge 1 commit into
mainfrom
preview-fork-prs-with-label-gate

Conversation

@chenglu

@chenglu chenglu commented Jun 23, 2026

Copy link
Copy Markdown
Member

之前 docs-stage 用 on: pull_request,fork PR 拿不到部署 secret,且显式
if: head.repo.full_name == 'cfug/flutter.cn' 直接跳过 fork。本改动:

  • 改用 pull_request_target(在 base 仓库上下文运行,fork PR 也有 secret)
  • fork PR 默认不触发,需维护者审过内容后打 'safe to preview' 标签才构建
  • 同仓库 PR 仍检出 PR head 完整预览;fork PR 只检出可信 base 代码,再用 GitHub API 把改动的 md/html(限 sites/docs/src/content/ 下、排除越界)覆盖进来, 用 base 仓库自己的 dash_site/translator 构建。绝不检出/执行 fork 代码。

之前 docs-stage 用 on: pull_request,fork PR 拿不到部署 secret,且显式
`if: head.repo.full_name == 'cfug/flutter.cn'` 直接跳过 fork。本改动:

- 改用 pull_request_target(在 base 仓库上下文运行,fork PR 也有 secret)
- fork PR 默认不触发,需维护者审过内容后打 'safe to preview' 标签才构建
- 同仓库 PR 仍检出 PR head 完整预览;fork PR 只检出可信 base 代码,再用
  GitHub API 把改动的 md/html(限 sites/docs/src/content/ 下、排除越界)覆盖进来,
  用 base 仓库自己的 dash_site/translator 构建。绝不检出/执行 fork 代码。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chenglu chenglu requested a review from a team as a code owner June 23, 2026 21:06
# 只检出这些受控路径;pathspec 限定在仓库根目录下的指定文件,无法写到仓库之外
xargs -a overlay-files.txt git checkout pr-head --
else
echo "没有匹配的 md/html 改动,按 base 内容构建。"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

如果没匹配到改动,是不是可以直接不用再构建了

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

好主意,我转交给 Claude 老师。

# 并排除含 .. 的越界路径与含空白的路径
gh api --paginate "repos/${GH_REPO}/pulls/${PR_NUMBER}/files" \
--jq '.[] | select(.status != "removed") | .filename' \
| grep -E '^sites/docs/src/content/[^[:space:]]+\.(md|html)$' \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

_includes 同样是文档的部分,也经常需要修改,建议也加入进来。

Suggested change
| grep -E '^sites/docs/src/content/[^[:space:]]+\.(md|html)$' \
| grep -E '^sites/docs/src/(content|_includes)/[^[:space:]]+\.(md|html)$' \

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.

3 participants