Skip to content

fork PR 触发 Lark notification 失败:secrets 不可用导致空 URL #113

Closed

Description

@luojiyin1987

问题

来自 fork 的 PR 触发 Lark notification 时失败,整个 Check 变红。

失败示例(miyaliu666/Open-Source-Bazaar.github.io:award-page):
https://github.com/Open-Source-Bazaar/Open-Source-Bazaar.github.io/actions/runs/32812529769/job/97694511026

关键日志:

Secret source: None

INPUT_URL:

##[error]No URL protocol specified
Process completed with exit code 1.

根因

GitHub 对来自 fork 的 pull_request 事件不暴露仓库的 Actions secrets。因此:

  1. secrets.LARK_CHATBOT_HOOK_URL 展开为空字符串
  2. feishu-action 收到空的 url
  3. action 把空字符串当 URL 解析,报 No URL protocol specified

Lark 通知属于辅助功能。fork PR 没有 secret 时应该跳过发送,不应该把整个 Check 弄红。

修复方案

GitHub Actions 规定 if: 条件不能直接引用 secrets.*。先把 secret 是否存在映射为 job 级 env,再在条件里检查:

env:
  HAS_LARK_WEBHOOK: ${{ secrets.LARK_CHATBOT_HOOK_URL != '' }}

if: ${{ contains(steps.message.outputs.content, ':') && env.HAS_LARK_WEBHOOK == 'true' }}

修复后的行为:

场景 行为
push / issues / discussions / release 不变,正常发送
仓库内分支的 PR 有 secret,正常发送
fork PR(含 pull_request_review_comment) 跳过发送,Check 保持绿色

不用 pull_request_target。该 workflow 会执行仓库内的 .github/scripts/transform-message.ts。在 pull_request_target 下 checkout 外部 PR 代码并暴露 secrets 会形成 secret 泄露风险。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions