Skip to content

Commit

Permalink
[FEATURE] Collect code coverage and add a coverage badge (#1160)
Browse files Browse the repository at this point in the history
Fixes #1126
Fixes #807
  • Loading branch information
oliverklee authored Aug 28, 2024
1 parent db52b75 commit e0a18a2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/codecoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

on:
push:
branches:
- main
pull_request:

name: Code coverage

jobs:
code-coverage:
name: Code coverage

runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
php-version:
- '8.3'
dependencies:
- highest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-file: development
tools: composer:v2
coverage: xdebug

- name: Show the Composer version
run: composer --version

- name: Show the Composer configuration
run: composer config --global --list

- name: Cache dependencies installed with composer
uses: actions/cache@v4
with:
path: ~/.cache/composer
key: php${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-
- name: Install Composer dependencies
run: |
if [[ "${{ matrix.dependencies }}" == 'lowest' ]]; then
DEPENDENCIES='--prefer-lowest';
else
DEPENDENCIES='';
fi;
composer install --no-progress;
composer update --with-dependencies --no-progress "${DEPENDENCIES}";
composer show;
- name: Run Tests
run: composer ci:tests:coverage

- name: Show generated coverage files
run: ls -lah

- name: Upload coverage results to Coveralls
uses: coverallsapp/github-action@v2
env:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ nbproject
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/coverage.xml
/vendor/
composer.lock
/.phive
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Latest Stable Version](https://poser.pugx.org/pelago/emogrifier/v/stable.svg)](https://packagist.org/packages/pelago/emogrifier)
[![Total Downloads](https://poser.pugx.org/pelago/emogrifier/downloads.svg)](https://packagist.org/packages/pelago/emogrifier)
[![License](https://poser.pugx.org/pelago/emogrifier/license.svg)](https://packagist.org/packages/pelago/emogrifier)
[![Coverage Status](https://coveralls.io/repos/github/MyIntervals/emogrifier/badge.svg?branch=main)](https://coveralls.io/github/MyIntervals/emogrifier?branch=main)

_n. e•mog•ri•fi•er [\ē-'mä-grƏ-,fī-Ər\] - a utility for changing completely the
nature or appearance of HTML email, esp. in a particularly fantastic or bizarre
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"ci:tests": [
"@ci:tests:unit"
],
"ci:tests:coverage": "phpunit --do-not-cache-result --coverage-clover=coverage.xml",
"ci:tests:sof": "phpunit --stop-on-failure --do-not-cache-result",
"ci:tests:unit": "phpunit --do-not-cache-result",
"composer:normalize": "\"./.phive/composer-normalize\" --no-check-lock",
Expand All @@ -117,6 +118,7 @@
"ci:php:stan": "Checks the PHP types using PHPStan.",
"ci:static": "Runs all static code analysis checks for the code and the composer.json.",
"ci:tests": "Runs all dynamic tests (i.e., currently, the unit tests).",
"ci:tests:coverage": "Runs the unit tests with code coverage.",
"ci:tests:sof": "Runs the unit tests and stops at the first failure.",
"ci:tests:unit": "Runs all unit tests.",
"composer:normalize": "Reformats and sorts the composer.json file.",
Expand Down

0 comments on commit e0a18a2

Please sign in to comment.