@@ -3,6 +3,10 @@ name: Run tests
3
3
on :
4
4
- push
5
5
6
+ permissions :
7
+ checks : write
8
+ pull-requests : write # necessary to publish results in PR
9
+
6
10
jobs :
7
11
tests :
8
12
runs-on : ubuntu-latest
@@ -41,18 +45,42 @@ jobs:
41
45
- name : Build
42
46
run : npm run production
43
47
44
- - name : Run tests (without coverage )
48
+ - name : Run tests (PHP <= 8.3 )
45
49
if : matrix.php-version != '8.4'
46
50
run : composer test
47
51
48
52
- name : Run tests with coverage (PHP 8.4)
49
53
if : matrix.php-version == '8.4'
50
- run : composer test -- --coverage-clover=coverage .xml
54
+ run : composer test -- --coverage-clover=phpunit_coverage.xml --log-junit=phpunit_report .xml
51
55
52
56
- name : Upload coverage report to GitHub Artifacts
57
+ id : artifact-upload-step
53
58
if : matrix.php-version == '8.4'
54
59
uses : actions/upload-artifact@v4
55
60
with :
56
61
name : Code coverage report (PHP ${{ matrix.php-version }})
57
- path : coverage.xml
62
+ path : |
63
+ phpunit_coverage.xml
64
+ phpunit_report.xml
58
65
if-no-files-found : warn
66
+
67
+ - name : Calculate coverage percentage
68
+ if : matrix.php-version == '8.4'
69
+ run : |
70
+ COVERAGE=$(php -r "
71
+ \$xml = simplexml_load_file('phpunit_coverage.xml');
72
+ \$metrics = \$xml->project->metrics;
73
+ \$covered = (int) \$metrics['coveredelements'];
74
+ \$total = (int) \$metrics['elements'];
75
+ echo \$total > 0 ? round((\$covered / \$total) * 100, 2) : 0;
76
+ ")
77
+ echo "COVERAGE=$COVERAGE"
78
+ echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
79
+
80
+ - name : Comment test results in PR
81
+ if : matrix.php-version == '8.4'
82
+ uses : EnricoMi/publish-unit-test-result-action@v2
83
+ with :
84
+ files : phpunit_report.xml
85
+ check_run : false # disabled because of https://github.com/EnricoMi/publish-unit-test-result-action/issues/12
86
+ comment_title : " Test results (coverage: ${{ env.COVERAGE }}%)"
0 commit comments