Skip to content

Commit

Permalink
coverage check
Browse files Browse the repository at this point in the history
  • Loading branch information
mike4git committed Aug 20, 2024
1 parent 4524268 commit e2f87ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A default implementation of the Converter & Populator design pattern.

![Coverage Status](https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_%COVERAGE%.svg)

## Installation

1. **Require the bundle**
Expand Down
41 changes: 41 additions & 0 deletions check_coverage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

$xmlContent = file_get_contents('.coverage/cobertura.xml');
$matches = [];
preg_match("#coverage line-rate=\"(.*)\"#U", $xmlContent, $matches);

$coverage = (int) ((float) $matches[1] * 100);

echo "Coverage: " . $coverage . "%\n";

// Dateipfad festlegen
$file = 'README.md';

// Den Inhalt der Datei lesen
$content = file_get_contents($file);

if ($content === false) {
die("Die README.md konnte nicht gelesen werden.");
}

// Das zu ersetzende Token definieren
$search = '%COVERAGE%';


// Das Token durch den Ersatztext ersetzen
$newContent = str_replace($search, $coverage, $content);

// Den neuen Inhalt zurück in die Datei schreiben
$result = file_put_contents($file, $newContent);

if ($result === false) {
die("Fehler beim Schreiben der README.md.");
}

if ($coverage < 80) {
echo "Test coverage is below 80%\n";
exit(1); // Gibt einen Fehlercode zurück, der den Build fehlschlagen lässt
}

echo "Test coverage is sufficient.\n";
exit(0);

0 comments on commit e2f87ad

Please sign in to comment.