From be99cd48d4d6182eaa7eccf3e789b2ac066d3339 Mon Sep 17 00:00:00 2001 From: "Nitsche, Alexander" Date: Tue, 3 Feb 2026 16:18:14 +0100 Subject: [PATCH 1/2] Install specific Cachetool version - Force the use of a specific Cachetool version. - Use the latest version if none is defined and installed. - Support the obsolete "cachetool_url" option for backwards compatibility and inform to switch to the "cachetool_version" option for improved version control. - Make sure that the downloaded file is named "cachetool.phar". - Download the file to .dep/cachetool.phar instead of current/cachetool.phar, similar to how Composer is handled. --- contrib/cachetool.php | 32 +++++++++++++++++++++----------- docs/contrib/cachetool.md | 38 ++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/contrib/cachetool.php b/contrib/cachetool.php index ff6ba7e72..7c8fffb16 100644 --- a/contrib/cachetool.php +++ b/contrib/cachetool.php @@ -49,21 +49,31 @@ namespace Deployer; set('cachetool', ''); -/** - * URL to download cachetool from if it is not available - * - * CacheTool 9.x works with PHP >=8.1 - * CacheTool 8.x works with PHP >=8.0 - * CacheTool 7.x works with PHP >=7.3 - */ -set('cachetool_url', 'https://github.com/gordalina/cachetool/releases/download/9.1.0/cachetool.phar'); set('cachetool_args', ''); +set('cachetool_version', null); + +// Returns Cachetool binary path if found. Otherwise, tries to install Cachetool to `.dep/cachetool.phar`. set('bin/cachetool', function () { - if (!test('[ -f {{release_or_current_path}}/cachetool.phar ]')) { - run("cd {{release_or_current_path}} && curl -sLO {{cachetool_url}}"); + if (test('[ -f {{deploy_path}}/.dep/cachetool.phar ]')) { + if (empty(get('cachetool_version')) || preg_match(parse('/Cachetool.*{{cachetool_version}}/'), run('{{bin/php}} {{deploy_path}}/.dep/cachetool.phar --version'))) { + return '{{bin/php}} {{deploy_path}}/.dep/cachetool.phar'; + } } - return '{{release_or_current_path}}/cachetool.phar'; + + if (has('cachetool_url')) { + warning('The option "cachetool_url" is outdated, use "cachetool_version" instead.'); + } + + $urlLatest = 'https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar'; + $urlVersion = 'https://github.com/gordalina/cachetool/releases/download/%1$s/cachetool.phar'; + $url = get('cachetool_version') ? sprintf($urlVersion, get('cachetool_version')) : (has('cachetool_url') ? get('cachetool_url') : $urlLatest); + $versionAsName = get('cachetool_version') ? ' {{cachetool_version}}' : ''; + warning("Cachetool{$versionAsName} wasn't found. Installing to \"{{deploy_path}}/.dep/cachetool.phar\"."); + run("cd {{deploy_path}} && curl -sSL $url -o cachetool.phar"); + run('mv {{deploy_path}}/cachetool.phar {{deploy_path}}/.dep/cachetool.phar'); + return '{{bin/php}} {{deploy_path}}/.dep/cachetool.phar'; }); + set('cachetool_options', function () { $options = (array) get('cachetool'); $fullOptions = (string) get('cachetool_args'); diff --git a/docs/contrib/cachetool.md b/docs/contrib/cachetool.md index 0efd7c90f..aab6f1bfb 100644 --- a/docs/contrib/cachetool.md +++ b/docs/contrib/cachetool.md @@ -85,42 +85,36 @@ http://gordalina.github.io/cachetool/ -### cachetool_url -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L59) +### cachetool_args +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L52) -URL to download cachetool from if it is not available -CacheTool 9.x works with PHP >=8.1 -CacheTool 8.x works with PHP >=8.0 -CacheTool 7.x works with PHP >=7.3 -```php title="Default value" -'https://github.com/gordalina/cachetool/releases/download/9.1.0/cachetool.phar' -``` -### cachetool_args -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L60) +### cachetool_version +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L53) +```php title="Default value" +null +``` ### bin/cachetool -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L61) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L56) +Returns Cachetool binary path if found. Otherwise, tries to install Cachetool to `.dep/cachetool.phar`. +:::info Autogenerated +The value of this configuration is autogenerated on access. +::: -```php title="Default value" -if (!test('[ -f {{release_or_current_path}}/cachetool.phar ]')) { -run("cd {{release_or_current_path}} && curl -sLO {{cachetool_url}}"); -} -return '{{release_or_current_path}}/cachetool.phar'; -``` ### cachetool_options -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L67) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L77) :::info Autogenerated @@ -134,7 +128,7 @@ The value of this configuration is autogenerated on access. ## Tasks ### cachetool\:clear\:opcache {#cachetool-clear-opcache} -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L89) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L99) Clears OPcode cache. @@ -142,7 +136,7 @@ Clear opcache cache ### cachetool\:clear\:apcu {#cachetool-clear-apcu} -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L100) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L110) Clears APCu system cache. @@ -150,7 +144,7 @@ Clear APCu cache ### cachetool\:clear\:stat {#cachetool-clear-stat} -[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L111) +[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L121) Clears file status and realpath caches. From 25e37f097aee165ac3694b61c9902ad7dddf8f82 Mon Sep 17 00:00:00 2001 From: "Nitsche, Alexander" Date: Tue, 3 Feb 2026 20:29:23 +0100 Subject: [PATCH 2/2] Use verbose variable inline-notation of Deployer --- contrib/cachetool.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/cachetool.php b/contrib/cachetool.php index 7c8fffb16..3d5432c85 100644 --- a/contrib/cachetool.php +++ b/contrib/cachetool.php @@ -65,8 +65,8 @@ } $urlLatest = 'https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar'; - $urlVersion = 'https://github.com/gordalina/cachetool/releases/download/%1$s/cachetool.phar'; - $url = get('cachetool_version') ? sprintf($urlVersion, get('cachetool_version')) : (has('cachetool_url') ? get('cachetool_url') : $urlLatest); + $urlVersion = 'https://github.com/gordalina/cachetool/releases/download/{{cachetool_version}}/cachetool.phar'; + $url = get('cachetool_version') ? parse($urlVersion) : (has('cachetool_url') ? get('cachetool_url') : $urlLatest); $versionAsName = get('cachetool_version') ? ' {{cachetool_version}}' : ''; warning("Cachetool{$versionAsName} wasn't found. Installing to \"{{deploy_path}}/.dep/cachetool.phar\"."); run("cd {{deploy_path}} && curl -sSL $url -o cachetool.phar");