Skip to content

Commit 2282d76

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 2282d76

31 files changed

Lines changed: 2831 additions & 77 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/__greetings.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions: {}
1212
jobs:
1313
greetings:
1414
if: ${{ github.event_name == 'issues' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') }}
15-
uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
15+
uses: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0
1616
permissions:
1717
contents: read
1818
issues: write

‎.github/workflows/__need-fix-to-issue.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ permissions: {}
1818

1919
jobs:
2020
main:
21-
uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
21+
uses: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0
2222
permissions:
2323
contents: read
2424
issues: write

‎.github/workflows/__semantic-pull-request.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
main:
1515
permissions:
1616
contents: read
17-
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
17+
uses: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
permissions: {}
55
jobs:
66
linter:
7-
uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
7+
uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0
88
permissions:
99
contents: read
1010
statuses: write
@@ -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:

‎.github/workflows/__stale.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions: {}
88

99
jobs:
1010
main:
11-
uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@66882b24f9f13e45a6541896a5a7c638cb91c94c # 4.0.0
11+
uses: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml@d07ee49b460ae2f3815804b5153fe918092aa321 # 4.2.0
1212
permissions:
1313
issues: write
1414
pull-requests: write
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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: |
25+
rm .php-version
26+
php -r 'echo PHP_VERSION;' > "$RUNNER_TEMP/php-version-before"
27+
chmod 600 tests/php-project/composer.json
28+
- name: Act - Discover releases for a nested Composer project
29+
id: versions
30+
uses: $/actions/get-php-versions
31+
with:
32+
working-directory: tests/php-project
33+
- name: Assert - Discovery preserves the runner PHP installation
34+
run: test "$(php -r 'echo PHP_VERSION;')" = "$(cat "$RUNNER_TEMP/php-version-before")"
35+
- name: Act - Set up the highest compatible release
36+
id: setup
37+
uses: $/actions/setup-php
38+
with:
39+
working-directory: ${{ github.workspace }}/tests/php-project
40+
install-dependencies: "false"
41+
- name: Assert - Setup and discovery agree
42+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
43+
env:
44+
VERSIONS: ${{ steps.versions.outputs.php-versions }}
45+
HIGHEST: ${{ steps.versions.outputs.php-version }}
46+
INSTALLED: ${{ steps.setup.outputs.php-version }}
47+
with:
48+
script: |
49+
const assert = require('node:assert/strict');
50+
const versions = JSON.parse(process.env.VERSIONS);
51+
assert.ok(versions.length > 1, 'Discover every compatible stable minor, not only one default');
52+
assert.equal(versions.at(-1), process.env.HIGHEST);
53+
assert.equal(process.env.INSTALLED, process.env.HIGHEST.split('.').slice(0, 2).join('.'));
54+
const {stdout} = await exec.getExecOutput('php', ['-r', 'echo PHP_VERSION;'], {silent: true});
55+
assert.equal(stdout.trim(), process.env.HIGHEST);
56+
- name: Arrange - Project version file overrides automatic selection
57+
run: echo '8.2' > tests/php-project/.php-version
58+
- name: Act - Honor the version file
59+
id: file
60+
uses: $/actions/setup-php
61+
with:
62+
working-directory: tests/php-project
63+
install-dependencies: "false"
64+
- name: Act - Explicit version overrides the version file
65+
id: explicit
66+
uses: $/actions/setup-php
67+
with:
68+
working-directory: tests/php-project
69+
php-version: "8.3"
70+
install-dependencies: "false"
71+
- name: Assert - Overrides are preserved
72+
env:
73+
FILE_VERSION: ${{ steps.file.outputs.php-version }}
74+
EXPLICIT_VERSION: ${{ steps.explicit.outputs.php-version }}
75+
run: |
76+
test "$FILE_VERSION" = '8.2'
77+
test "$EXPLICIT_VERSION" = '8.3'
78+
- name: Arrange - Composer platform override
79+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
80+
with:
81+
script: |
82+
const fs = require('node:fs');
83+
fs.rmSync('tests/php-project/.php-version');
84+
fs.rmSync('tests/php-project/composer.lock');
85+
const manifest = JSON.parse(fs.readFileSync('tests/php-project/composer.json', 'utf8'));
86+
manifest.config = {...manifest.config, platform: {php: '8.2.0'}};
87+
fs.writeFileSync('tests/php-project/composer.json', JSON.stringify(manifest));
88+
- name: Act - Honor Composer platform selection
89+
id: platform
90+
uses: $/actions/setup-php
91+
with:
92+
working-directory: tests/php-project
93+
install-dependencies: "false"
94+
- name: Assert - Composer platform override is preserved
95+
env:
96+
PLATFORM_VERSION: ${{ steps.platform.outputs.php-version }}
97+
run: test "$PLATFORM_VERSION" = '8.2'
98+
- name: Act - Resolve the local Docker build runtime
99+
id: docker
100+
run: |
101+
docker build --tag php-version-resolver actions/get-php-versions
102+
test "$(docker run --rm --entrypoint id php-version-resolver -u)" -ne 0
103+
version=$(docker run --rm --user "$(id -u):$(id -g)" --volume "$GITHUB_WORKSPACE/tests/php-project:/project:ro" php-version-resolver)
104+
printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"
105+
- name: Assert - Local builds use the same Composer constraint
106+
env:
107+
DOCKER_VERSION: ${{ steps.docker.outputs.version }}
108+
ACTION_VERSION: ${{ steps.versions.outputs.php-version }}
109+
run: test "$DOCKER_VERSION" = "$ACTION_VERSION"
110+
- name: Arrange - Project symlink escapes the checkout
111+
run: ln -s /tmp tests/php-project/outside
112+
- name: Act - Reject a directory outside the checkout
113+
id: outside
114+
continue-on-error: true
115+
uses: $/actions/get-php-versions
116+
with:
117+
working-directory: ..
118+
- name: Act - Reject a symlink outside the checkout
119+
id: symlink
120+
continue-on-error: true
121+
uses: $/actions/get-php-versions
122+
with:
123+
working-directory: tests/php-project/outside
124+
- name: Assert - Invalid paths fail without outputs
125+
env:
126+
OUTSIDE_OUTCOME: ${{ steps.outside.outcome }}
127+
SYMLINK_OUTCOME: ${{ steps.symlink.outcome }}
128+
OUTSIDE_OUTPUTS: ${{ toJSON(steps.outside.outputs) }}
129+
SYMLINK_OUTPUTS: ${{ toJSON(steps.symlink.outputs) }}
130+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
131+
with:
132+
script: |
133+
const assert = require('node:assert/strict');
134+
for (const scenario of ['OUTSIDE', 'SYMLINK']) {
135+
assert.equal(process.env[`${scenario}_OUTCOME`], 'failure');
136+
assert.ok(Object.values(JSON.parse(process.env[`${scenario}_OUTPUTS`])).every(value => value === ''));
137+
}

‎.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)