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

GitHub复用工作流稀疏检出报错,求排查解决方法

问题描述

Repo A的目录结构:

.github
|___ workflows
     |___ called
          |____ action.yml

在Repo B中编写的工作流:

name: notify
on:
  label:
    types: [edited]

jobs:
  call-workflow-1-in-local-repo:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout action
        uses: actions/checkout@v4
        with:
          repository: me/repo-a
          ref: main
          path: ./shared-workflows
          sparse-checkout: .github/workflows
          sparse-checkout-cone-mode: false

      - name: Use reusable workflow
        uses: ./shared-workflows/called 
        with:
         instance: 'lorem'

运行时报错:

call-workflow-1-in-local-repo
Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/repo-b/repo-b/shared-workflows/called'. Did you forget to run actions/checkout before running your local action?

添加调试步骤:

- name: ls
  run: |
    echo $(pwd)
    echo $(ls)
    echo $(ls shared-workflows)

输出显示shared-workflows目录为空:

/home/runner/work/repo-b/repo-b
shared-workflows
# EMPTY LINE

全量检出整个仓库可正常运行,但不想拉取额外代码,问遗漏了什么?


解决方案

问题出在稀疏检出的路径配置和后续引用路径的匹配错误:

  1. 稀疏检出路径未精准定位目标目录:关闭cone模式后,sparse-checkout仅指定.github/workflows不会自动递归拉取子目录内容,导致called目录及其中的action.yml未被检出。
  2. 引用路径与实际检出结构不匹配:稀疏检出会保留仓库根目录的层级结构,即使拉取成功,called目录也会位于shared-workflows/.github/workflows/下,而非直接在shared-workflows根目录。

修正后的工作流步骤如下:

- name: Checkout action
  uses: actions/checkout@v4
  with:
    repository: me/repo-a
    ref: main
    path: ./shared-workflows
    sparse-checkout: .github/workflows/called
    sparse-checkout-cone-mode: false

- name: Use reusable workflow
  uses: ./shared-workflows/.github/workflows/called 
  with:
   instance: 'lorem'

这样既能精准拉取目标目录的必要文件,又能通过正确路径引用到action.yml,避免全量检出冗余代码。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 20:42:41