From 7e54d67d7659d7569c00b747aad7ea48acf9556a Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Tue, 20 Jan 2026 15:31:04 +0100 Subject: [PATCH 1/2] Cachetool: Update binary version mapping --- src/Deployer/Task/After/CachetoolTask.php | 34 +++++--- .../Deployer/Task/After/CachetoolTaskTest.php | 85 +++++++++++++++++++ 2 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 tests/Unit/Deployer/Task/After/CachetoolTaskTest.php diff --git a/src/Deployer/Task/After/CachetoolTask.php b/src/Deployer/Task/After/CachetoolTask.php index 2f097e6..69c6c4e 100644 --- a/src/Deployer/Task/After/CachetoolTask.php +++ b/src/Deployer/Task/After/CachetoolTask.php @@ -19,6 +19,7 @@ class CachetoolTask extends TaskBase /** * @var string[] * + * CacheTool 9.x/10.x works with PHP >=8.1 * CacheTool 8.x works with PHP >=8.0 * CacheTool 7.x works with PHP >=7.3 * CacheTool 6.x works with PHP >=7.3 @@ -26,7 +27,8 @@ class CachetoolTask extends TaskBase * CacheTool 4.x works with PHP >=7.1 */ private $versionBinaryMapping = [ - 8 => 'https://github.com/gordalina/cachetool/releases/download/8.4.0/cachetool.phar', + 10 => 'https://github.com/gordalina/cachetool/releases/download/10.0.0/cachetool.phar', + 8 => 'https://github.com/gordalina/cachetool/releases/download/8.6.1/cachetool.phar', 7 => 'https://github.com/gordalina/cachetool/releases/download/7.1.0/cachetool.phar', 6 => 'https://github.com/gordalina/cachetool/releases/download/6.6.0/cachetool.phar', 5 => 'https://github.com/gordalina/cachetool/releases/download/5.1.3/cachetool.phar', @@ -52,10 +54,10 @@ public function configure(Configuration $config): void $cachetoolBinary = get('cachetool_binary'); within('{{release_path}}', function () { - run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl()); + $phpVersion = $this->getPhpVersion(); $cachetoolBinary = '{{release_path}}/cachetool.phar'; - - writeln(sprintf("Downloaded cachetool %s for PHP %f", $cachetoolBinary, $this->getPhpVersion())); + run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl($phpVersion)); + writeln(sprintf("Downloaded cachetool %s for PHP %s", $cachetoolBinary, $phpVersion)); return $cachetoolBinary; }); return $cachetoolBinary; @@ -103,30 +105,36 @@ public function configure(Configuration $config): void }); } - protected function getPhpVersion(): float + protected function getPhpVersion(): string { - return (float) run('{{bin/php}} -r "echo PHP_VERSION . \" - \" . PHP_VERSION_ID;"'); + return run('{{bin/php}} -r "echo PHP_VERSION;"'); } - public function getCachetoolUrl(): string + public function getCachetoolUrl(?string $phpVersion = null): string { - $phpVersion = $this->getPhpVersion(); - if ($phpVersion >= 8.0) { + $phpVersion = $phpVersion ?? $this->getPhpVersion(); + + if (version_compare($phpVersion, '8.1.0', '>=')) { + return $this->versionBinaryMapping[10]; + } + + if (version_compare($phpVersion, '8.0.0', '>=')) { return $this->versionBinaryMapping[8]; } - if ($phpVersion >= 7.3) { + if (version_compare($phpVersion, '7.3.0', '>=')) { return $this->versionBinaryMapping[7]; } - if ($phpVersion >= 7.2) { + if (version_compare($phpVersion, '7.2.0', '>=')) { return $this->versionBinaryMapping[5]; } - if ($phpVersion >= 7.1) { + if (version_compare($phpVersion, '7.1.0', '>=')) { return $this->versionBinaryMapping[4]; } - return $this->versionBinaryMapping[8]; + // Default to latest for unknown/newer PHP versions + return $this->versionBinaryMapping[10]; } } diff --git a/tests/Unit/Deployer/Task/After/CachetoolTaskTest.php b/tests/Unit/Deployer/Task/After/CachetoolTaskTest.php new file mode 100644 index 0000000..4c07ae7 --- /dev/null +++ b/tests/Unit/Deployer/Task/After/CachetoolTaskTest.php @@ -0,0 +1,85 @@ +task = new CachetoolTask(); + } + + /** + * @dataProvider phpVersionToCachetoolUrlProvider + */ + public function testGetCachetoolUrlReturnsCorrectVersionForPhpVersion( + string $phpVersion, + string $expectedUrlPart + ): void { + $result = $this->task->getCachetoolUrl($phpVersion); + + $this->assertStringContainsString($expectedUrlPart, $result); + } + + /** + * @return array + */ + public static function phpVersionToCachetoolUrlProvider(): array + { + return [ + // PHP 8.1+ should get cachetool 10.x + 'PHP 8.3.15 gets cachetool 10' => ['8.3.15', '10.0.0'], + 'PHP 8.2.0 gets cachetool 10' => ['8.2.0', '10.0.0'], + 'PHP 8.1.0 gets cachetool 10' => ['8.1.0', '10.0.0'], + 'PHP 8.1.27 gets cachetool 10' => ['8.1.27', '10.0.0'], + + // PHP 8.0.x should get cachetool 8.x + 'PHP 8.0.0 gets cachetool 8' => ['8.0.0', '8.6.1'], + 'PHP 8.0.30 gets cachetool 8' => ['8.0.30', '8.6.1'], + + // PHP 7.3+ should get cachetool 7.x + 'PHP 7.4.33 gets cachetool 7' => ['7.4.33', '7.1.0'], + 'PHP 7.3.0 gets cachetool 7' => ['7.3.0', '7.1.0'], + 'PHP 7.3.33 gets cachetool 7' => ['7.3.33', '7.1.0'], + + // PHP 7.2.x should get cachetool 5.x + 'PHP 7.2.0 gets cachetool 5' => ['7.2.0', '5.1.3'], + 'PHP 7.2.34 gets cachetool 5' => ['7.2.34', '5.1.3'], + + // PHP 7.1.x should get cachetool 4.x + 'PHP 7.1.0 gets cachetool 4' => ['7.1.0', '4.1.1'], + 'PHP 7.1.33 gets cachetool 4' => ['7.1.33', '4.1.1'], + + // Unsupported/old PHP versions fall back to latest (10.x) + 'PHP 7.0.33 falls back to cachetool 10' => ['7.0.33', '10.0.0'], + 'PHP 5.6.40 falls back to cachetool 10' => ['5.6.40', '10.0.0'], + + // Future PHP versions should get latest (10.x) + 'PHP 9.0.0 gets cachetool 10' => ['9.0.0', '10.0.0'], + 'PHP 8.4.0 gets cachetool 10' => ['8.4.0', '10.0.0'], + ]; + } + + public function testGetCachetoolUrlReturnsFullGithubUrl(): void + { + $result = $this->task->getCachetoolUrl('8.2.0'); + + $this->assertStringStartsWith('https://github.com/gordalina/cachetool/releases/download/', $result); + $this->assertStringEndsWith('/cachetool.phar', $result); + } + + public function testGetCachetoolUrlForPhp71ReturnsLegacyUrl(): void + { + $result = $this->task->getCachetoolUrl('7.1.0'); + + // Cachetool 4.x uses a different URL format (gordalina.github.io) + $this->assertStringStartsWith('https://gordalina.github.io/cachetool/downloads/', $result); + } +} From afafd29bd58c6abffc2d914e0d93f116f3b33032 Mon Sep 17 00:00:00 2001 From: Timon de Groot Date: Tue, 20 Jan 2026 15:33:17 +0100 Subject: [PATCH 2/2] Cachetool: Don't run by default On the Hypernode platform, we have validate_timestamps enabled by default, so we don't have to manually clear the opcache. People can still enable this by configuring `after('deploy:symlink', 'cachetool:clear:opcache');`. --- src/Deployer/Task/After/CachetoolTask.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Deployer/Task/After/CachetoolTask.php b/src/Deployer/Task/After/CachetoolTask.php index 69c6c4e..c522224 100644 --- a/src/Deployer/Task/After/CachetoolTask.php +++ b/src/Deployer/Task/After/CachetoolTask.php @@ -37,7 +37,6 @@ class CachetoolTask extends TaskBase public function register(): void { - after('deploy:symlink', 'cachetool:clear:opcache'); after('cachetool:clear:opcache', 'cachetool:cleanup'); }