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

如何在共享仓库中实现依赖/嵌套式GitHub Actions工作流与动作?

概述

我有一套需要在多个仓库复用的工作流和动作,打算存到单个"infra"仓库里。
这里有一个单一入口点(可复用工作流),这个工作流需要调用和它同仓库、同引用的其他工作流/动作。
GitHub文档里说明:

如果使用uses: ./path/to/local/workflow.yaml语法,被调用的工作流和调用者工作流来自同一提交。

但实际情况是,哪怕调用者工作流(入口点)位于共享仓库中,GitHub Actions(GHA)仍无法定位共享仓库内的被调用工作流。

测试环境

我搭建了测试用的实现:

  • 用户仓库:alliepiper/test_gha
  • 共享仓库:alliepiper/test_gha_infra

这些仓库可能会被删除,因此我将带注释的实现代码附在下方:

实现细节

工作流/动作定义如下:


用户工作流:alliepiper/test_gha/.github/workflows/level-0.yml

调用远程仓库中的入口点工作流:

name: Project Workflow
on:
  workflow_dispatch:
jobs:
  call-reusable-workflow:
    uses: alliepiper/test_gha_infra/.github/workflows/level-1.yml@v1

此部分可正常运行。


共享工作流入口点:alliepiper/test_gha_infra/.github/workflows/level-1.yml

使用uses中的本地路径,调用当前test_gha_infra共享仓库内的第二个可复用工作流:

name: First remote reusable workflow
on:
  workflow_call:
jobs:
  call-reusable-workflow:
    uses: ./.github/workflows/level-2.yml

此部分执行失败(错误信息见下文),后续工作流/动作无法继续执行。


第二个共享工作流:alliepiper/test_gha_infra/.github/workflows/level-2.yml

使用uses中的本地路径,调用当前test_gha_infra共享仓库内的一个动作:

name: Nested Remote Reusable Workflow
on:
  workflow_call:
jobs:
  invoke-action:
    runs-on: ubuntu-latest
    steps:
      - name: Run the action
        uses: ./.github/actions/level-3

共享动作:alliepiper/test_gha_infra/.github/actions/level-3/action.yml

仅输出Hello World:

name: "Nested remote reusable action"
runs:
  using: "composite"
  steps:
    - name: Output
      shell: bash
      run: |
        echo "Hello World!"
错误信息

错误内容:

Invalid workflow file: .github/workflows/level-0.yml#L12
error parsing called workflow".github/workflows/level-0.yml"
-> "alliepiper/test_gha_infra/.github/workflows/level-1.yml@v1" (source tag with sha:e7a9ca6ce6d0d85d16d24e9715abe852dc92bb7e)
--> "./.github/workflows/level-2.yml"
: workflow was not found. See https://docs.github.com/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.

内容的提问来源于stack exchange,提问作者Allison Piper

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 17:57:18