Skip to content

Commit 9d5b836

Browse files
committed
feat!: discover PHP versions from Composer constraints
Use Composer constraints for automatic CI matrices and default setup, with a shared Docker resolver for local builds. BREAKING CHANGE: Default CI tests every stable PHP minor allowed by require.php. Projects without a PHP constraint must declare one or select PHP explicitly.
1 parent 98a2a67 commit 9d5b836

24 files changed

Lines changed: 2629 additions & 51 deletions

‎.github/dependabot.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ updates:
55
prefix: build
66
include: scope
77
open-pull-requests-limit: 20
8-
directory: /
8+
directories:
9+
- /
10+
- /actions/**/*
911
schedule:
1012
interval: weekly
1113
day: friday
@@ -41,6 +43,7 @@ updates:
4143
open-pull-requests-limit: 20
4244
versioning-strategy: increase
4345
directories:
46+
- /actions/**/*
4447
- /tests/php-project
4548
- /tests/php-project/tools
4649
schedule:

‎.github/renovate.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"customType": "regex",
41-
"managerFilePatterns": ["/^actions/setup-php/action\\.yml$/"],
41+
"managerFilePatterns": ["/^actions/.*?/action\\.yml$/"],
4242
"matchStrings": ["tools: composer:(?<currentValue>\\d+\\.\\d+\\.\\d+)"],
4343
"datasourceTemplate": "github-releases",
4444
"depNameTemplate": "composer/composer"

‎.github/workflows/__shared-ci.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ jobs:
2424
permissions:
2525
contents: read
2626
id-token: write
27+
test-action-get-php-versions:
28+
uses: $/.github/workflows/__test-action-get-php-versions.yml
29+
permissions:
30+
contents: read
31+
id-token: write
2732
test-action-setup-php:
2833
uses: $/.github/workflows/__test-action-setup-php.yml
2934
permissions:
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Internal - Test Composer PHP version discovery
2+
on:
3+
workflow_call:
4+
permissions: {}
5+
jobs:
6+
unit:
7+
uses: $/.github/workflows/continuous-integration.yml
8+
permissions:
9+
contents: read
10+
id-token: write
11+
with:
12+
working-directory: actions/get-php-versions
13+
lint: "false"
14+
dependency-review: false
15+
integration:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
steps:
20+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
21+
with:
22+
persist-credentials: false
23+
- name: Arrange - Composer is the only version declaration
24+
run: rm .php-version
25+
- name: Act - Discover releases for a nested Composer project
26+
id: versions
27+
uses: $/actions/get-php-versions
28+
with:
29+
working-directory: tests/php-project
30+
- name: Act - Set up the highest compatible release
31+
id: setup
32+
uses: $/actions/setup-php
33+
with:
34+
working-directory: tests/php-project
35+
install-dependencies: "false"
36+
- name: Assert - Setup and discovery agree
37+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
38+
env:
39+
VERSIONS: ${{ steps.versions.outputs.php-versions }}
40+
HIGHEST: ${{ steps.versions.outputs.php-version }}
41+
INSTALLED: ${{ steps.setup.outputs.php-version }}
42+
with:
43+
script: |
44+
const assert = require('node:assert/strict');
45+
const versions = JSON.parse(process.env.VERSIONS);
46+
assert.ok(versions.length > 1, 'Discover every compatible stable minor, not only one default');
47+
assert.equal(versions.at(-1), process.env.HIGHEST);
48+
assert.equal(process.env.INSTALLED, process.env.HIGHEST.split('.').slice(0, 2).join('.'));
49+
const {stdout} = await exec.getExecOutput('php', ['-r', 'echo PHP_VERSION;'], {silent: true});
50+
assert.equal(stdout.trim(), process.env.HIGHEST);
51+
- name: Arrange - Project version file overrides automatic selection
52+
run: echo '8.2' > tests/php-project/.php-version
53+
- name: Act - Honor the version file
54+
id: file
55+
uses: $/actions/setup-php
56+
with:
57+
working-directory: tests/php-project
58+
install-dependencies: "false"
59+
- name: Act - Explicit version overrides the version file
60+
id: explicit
61+
uses: $/actions/setup-php
62+
with:
63+
working-directory: tests/php-project
64+
php-version: "8.3"
65+
install-dependencies: "false"
66+
- name: Assert - Overrides are preserved
67+
env:
68+
FILE_VERSION: ${{ steps.file.outputs.php-version }}
69+
EXPLICIT_VERSION: ${{ steps.explicit.outputs.php-version }}
70+
run: |
71+
test "$FILE_VERSION" = '8.2'
72+
test "$EXPLICIT_VERSION" = '8.3'
73+
- name: Arrange - Composer platform override
74+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
75+
with:
76+
script: |
77+
const fs = require('node:fs');
78+
fs.rmSync('tests/php-project/.php-version');
79+
fs.rmSync('tests/php-project/composer.lock');
80+
const manifest = JSON.parse(fs.readFileSync('tests/php-project/composer.json', 'utf8'));
81+
manifest.config = {...manifest.config, platform: {php: '8.2.0'}};
82+
fs.writeFileSync('tests/php-project/composer.json', JSON.stringify(manifest));
83+
- name: Act - Honor Composer platform selection
84+
id: platform
85+
uses: $/actions/setup-php
86+
with:
87+
working-directory: tests/php-project
88+
install-dependencies: "false"
89+
- name: Assert - Composer platform override is preserved
90+
env:
91+
PLATFORM_VERSION: ${{ steps.platform.outputs.php-version }}
92+
run: test "$PLATFORM_VERSION" = '8.2'
93+
- name: Act - Resolve the local Docker build runtime
94+
id: docker
95+
run: |
96+
docker build --tag php-version-resolver actions/get-php-versions
97+
version=$(docker run --rm --volume "$GITHUB_WORKSPACE/tests/php-project:/project:ro" php-version-resolver)
98+
printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"
99+
- name: Assert - Local builds use the same Composer constraint
100+
env:
101+
DOCKER_VERSION: ${{ steps.docker.outputs.version }}
102+
ACTION_VERSION: ${{ steps.versions.outputs.php-version }}
103+
run: test "$DOCKER_VERSION" = "$ACTION_VERSION"

‎.github/workflows/__test-workflow-continuous-integration.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ jobs:
115115
id-token: write
116116
with:
117117
working-directory: tests/php-project
118-
php-versions: '["8.2", ""]'
119118
test: '{"cache":".phpunit.cache"}'
120119
runs-on: '["ubuntu-24.04"]'
121120
dependency-review: false

0 commit comments

Comments
 (0)