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

GitHub Action中glob匹配markdown文件仅返回docs目录文件如何解决?

问题解决方案:GitHub Actions 中 glob 匹配仅返回 docs 目录下 md 文件的问题

问题根源

GitHub Actions 运行环境的默认 Bash 未开启 globstar 选项,此时 ** 通配符仅会匹配一级子目录,不会递归遍历所有层级的子文件夹,因此只会返回第一层子目录下的 md 文件,本地环境如果默认开启 globstar(如 Zsh、手动配置过的 Bash)运行命令就会正常。

解决方法

方案1:开启 Bash globstar 选项(兼容原写法)

直接在 run 脚本开头开启 globstar 即可让 ** 生效,修改后的配置如下:

- name: 'Spellchecking Content'
        run: |
          shopt -s globstar
          npm install cspell -g
          pwd
          ls ./**/*.md
          npx cspell $(ls ./**/*.md) -c ${{ github.workspace }}/cspell.json
        working-directory: ${{ github.workspace }}

方案2:使用 find 命令实现文件匹配(兼容性更高)

find 命令不依赖 Bash 全局配置,适配所有环境,还可以规避文件名带空格、特殊字符导致的解析错误,推荐使用:

- name: 'Spellchecking Content'
        run: |
          npm install cspell -g
          pwd
          find . -name "*.md" -type f
          find . -name "*.md" -type f -print0 | xargs -0 npx cspell -c ${{ github.workspace }}/cspell.json
        working-directory: ${{ github.workspace }}

验证方法

如果需要确认配置项状态,可以在 run 脚本中添加以下命令查看 globstar 开启状态:

shopt | grep globstar

输出结果为 globstar on 代表配置生效。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 12:54:03