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

Github Actions中trilom/file-changes-action报错,新分支无法自动修复文件求助

问题排查与解决方案

结合你的配置和问题现象,合并main分支后新分支推送无法触发sqlfluff修复,大概率是文件变更检测失效或者流程中的错误被掩盖,以下是具体排查方向和修复方案:

1. 替换老旧的文件变更检测Action

trilom/file-changes-action@v1.2.4已多年未维护,在分支合并场景下极易出现文件变更识别错误,导致pre-commit的--files参数为空,根本没执行修复逻辑。建议换成官方可靠的方式获取变更文件:

修改sqlfluff_linter.yml中的文件变更步骤:

- id: file_changes
  uses: actions/github-script@v6
  with:
    script: |
      const changes = await github.rest.repos.getCommit({
        owner: context.repo.owner,
        repo: context.repo.repo,
        ref: context.sha
      });
      const files = changes.data.files.map(f => f.filename).join(' ');
      core.setOutput('files', files);

2. 移除continue-on-error: true

你给所有步骤都添加了这个配置,会直接掩盖流程中的错误(比如文件变更步骤失败、pre-commit执行报错),导致你无法定位真正的问题根源。删掉所有continue-on-error: true,让Action在出错时直接终止,方便排查。

3. 验证文件变更参数有效性

在pre-commit步骤前添加打印逻辑,确认steps.file_changes.outputs.files是否获取到了正确的变更文件列表:

- name: 打印变更文件
  run: echo "变更文件列表: ${{ steps.file_changes.outputs.files }}"

如果输出为空,说明文件变更检测逻辑确实存在问题,优先执行方案1替换Action。

4. 优化checkout分支拉取逻辑

虽然你设置了fetch-depth: 0,但在on: push触发场景下,可以明确指定拉取当前分支,避免合并后分支历史识别混乱:

- uses: actions/checkout@v3
  with:
    fetch-depth: 0
    ref: ${{ github.head_ref || github.ref_name }}

最终修改后的sqlfluff_linter.yml示例

name: lint
on: push
jobs:
  lint:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.head_ref || github.ref_name }}
      - uses: actions/setup-python@v3
      - id: file_changes
        uses: actions/github-script@v6
        with:
          script: |
            const changes = await github.rest.repos.getCommit({
              owner: context.repo.owner,
              repo: context.repo.repo,
              ref: context.sha
            });
            const files = changes.data.files.map(f => f.filename).join(' ');
            core.setOutput('files', files);
      - name: 打印变更文件
        run: echo "变更文件列表: ${{ steps.file_changes.outputs.files }}"
      - uses: pre-commit/action@v3.0.0
        with:
          extra_args: --color=always --files ${{ steps.file_changes.outputs.files}}
      - uses: stefanzweifel/git-auto-commit-action@v4

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 08:53:36