Skip to content

Commit afc31f6

Browse files
swissspidyclaude
andauthored
Drop roave/security-advisories in CI when it conflicts with the PHP in use (#305)
* Drop roave/security-advisories on PHP < 8.2 in CI It conflicts with every PHP release below 8.2, so composer install can never succeed there. Composer's policy.advisories.block still applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5mjnLFLCExqdULKVSB * Drop roave/security-advisories on all PHP versions Its PHP conflict covers patch releases of 8.3-8.5 too (e.g. Windows runners on PHP 8.5.11), not just < 8.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5mjnLFLCExqdULKVSB * Only drop roave/security-advisories when it conflicts with the PHP in use Read roave's php conflict constraint from Packagist and drop the package only when the running PHP falls inside it, so up-to-date PHP versions keep the dependency check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5mjnLFLCExqdULKVSB * Link setup-php security release notes in roave comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5mjnLFLCExqdULKVSB * Update PHP to the latest patch on Windows runners Windows runners don't pick up patched setup-php builds automatically (shivammathur/setup-php#1139), so they lag a patch release behind and roave/security-advisories can't install there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTd5mjnLFLCExqdULKVSB --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fd58c25 commit afc31f6

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎.github/workflows/reusable-functional.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ jobs:
165165
tools: composer
166166
env:
167167
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168+
# Windows runners don't pick up patched PHP builds on their own (shivammathur/setup-php#1139).
169+
update: ${{ runner.os == 'Windows' }}
168170

169171
- name: Change ImageMagick policy to allow pdf->png conversion.
170172
# Keyed on the actual runner rather than the `os` input, and tolerant of
@@ -188,6 +190,30 @@ jobs:
188190
shell: bash
189191
run: echo "value=$(date -u +%Y-%W)" >> "$GITHUB_OUTPUT"
190192

193+
# roave/security-advisories also conflicts with PHP releases that have known
194+
# advisories, so it can't install on those (Roave/SecurityAdvisories#155).
195+
# Drop it only when it conflicts with the PHP version in use. setup-php ships
196+
# builds with security fixes backported, even for EOL versions, so this is
197+
# safe on CI (shivammathur/setup-php#1139).
198+
- name: Drop roave/security-advisories if it conflicts with this PHP version
199+
shell: bash
200+
run: |
201+
php -r 'exit(isset(json_decode(file_get_contents("composer.json"), true)["require-dev"]["roave/security-advisories"]) ? 0 : 1);' || exit 0
202+
export CONFLICT="$(composer show --available --format=json roave/security-advisories dev-latest | php -r 'echo json_decode(stream_get_contents(STDIN), true)["conflicts"]["php"] ?? "";')"
203+
echo "roave/security-advisories conflicts with php ${CONFLICT:-(none)}"
204+
if php -r '
205+
foreach (preg_split("/\s*\|\|?\s*/", getenv("CONFLICT"), -1, PREG_SPLIT_NO_EMPTY) as $range) {
206+
$hit = true;
207+
foreach (preg_split("/\s*,\s*|\s+/", $range) as $c) {
208+
preg_match("/^(<=|>=|<|>|==|=|!=)?v?(.+)$/", $c, $m);
209+
$hit = $hit && version_compare(PHP_VERSION, $m[2], $m[1] ?: "==");
210+
}
211+
if ($hit) exit(0);
212+
}
213+
exit(1);'; then
214+
composer remove --dev --no-update --no-interaction roave/security-advisories
215+
fi
216+
191217
- name: Install Composer dependencies & cache dependencies
192218
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
193219
with:

‎.github/workflows/reusable-unit.yml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
tools: composer,cs2pr
4949
env:
5050
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
# Windows runners don't pick up patched PHP builds on their own (shivammathur/setup-php#1139).
52+
update: ${{ runner.os == 'Windows' }}
5153

5254
# WP-CLI packages do not commit a lock file, so `composer update` resolves
5355
# dependencies on every run while the cache key stays pinned to composer.json.
@@ -59,6 +61,30 @@ jobs:
5961
shell: bash
6062
run: echo "value=$(date -u +%Y-%W)" >> "$GITHUB_OUTPUT"
6163

64+
# roave/security-advisories also conflicts with PHP releases that have known
65+
# advisories, so it can't install on those (Roave/SecurityAdvisories#155).
66+
# Drop it only when it conflicts with the PHP version in use. setup-php ships
67+
# builds with security fixes backported, even for EOL versions, so this is
68+
# safe on CI (shivammathur/setup-php#1139).
69+
- name: Drop roave/security-advisories if it conflicts with this PHP version
70+
shell: bash
71+
run: |
72+
php -r 'exit(isset(json_decode(file_get_contents("composer.json"), true)["require-dev"]["roave/security-advisories"]) ? 0 : 1);' || exit 0
73+
export CONFLICT="$(composer show --available --format=json roave/security-advisories dev-latest | php -r 'echo json_decode(stream_get_contents(STDIN), true)["conflicts"]["php"] ?? "";')"
74+
echo "roave/security-advisories conflicts with php ${CONFLICT:-(none)}"
75+
if php -r '
76+
foreach (preg_split("/\s*\|\|?\s*/", getenv("CONFLICT"), -1, PREG_SPLIT_NO_EMPTY) as $range) {
77+
$hit = true;
78+
foreach (preg_split("/\s*,\s*|\s+/", $range) as $c) {
79+
preg_match("/^(<=|>=|<|>|==|=|!=)?v?(.+)$/", $c, $m);
80+
$hit = $hit && version_compare(PHP_VERSION, $m[2], $m[1] ?: "==");
81+
}
82+
if ($hit) exit(0);
83+
}
84+
exit(1);'; then
85+
composer remove --dev --no-update --no-interaction roave/security-advisories
86+
fi
87+
6288
- name: Install Composer dependencies & cache dependencies
6389
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # 4.0.0
6490
with:

0 commit comments

Comments
 (0)