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

Pylint-fail-under未终止GitHub Action任务问题求助

解决GitHub Action中Pylint评分低于6.0时终止任务的问题

你可以通过两种方式实现需求:单个文件评分不达标即终止,或项目整体平均评分不达标即终止,以下是对应的配置修改方案:

场景1:单个文件评分低于6.0立即终止任务

修改工作流中代码检查步骤的命令,调整阈值并让find在首个不达标文件出现时停止执行:

name: Python Linting
on:
  push:
    branches:
      - 'test'

jobs:
  linting:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pylint pylint-fail-under umsgpack cryptography
      - name: Analysing the code with pylint
        run: find . -type f -name '*.py' -not -path '*/__pycache__/*' -not -path '*/venv/*' -exec pylint-fail-under --fail-under=6.0 --enable=W {} \; -quit

关键修改点:

  • 将--fail-under=7.0改为--fail-under=6.0,匹配你的评分阈值要求
  • 添加-not -path参数排除缓存目录和虚拟环境文件,避免无效检查
  • 增加-quit选项,让find在首个文件检查失败时立即停止后续执行,触发GitHub Action任务终止

场景2:项目整体平均评分低于6.0终止任务

若需要基于所有Python文件的平均评分判断,直接用pylint-fail-under扫描整个项目目录即可:

name: Python Linting
on:
  push:
    branches:
      - 'test'

jobs:
  linting:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pylint pylint-fail-under umsgpack cryptography
      - name: Analysing the code with pylint
        run: pylint-fail-under --fail-under=6.0 --enable=W .

说明:

  • .表示扫描当前目录下所有符合规则的Python文件(自动忽略__pycache__等默认排除项)
  • pylint-fail-under会计算所有文件的平均评分,若低于6.0则返回非零退出码,GitHub Action会自动终止任务

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 06:33:26