You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何判断GitHub Action运行于公共仓库还是私有仓库?

GitHub Actions 中判断仓库公私的字段

有的,github 对象里存在用于判断仓库公/私的字段:github.event.repository.private,它是一个布尔值:

  • 当值为true时,代表当前仓库是私有仓库
  • 当值为false时,代表当前仓库是公共仓库

你可以在工作流中直接用这个字段做条件判断,比如:

jobs:
  check-repo-type:
    runs-on: ubuntu-latest
    steps:
      - name: 判断仓库类型
        run: |
          if [ "${{ github.event.repository.private }}" = "true" ]; then
            echo "这是私有仓库"
          else
            echo "这是公共仓库"
          fi

内容的提问来源于stack exchange,提问作者Mayank Kumar Chaudhari

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 21:48:08