Generate readme badges during your pre-push

1.1.0 2024-04-15 14:24 UTC

This package is auto-updated.

Last update: 2024-10-15 15:25:40 UTC


README

Generate badges as part of your pre-push hooks!

Installation

  1. Add networkrailbusinesssystems/badges to your Composer dev dependencies
composer require --dev networkrailbusinesssystems/badges
  1. Ensure that PHPUnit outputs logs and coverage with the following settings:
<coverage>
    <report>
        <html outputDirectory=".phpunit.cache/html" />
        <text outputFile=".phpunit.cache/coverage.txt" showUncoveredFiles="false" showOnlySummary="true" />
    </report>
</coverage>
<logging>
    <junit outputFile=".phpunit.cache/tests.xml" />
</logging>
  1. Add the following commands to the pre-push hook:
php vendor/networkrailbusinesssystems/badges/badges.php
git add .github/*.svg
git diff-index --quiet --cached HEAD || git commit -m "Updated badges" --no-verify
  1. Add the following lines to readme.md, excluding badges as required:
![Composer status](.github/composer.svg)
![Coverage status](.github/coverage.svg)
![Frontend version](.github/frontend.svg)
![Laravel version](.github/laravel.svg)
![NPM status](.github/npm.svg)
![PHP version](.github/php.svg)
![Tests status](.github/tests.svg)

Debug driver

You must have either xdebug or PCOV installed to run coverage checks, and enable the coverage mode.

PCOV is generally newer and faster than XDebug, however it may not be as accurate.

XDebug

  1. sudo apt install php-xdebug
  2. Add the following to the end of your php.ini:
[xdebug]
xdebug.mode=coverage

PCOV

  1. sudo apt install php8.2-dev
  2. sudo apt install php-pear
  3. sudo pecl install pcov
  4. Add the following to the end of your php.ini:
[pcov]
extension=pcov.so

Usage

  1. Run git push as normal
  2. The pre-push hooks will fire, running your tests and coverage
  3. The badges will automatically generate, update, and be added to the commit