1+ name : Generate Code Coverage Report
2+ on :
3+ push :
4+ branches :
5+ - main
6+ permissions :
7+ contents : write
8+ jobs :
9+ test :
10+ if : ${{ github.actor != 'dependabot[bot]' }}
11+ runs-on : ubuntu-latest
12+ name : PHP setup
13+ steps :
14+
15+ - name : Checkout code
16+ uses : actions/checkout@v3
17+ with :
18+ ref : main
19+ fetch-depth : 0
20+ - name : Install SQLite 3
21+ run : |
22+ sudo apt-get update
23+ sudo apt-get install sqlite3
24+ - name : Setup PHP
25+ uses : shivammathur/setup-php@v2
26+ with :
27+ php-version : 8.1
28+ extensions : curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv, xdebug
29+ coverage : xdebug
30+ tools : composer:v2
31+ - name : Install dependencies
32+ run : |
33+ composer require "laravel/framework:^9.0" "phpunit/phpunit:^9.0" "doctrine/dbal:^3.0" --no-interaction --no-update --no-suggest
34+ composer update --prefer-dist --no-interaction
35+ - name : Execute tests
36+ run : vendor/bin/phpunit --coverage-clover coverage.xml
37+ - name : Check test coverage
38+ id : test-coverage
39+ uses : johanvanhelden/gha-clover-test-coverage-check@v1
40+ with :
41+ percentage : " 1"
42+ filename : coverage.xml
43+ metric : elements
44+ rounded-precision : 2
45+ - name : Generate the badge SVG image
46+ uses : emibcn/badge-action@v1
47+ id : badge
48+ with :
49+ label : coverage
50+ status : ${{ steps.test-coverage.outputs.coverage-rounded-display }}
51+ path : ./test-coverage.svg
52+ color : ${{ steps.test-coverage.outputs.coverage > 90 && 'green' ||
53+ steps.test-coverage.outputs.coverage > 80 && 'yellow,green' ||
54+ steps.test-coverage.outputs.coverage > 70 && 'yellow' ||
55+ steps.test-coverage.outputs.coverage > 60 && 'orange,yellow' ||
56+ steps.test-coverage.outputs.coverage > 50 && 'orange' ||
57+ steps.test-coverage.outputs.coverage > 40 && 'red,orange' ||
58+ steps.test-coverage.outputs.coverage > 30 && 'red,red,orange' ||
59+ steps.test-coverage.outputs.coverage > 20 && 'red,red,red,orange' ||
60+ ' red' }}
61+ - name : Upload badge as artifact
62+ uses : actions/upload-artifact@v3
63+ with :
64+ name : badge
65+ path : test-coverage.svg
66+ if-no-files-found : error
67+ - name : Commit badge
68+ continue-on-error : true
69+ env :
70+ BADGE : test-coverage.svg
71+ run : |
72+ git config --local user.email "[email protected] " 73+ git config --local user.name "GitHub Action"
74+ git add "${BADGE}"
75+ git commit -m "Update Coverage Badge"
76+ - name : Push badge commit
77+ uses : ad-m/github-push-action@master
78+ if : ${{ success() }}
79+ with :
80+ force : true
81+ github_token : ${{ secrets.COVERAGE_TOKEN }}
82+ branch : coverage-badge-dont-delete
0 commit comments