Skip to content

Commit a3d41ba

Browse files
author
awu
committed
chore: Add Dependabot configuration and dynamically generate PHP version matrix for workflows
1 parent 670bf4c commit a3d41ba

File tree

4 files changed

+106
-19
lines changed

4 files changed

+106
-19
lines changed

.github/depentabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "composer"
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 5
8+
allow:
9+
- dependency-type: direct
10+
labels:
11+
- Dependencies
12+
versioning-strategy: increase
13+
commit-message:
14+
prefix: "chore"
15+
prefix-development: chore

.github/scripts/version_matrix.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$composerJsonFile = __DIR__ . '/../../composer.json';
6+
$composerJsonData = file_get_contents($composerJsonFile);
7+
if ($composerJsonData === false) {
8+
throw new RuntimeException('Failed to read composer.json file');
9+
}
10+
11+
$composerData = json_decode($composerJsonData, true);
12+
if (!isset($composerData['require']['php'])) {
13+
throw new RuntimeException('PHP version not found in composer.json');
14+
}
15+
16+
$minPhpVersion = $composerData['require']['php'];
17+
$minPhpVersion = str_replace('>=', '', $minPhpVersion);
18+
19+
$phpWatchJsonData = file_get_contents('https://php.watch/api/v1/versions');
20+
if ($phpWatchJsonData === false) {
21+
throw new RuntimeException('Failed to fetch PHP versions from php.watch API');
22+
}
23+
24+
$phpWatchData = json_decode($phpWatchJsonData, true);
25+
if (!isset($phpWatchData['data'])) {
26+
throw new RuntimeException('Invalid data format received from php.watch API');
27+
}
28+
29+
$phpMatrix = array_filter(
30+
$phpWatchData['data'],
31+
function (array $item) use ($minPhpVersion): bool {
32+
return $item['name'] >= $minPhpVersion && $item['isNextVersion'] === false;
33+
},
34+
);
35+
36+
$phpVersions = array_map(
37+
static fn (array $version): string => $version['name'],
38+
$phpMatrix,
39+
);
40+
41+
sort($phpVersions);
42+
43+
echo json_encode(array_values($phpVersions));

.github/workflows/code_quality.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,43 @@ permissions:
1212
contents: read
1313

1414
jobs:
15+
generate-matrix:
16+
name: 'Generate PHP Version Matrix'
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.set-matrix.outputs.matrix }}
20+
first: ${{ steps.set-first.outputs.first }}
21+
steps:
22+
- name: PHP-Setup
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: 'latest'
26+
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Fetch PHP versions
31+
id: set-matrix
32+
run: |
33+
php .github/scripts/version_matrix.php > matrix.json
34+
echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
35+
36+
- name: Extract first version
37+
id: set-first
38+
run: |
39+
matrix='${{ steps.set-matrix.outputs.matrix }}'
40+
first=$(echo "$matrix" | jq -r '.[0]')
41+
echo "first=$first" >> $GITHUB_OUTPUT
42+
1543
code-quality:
44+
needs: [ generate-matrix ]
1645
name: 'PHP Code Quality'
1746
runs-on: ubuntu-latest
1847
steps:
1948
- name: PHP-Setup
2049
uses: shivammathur/setup-php@v2
2150
with:
22-
php-version: '8.2'
51+
php-version: ${{ needs.generate-matrix.outputs.first }}
2352

2453
- name: Checkout
2554
uses: actions/checkout@v4
@@ -50,12 +79,12 @@ jobs:
5079
run: composer ecs-dry
5180

5281
unittest:
53-
needs: [ code-quality ]
82+
needs: [ generate-matrix, code-quality ]
5483
name: 'PHP Unit and E2E Tests'
5584
runs-on: ubuntu-latest
5685
strategy:
5786
matrix:
58-
version: [ 8.2, 8.3, 8.4 ]
87+
version: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
5988
steps:
6089
- name: PHP-Setup
6190
uses: shivammathur/setup-php@v2
@@ -89,7 +118,7 @@ jobs:
89118
- name: PHP-Setup
90119
uses: shivammathur/setup-php@v2
91120
with:
92-
php-version: '8.2'
121+
php-version: ${{ needs.generate-matrix.outputs.first }}
93122

94123
- name: Checkout
95124
uses: actions/checkout@v4
@@ -105,4 +134,4 @@ jobs:
105134
uses: codecov/codecov-action@v5
106135
with:
107136
token: ${{ secrets.CODECOV_TOKEN }}
108-
slug: wundii/data-mapper-symfony-bundle
137+
slug: wundii/data-mapper-symfony-bundle

composer.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818
"ext-simplexml": "*",
1919
"ext-spl": "*",
2020
"ext-xml": "*",
21-
"symfony/config": "^6.4 || ^7.0",
22-
"symfony/console": "^6.4 || ^7.0",
23-
"symfony/dependency-injection": "^6.4||^7.0",
24-
"symfony/http-kernel": "^6.4||^7.0",
21+
"symfony/config": "^6.4 || ^7.0 || ^8.0",
22+
"symfony/console": "^6.4 || ^7.0 || ^8.0",
23+
"symfony/dependency-injection": "^6.4||^7.0 || ^8.0",
24+
"symfony/http-kernel": "^6.4||^7.0 || ^8.0",
2525
"wundii/data-mapper": "^1.3.1"
2626
},
2727
"require-dev": {
2828
"ext-dom": "*",
2929
"ext-libxml": "*",
30-
"nette/neon": "^v3.4",
31-
"phpstan/phpstan": "^2.0",
32-
"phpstan/phpstan-strict-rules": "^2.0",
33-
"phpunit/phpunit": "^11.4",
34-
"rector/rector": "^2.0",
35-
"symfony/var-dumper": "^7.0",
36-
"symfony/yaml": "^7.0",
37-
"symplify/easy-coding-standard": "^12.3",
38-
"wundii/phplint": "^0.3"
30+
"nette/neon": "3.4.6",
31+
"phpstan/phpstan": "2.1.32",
32+
"phpstan/phpstan-strict-rules": "2.0.7",
33+
"phpunit/phpunit": "11.5.44",
34+
"rector/rector": "2.2.8",
35+
"symfony/var-dumper": "7.4.0 || 8.0.0",
36+
"symfony/yaml": "7.4.0 || 8.0.0",
37+
"symplify/easy-coding-standard": "12.6.2",
38+
"wundii/phplint": "0.3.3"
3939
},
4040
"autoload": {
4141
"psr-4": {
@@ -75,4 +75,4 @@
7575
"unittest": "php vendor/bin/phpunit --configuration phpunit.xml"
7676
},
7777
"minimum-stability": "stable"
78-
}
78+
}

0 commit comments

Comments
 (0)