Skip to content

Commit e9db2b4

Browse files
authored
Merge pull request #31 from Nimut/github-actions
2 parents 4b361a0 + 15ca05c commit e9db2b4

File tree

6 files changed

+227
-105
lines changed

6 files changed

+227
-105
lines changed

Diff for: .github/workflows/compute.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: ✏️ matrix
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
os:
7+
value: ${{ jobs.compute.outputs.os }}
8+
coverage:
9+
value: ${{ jobs.compute.outputs.coverage }}
10+
major:
11+
value: ${{ jobs.compute.outputs.major }}
12+
php:
13+
value: ${{ jobs.compute.outputs.php }}
14+
exclude:
15+
value: ${{ jobs.compute.outputs.exclude }}
16+
17+
env:
18+
OS: '[ "ubuntu-latest" ]'
19+
COVERAGE: '[ "~9.0.0", "~9.1.0", "~9.2.0", "~10.0.0", "~10.1.0" ]'
20+
PHP: '[ "8.0", "8.1", "8.2", "8.3" ]'
21+
EXCLUDE: '[ { "coverage": "10", "php": "8.0" }, { "coverage": "~10.0.0", "php": "8.0" }, { "coverage": "~10.1.0", "php": "8.0" } ]'
22+
23+
jobs:
24+
compute:
25+
name: Compute outputs
26+
27+
runs-on: ubuntu-latest
28+
29+
outputs:
30+
os: ${{ env.OS }}
31+
coverage: ${{ env.COVERAGE }}
32+
major: ${{ steps.major-version.outputs.major }}
33+
php: ${{ env.PHP }}
34+
exclude: ${{ env.EXCLUDE }}
35+
36+
steps:
37+
- name: Compute major versions
38+
id: major-version
39+
run: |
40+
echo -e "COVERAGE\n"
41+
echo $COVERAGE
42+
echo -e "\n\nSplit by comma\n"
43+
echo $COVERAGE | tr "," "\n"
44+
echo -e "\n\nParse numbers\n"
45+
echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9"
46+
echo -e "\n\nCut last 2 characters\n"
47+
echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9" | sed "s/.\{2\}$//"
48+
echo -e "\n\nSort by version\n"
49+
echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9" | sed "s/.\{2\}$//" | sort -V
50+
echo -e "\n\nUnique values only\n"
51+
echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9" | sed "s/.\{2\}$//" | sort -V | uniq
52+
echo -e "\n\nCovert to JSON\n"
53+
echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9" | sed "s/.\{2\}$//" | sort -V | uniq | jq --compact-output --raw-input --slurp 'split("\n") | map(select(. != ""))'
54+
echo "major=$(echo $COVERAGE | tr "," "\n" | tr -cd "\n0-9" | sed "s/.\{2\}$//" | sort -V | uniq | jq --compact-output --raw-input --slurp 'split("\n") | map(select(. != ""))')" >> $GITHUB_OUTPUT

Diff for: .github/workflows/test.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: 🏃 tests
2+
3+
on: [ push, pull_request, workflow_call ]
4+
5+
jobs:
6+
compute:
7+
uses: ./.github/workflows/compute.yml
8+
9+
build:
10+
name: 'Build COVERAGE: ${{ matrix.coverage }} - PHP: ${{ matrix.php }}'
11+
12+
needs: [ compute ]
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: ${{ fromJson(needs.compute.outputs.os) }}
18+
coverage: ${{ fromJson(needs.compute.outputs.coverage) }}
19+
php: ${{ fromJson(needs.compute.outputs.php) }}
20+
exclude: ${{ fromJson(needs.compute.outputs.exclude) }}
21+
22+
runs-on: ${{ matrix.os }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Store Composer cache directory
29+
id: composer-cache
30+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
31+
32+
- name: Store PHP code coverage version
33+
id: version-cache
34+
env:
35+
COVERAGE: ${{ matrix.coverage }}
36+
run: |
37+
echo "version=$(echo $COVERAGE | tr -d -c 0-9)" >> $GITHUB_OUTPUT
38+
echo "major=$(echo $COVERAGE | tr -d -c 0-9 | sed 's/.\{2\}$//')" >> $GITHUB_OUTPUT
39+
40+
- uses: actions/cache/restore@v4
41+
id: restore-composer-cache
42+
with:
43+
path: ${{ steps.composer-cache.outputs.dir }}
44+
key: ${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}-${{ matrix.coverage }}
45+
restore-keys: |
46+
${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}-
47+
${{ runner.os }}-${{ matrix.php }}-
48+
${{ runner.os }}-
49+
50+
- name: Set up PHP Version ${{ matrix.php }}
51+
uses: shivammathur/setup-php@v2
52+
with:
53+
php-version: ${{ matrix.php }}
54+
coverage: xdebug
55+
tools: composer:v2
56+
57+
- name: Environment Check
58+
run: |
59+
php --version
60+
composer --version
61+
mkdir -p .Log/coverage/ .Log/log/
62+
63+
- name: Validate composer.json
64+
run: composer validate
65+
66+
- name: Composer install
67+
run: composer update --with "phpunit/php-code-coverage:${{ matrix.coverage }}" --no-interaction
68+
69+
- name: Save composer cache
70+
uses: actions/cache/save@v4
71+
with:
72+
path: ${{ steps.composer-cache.outputs.dir }}
73+
key: ${{ steps.restore-composer-cache.outputs.cache-primary-key }}
74+
75+
- name: Lint PHP
76+
run: php .Build/bin/parallel-lint --exclude .Build .
77+
78+
- name: Run PHPUnit
79+
if: ${{ success() || failure() }}
80+
run: find 'tests' -wholename '*Test.php' | parallel --gnu 'echo -e "\n\nRunning test {}"; HASH=${{ steps.version-cache.outputs.version }}_$( echo {} | md5sum | cut -d " " -f 1); .Build/bin/phpunit --log-junit .Log/log/junit_$HASH.xml --coverage-php .Log/coverage/coverage_$HASH.cov --coverage-filter src/ {}'
81+
82+
- name: Archive PHPUnit logs
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: phpunit-logs-${{ runner.os }}-${{ matrix.php }}-${{ steps.version-cache.outputs.major }}-${{ matrix.coverage }}
86+
path: .Log/*
87+
retention-days: 1
88+
89+
merge:
90+
name: 'Merge COVERAGE: ${{ matrix.coverage }} - PHP: ${{ matrix.php }}'
91+
92+
needs: [ compute, build ]
93+
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
os: ${{ fromJson(needs.compute.outputs.os) }}
98+
coverage: ${{ fromJson(needs.compute.outputs.major) }}
99+
php: ${{ fromJson(needs.compute.outputs.php) }}
100+
exclude: ${{ fromJson(needs.compute.outputs.exclude) }}
101+
102+
runs-on: ${{ matrix.os }}
103+
104+
steps:
105+
- name: Checkout
106+
uses: actions/checkout@v4
107+
108+
- name: Download PHPUnit logs
109+
uses: actions/download-artifact@v4
110+
with:
111+
path: .Log
112+
pattern: phpunit-logs-${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }}-*
113+
merge-multiple: true
114+
115+
- name: Store Composer cache directory
116+
id: composer-cache
117+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
118+
119+
- uses: actions/cache/restore@v4
120+
id: restore-composer-cache
121+
with:
122+
path: ${{ steps.composer-cache.outputs.dir }}
123+
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }}
124+
restore-keys: |
125+
${{ runner.os }}-${{ matrix.php }}-
126+
${{ runner.os }}-
127+
128+
- name: Set up PHP Version ${{ matrix.php }}
129+
uses: shivammathur/setup-php@v2
130+
with:
131+
php-version: ${{ matrix.php }}
132+
coverage: xdebug
133+
tools: composer:v2
134+
135+
- name: Environment Check
136+
run: |
137+
php --version
138+
composer --version
139+
140+
- name: Validate composer.json
141+
run: composer validate
142+
143+
- name: Composer install
144+
run: composer update --with "phpunit/php-code-coverage:^${{ matrix.coverage }}.0" --no-interaction
145+
146+
- name: Save composer cache
147+
uses: actions/cache/save@v4
148+
with:
149+
path: ${{ steps.composer-cache.outputs.dir }}
150+
key: ${{ steps.restore-composer-cache.outputs.cache-primary-key }}
151+
152+
- name: Merge log files
153+
run: bin/phpunit-merger log .Log/log/ .Log/junit.xml
154+
155+
- name: Merge coverage files
156+
run: bin/phpunit-merger coverage .Log/coverage/ .Log/coverage.xml
157+
158+
- name: Archive PHPUnit logs
159+
uses: actions/upload-artifact@v4
160+
with:
161+
name: phpunit-logs-merged-${{ runner.os }}-${{ matrix.php }}-${{ matrix.coverage }}
162+
path: .Log/*
163+
retention-days: 1

Diff for: .travis.yml

-98
This file was deleted.

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"require-dev": {
3838
"phpunit/phpunit": "^9.3 || ^10.0",
3939
"symfony/filesystem": ">=2.7 <7.0",
40-
"phpspec/prophecy": "^1.0"
40+
"phpspec/prophecy": "^1.0",
41+
"php-parallel-lint/php-parallel-lint": "^1.4"
4142
},
4243
"suggest": {
4344
"friendsofphp/php-cs-fixer": "Tool to automatically fix PHP coding standards issues"

Diff for: phpunit.xml.dist

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.4/phpunit.xsd"
44
bootstrap=".Build/vendor/autoload.php"
5-
executionOrder="depends,defects"
6-
forceCoversAnnotation="false"
7-
beStrictAboutCoversAnnotation="true"
8-
beStrictAboutOutputDuringTests="true"
9-
beStrictAboutTodoAnnotatedTests="true"
10-
verbose="true">
5+
executionOrder="depends,defects">
116
<testsuites>
127
<testsuite name="coverage">
138
<directory suffix="Test.php">tests/PhpunitMerger/Command/Coverage</directory>

Diff for: src/PhpunitMerger/Command/CoverageCommand.php

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Nimut\PhpunitMerger\Command;
66

77
use SebastianBergmann\CodeCoverage\CodeCoverage;
8+
use SebastianBergmann\CodeCoverage\Driver\Driver;
89
use SebastianBergmann\CodeCoverage\Driver\Selector;
910
use SebastianBergmann\CodeCoverage\Filter;
1011
use SebastianBergmann\CodeCoverage\Report\Clover;
@@ -85,6 +86,12 @@ private function getCodeCoverage()
8586
{
8687
$filter = new Filter();
8788

89+
if (method_exists(Driver::class, 'forLineCoverage')) {
90+
$driver = Driver::forLineCoverage($filter);
91+
92+
return new CodeCoverage($driver, $filter);
93+
}
94+
8895
return new CodeCoverage((new Selector())->forLineCoverage($filter), $filter);
8996
}
9097

0 commit comments

Comments
 (0)