Update .gitea/workflows/pest.yml
This commit is contained in:
+106
-6
@@ -23,6 +23,13 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
default: '--coverage --coverage-clover=coverage.xml'
|
default: '--coverage --coverage-clover=coverage.xml'
|
||||||
|
coverage_badge:
|
||||||
|
required: false
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pest:
|
pest:
|
||||||
@@ -45,9 +52,102 @@ jobs:
|
|||||||
./vendor/bin/pest
|
./vendor/bin/pest
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Generate coverage badge
|
||||||
if: ${{ inputs.coverage }}
|
if: ${{ inputs.coverage_badge }}
|
||||||
uses: actions/upload-artifact@v3
|
run: |
|
||||||
with:
|
mkdir -p .gitea/badges
|
||||||
name: coverage
|
|
||||||
path: coverage.xml
|
php <<'PHP'
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$coverageFile = 'coverage.xml';
|
||||||
|
$badgeFile = '.gitea/badges/coverage.svg';
|
||||||
|
|
||||||
|
if (! file_exists($coverageFile)) {
|
||||||
|
fwrite(STDERR, "coverage.xml not found\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml = simplexml_load_file($coverageFile);
|
||||||
|
|
||||||
|
if (! $xml) {
|
||||||
|
fwrite(STDERR, "Could not parse coverage.xml\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$metrics = $xml->project->metrics ?? $xml->metrics ?? null;
|
||||||
|
|
||||||
|
if (! $metrics) {
|
||||||
|
fwrite(STDERR, "No coverage metrics found in coverage.xml\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$covered = (int) ($metrics['coveredstatements'] ?? 0);
|
||||||
|
$total = (int) ($metrics['statements'] ?? 0);
|
||||||
|
|
||||||
|
if ($total === 0) {
|
||||||
|
$percentage = 0;
|
||||||
|
} else {
|
||||||
|
$percentage = round(($covered / $total) * 100, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$color = match (true) {
|
||||||
|
$percentage >= 90 => '#4c1',
|
||||||
|
$percentage >= 80 => '#97ca00',
|
||||||
|
$percentage >= 70 => '#dfb317',
|
||||||
|
$percentage >= 60 => '#fe7d37',
|
||||||
|
default => '#e05d44',
|
||||||
|
};
|
||||||
|
|
||||||
|
$label = 'coverage';
|
||||||
|
$message = $percentage . '%';
|
||||||
|
|
||||||
|
$labelWidth = 68;
|
||||||
|
$messageWidth = 48;
|
||||||
|
$width = $labelWidth + $messageWidth;
|
||||||
|
|
||||||
|
$svg = <<<SVG
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="$width" height="20" role="img" aria-label="$label: $message">
|
||||||
|
<title>$label: $message</title>
|
||||||
|
<linearGradient id="s" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||||
|
<stop offset="1" stop-opacity=".1"/>
|
||||||
|
</linearGradient>
|
||||||
|
<clipPath id="r">
|
||||||
|
<rect width="$width" height="20" rx="3" fill="#fff"/>
|
||||||
|
</clipPath>
|
||||||
|
<g clip-path="url(#r)">
|
||||||
|
<rect width="$labelWidth" height="20" fill="#555"/>
|
||||||
|
<rect x="$labelWidth" width="$messageWidth" height="20" fill="$color"/>
|
||||||
|
<rect width="$width" height="20" fill="url(#s)"/>
|
||||||
|
</g>
|
||||||
|
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
|
||||||
|
<text aria-hidden="true" x="340" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="580">coverage</text>
|
||||||
|
<text x="340" y="140" transform="scale(.1)" fill="#fff" textLength="580">coverage</text>
|
||||||
|
<text aria-hidden="true" x="920" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="380">$message</text>
|
||||||
|
<text x="920" y="140" transform="scale(.1)" fill="#fff" textLength="380">$message</text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
SVG;
|
||||||
|
|
||||||
|
file_put_contents($badgeFile, $svg);
|
||||||
|
|
||||||
|
echo "Generated $badgeFile with $message\n";
|
||||||
|
PHP
|
||||||
|
|
||||||
|
- name: Commit coverage badge
|
||||||
|
if: ${{ inputs.coverage_badge && gitea.event_name == 'push' && gitea.ref == 'refs/heads/main' }}
|
||||||
|
run: |
|
||||||
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||||
|
git config user.name "gitea-actions"
|
||||||
|
git config user.email "gitea-actions@git.qlic.nl"
|
||||||
|
|
||||||
|
git add .gitea/badges/coverage.svg
|
||||||
|
|
||||||
|
if git diff --cached --quiet; then
|
||||||
|
echo "Coverage badge unchanged"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
git commit -m "Update coverage badge [skip ci]"
|
||||||
|
git push
|
||||||
Reference in New Issue
Block a user