'Github Action CI should fail when code coverage is not 100%
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%.
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Harsh Mishra |
