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

GitHub Actions执行失败:找不到指定文件或目录

排查Sphinx GitHub Actions工作流目录不存在错误

核心问题分析

错误提示No such file or directory指向工作目录/home/runner/work/Repo_Name/Repo_Name/Directory_Name/docs/python不存在,本地nektos act正常但GitHub Actions失败,大概率是路径大小写/拼写问题(Linux环境区分大小写,本地Windows/macOS通常不区分),或者目录结构与预期不符。

排查与修复步骤

  • 第一步:验证目录结构
    在Checkout repository步骤后添加目录检查,确认目标路径是否存在:

    - name: Check target directory existence
      run: |
        ls -la
        if [ ! -d "Directory_Name/docs/python" ]; then
          echo "ERROR: Target directory missing!"
          ls -laR > directory-structure.txt
          cat directory-structure.txt
        fi
    

    运行工作流后查看日志,确认实际目录结构与配置中的路径是否一致,重点检查大小写和拼写。

  • 第二步:修正路径大小写/拼写
    如果发现路径拼写错误或大小写不匹配,修改工作流中working-directory和path字段的路径,与仓库实际目录结构完全一致。例如仓库中实际是directory_name/docs/python,则对应调整配置中的路径。

  • 第三步:确认Checkout完整性
    若目录确实存在但仍报错,检查actions/checkout是否拉取了完整仓库:

    - name: Checkout repository
      uses: actions/checkout@v3
      with:
        fetch-depth: 0  # 拉取完整仓库历史,避免子目录未被检出
    
  • 第四步:检查Make依赖(次要)
    若目录问题解决后仍有make相关错误,确保Ubuntu runner安装了必要工具:

    - name: Install build tools
      run: sudo apt-get update && sudo apt-get install -y make
    

修正后的示例工作流片段

jobs:
  build-python-docs:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v3

    - name: Verify directory structure
      run: ls -laR Directory_Name/docs/ || echo "Directory not found"

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.10' 

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install sphinx
        pip install -r requirements.txt
        sudo apt-get update && sudo apt-get install -y make  # 按需添加

    - name: Build HTML
      run: make html
      working-directory: Directory_Name/docs/python

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 22:03:19