当代码覆盖率不是 100% 时,Github Action CI 应该会失败

发布于 2025-01-14 19:30:51 字数 906 浏览 4 评论 0原文

我想检查 Github Action CI 中推送和拉取请求的代码覆盖率。我正在使用 Symfony。我找到了针对 Javascript 的操作,但没有找到针对 PHP 或基于 Symfony 的操作。

我已经创建了一个 GitHub 操作工作流程,如下所示:

name: Running Code Coverage

on: [push, pull_request]

jobs:
  build:
    name: Code Coverage
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php-version: [8.1]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up PHP ${{ matrix.php-version }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v1
        with:
          token: ${{ secrets.CODECOV_SECRET_TOKEN }}
          fail_ci_if_error: true
          files: ./coverage_report.xml 

但我无法使用上述方法实现我的最终目标,因为它将代码覆盖率上传到 codecov,在那里我可以看到 %age。

我的目标是,当代码覆盖率低于 100% 等阈值时,CI 应该失败。

I want to check the code coverage percentage in the Github Action CI on push and pull requests. I'm using Symfony. I've found actions for Javascript but not for PHP or Symfony-based.

I've already created a GitHub action workflow which is as below:

name: Running Code Coverage

on: [push, pull_request]

jobs:
  build:
    name: Code Coverage
    runs-on: ubuntu-latest

    strategy:
      matrix:
        php-version: [8.1]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up PHP ${{ matrix.php-version }}
        uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-version }}

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v1
        with:
          token: ${{ secrets.CODECOV_SECRET_TOKEN }}
          fail_ci_if_error: true
          files: ./coverage_report.xml 

But I cannot achieve my end goal using the above as it uploads the code coverage to codecov and there I can see the %age.

My goal is that the CI should fail when the code coverage is below a threshold like 100%.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贩梦商人 2025-01-21 19:30:52

参考关于阈值的官方文档

阈值(数字):允许覆盖率下降 X%,并发布成功状态。

以下是来自同一文档的示例 codecov.yml 引用:

coverage:
  status:
    project:
      default:
        # basic
        target: auto
        threshold: 0%
        base: auto 
        flags: 
          - unit
        paths: 
          - "src"
       # advanced settings
        branches: 
          - master
        if_ci_failed: error #success, failure, error, ignore
        informational: false
        only_pulls: false

Referencing from the official docs on threshold:

threshold (number): Allow the coverage to drop by X%, and posting a success status.

Here is an example codecov.yml reference from the same docs:

coverage:
  status:
    project:
      default:
        # basic
        target: auto
        threshold: 0%
        base: auto 
        flags: 
          - unit
        paths: 
          - "src"
       # advanced settings
        branches: 
          - master
        if_ci_failed: error #success, failure, error, ignore
        informational: false
        only_pulls: false
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文