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

MegaLinter中YAML Linter无法检测Git仓库文件问题求助

问题描述

在CI工作流中使用MegaLinter GitHub Action对包含YAML在内的多类文件做代码检查,YAML Linter已正常启动,但无法检测Git仓库中的文件。MegaLinter输出显示无法列出git忽略文件,最终仅保留0个文件。

工作流代码片段

name: Run CI Light Linters
on:
  push:
    branches:
      - main

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run CI Light Linters
        id: Mega-Linters
        if: ${{ inputs.ENABLE_LINTERS == '' }}
        uses: oxsecurity/megalinter/flavors/ci_light@fda6ac3a38be0e969820709ac16e442464e5a035
        with:
          # other configuration options...
          ENABLE_LINTERS: "YAML_PRETTIER"
        env:
          VALIDATE_ALL_CODEBASE: true
          continue-on-error: true

MegaLinter输出信息

MegaLinter now collects the files to analyse (expand for details)
Listing all files in directory [/github/workspace], then filter with:

  • File extensions: .yaml, .yml Unable to list git ignored files (/github/workspace) Kept [0] files on [0] found files

+----MATCHING LINTERS-+----------+----------------+------------+ | Descriptor | Linter | Criteria | Matching files | Format/Fix |
+------------+--------+----------+----------------+------------+

+----SUMMARY-+--------+------+-------+-------+--------+--------------+ | Descriptor | Linter | Mode | Files | Fixed | Errors | Elapsed time |
+------------+--------+------+-------+-------+--------+--------------+

Unable to find git repository to list updated files [Updated Sources
Reporter] No source file has been formatted or fixed ✅ Successfully
linted all files without errors

解决方案
  • 修复Checkout步骤的Git仓库拉取
    actions/checkout@v2默认只拉取最新提交,缺少Git仓库元数据,导致MegaLinter无法识别仓库。需添加fetch-depth: 0参数拉取完整仓库信息:

    - name: Checkout code
      uses: actions/checkout@v2
      with:
        fetch-depth: 0
    
  • 修正条件判断逻辑
    当前if: ${{ inputs.ENABLE_LINTERS == '' }}的条件在push触发场景下不成立(inputs未定义),会导致MegaLinter执行异常。如果不需要该条件,直接删除;若需保留,需确保ENABLE_LINTERS输入参数的取值符合预期。

  • 补充仓库根目录配置
    可通过环境变量明确指定Git仓库根目录,避免路径识别问题:

    env:
      VALIDATE_ALL_CODEBASE: true
      continue-on-error: true
      GIT_REPOSITORY_ROOT: /github/workspace
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 15:45:04