Skip to content

Commit be99cd4

Browse files
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.
1 parent 3e3ea6c commit be99cd4

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

contrib/cachetool.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,31 @@
4949
namespace Deployer;
5050

5151
set('cachetool', '');
52-
/**
53-
* URL to download cachetool from if it is not available
54-
*
55-
* CacheTool 9.x works with PHP >=8.1
56-
* CacheTool 8.x works with PHP >=8.0
57-
* CacheTool 7.x works with PHP >=7.3
58-
*/
59-
set('cachetool_url', 'https://github.com/gordalina/cachetool/releases/download/9.1.0/cachetool.phar');
6052
set('cachetool_args', '');
53+
set('cachetool_version', null);
54+
55+
// Returns Cachetool binary path if found. Otherwise, tries to install Cachetool to `.dep/cachetool.phar`.
6156
set('bin/cachetool', function () {
62-
if (!test('[ -f {{release_or_current_path}}/cachetool.phar ]')) {
63-
run("cd {{release_or_current_path}} && curl -sLO {{cachetool_url}}");
57+
if (test('[ -f {{deploy_path}}/.dep/cachetool.phar ]')) {
58+
if (empty(get('cachetool_version')) || preg_match(parse('/Cachetool.*{{cachetool_version}}/'), run('{{bin/php}} {{deploy_path}}/.dep/cachetool.phar --version'))) {
59+
return '{{bin/php}} {{deploy_path}}/.dep/cachetool.phar';
60+
}
6461
}
65-
return '{{release_or_current_path}}/cachetool.phar';
62+
63+
if (has('cachetool_url')) {
64+
warning('The option "cachetool_url" is outdated, use "cachetool_version" instead.');
65+
}
66+
67+
$urlLatest = 'https://github.com/gordalina/cachetool/releases/latest/download/cachetool.phar';
68+
$urlVersion = 'https://github.com/gordalina/cachetool/releases/download/%1$s/cachetool.phar';
69+
$url = get('cachetool_version') ? sprintf($urlVersion, get('cachetool_version')) : (has('cachetool_url') ? get('cachetool_url') : $urlLatest);
70+
$versionAsName = get('cachetool_version') ? ' {{cachetool_version}}' : '';
71+
warning("Cachetool{$versionAsName} wasn't found. Installing to \"{{deploy_path}}/.dep/cachetool.phar\".");
72+
run("cd {{deploy_path}} && curl -sSL $url -o cachetool.phar");
73+
run('mv {{deploy_path}}/cachetool.phar {{deploy_path}}/.dep/cachetool.phar');
74+
return '{{bin/php}} {{deploy_path}}/.dep/cachetool.phar';
6675
});
76+
6777
set('cachetool_options', function () {
6878
$options = (array) get('cachetool');
6979
$fullOptions = (string) get('cachetool_args');

docs/contrib/cachetool.md

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,36 @@ http://gordalina.github.io/cachetool/
8585

8686

8787

88-
### cachetool_url
89-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L59)
88+
### cachetool_args
89+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L52)
9090

91-
URL to download cachetool from if it is not available
9291

93-
CacheTool 9.x works with PHP >=8.1
94-
CacheTool 8.x works with PHP >=8.0
95-
CacheTool 7.x works with PHP >=7.3
9692

97-
```php title="Default value"
98-
'https://github.com/gordalina/cachetool/releases/download/9.1.0/cachetool.phar'
99-
```
10093

10194

102-
### cachetool_args
103-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L60)
95+
### cachetool_version
96+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L53)
10497

10598

10699

100+
```php title="Default value"
101+
null
102+
```
107103

108104

109105
### bin/cachetool
110-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L61)
106+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L56)
111107

108+
Returns Cachetool binary path if found. Otherwise, tries to install Cachetool to `.dep/cachetool.phar`.
109+
:::info Autogenerated
110+
The value of this configuration is autogenerated on access.
111+
:::
112112

113113

114-
```php title="Default value"
115-
if (!test('[ -f {{release_or_current_path}}/cachetool.phar ]')) {
116-
run("cd {{release_or_current_path}} && curl -sLO {{cachetool_url}}");
117-
}
118-
return '{{release_or_current_path}}/cachetool.phar';
119-
```
120114

121115

122116
### cachetool_options
123-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L67)
117+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L77)
124118

125119

126120
:::info Autogenerated
@@ -134,23 +128,23 @@ The value of this configuration is autogenerated on access.
134128
## Tasks
135129

136130
### cachetool\:clear\:opcache {#cachetool-clear-opcache}
137-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L89)
131+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L99)
138132

139133
Clears OPcode cache.
140134

141135
Clear opcache cache
142136

143137

144138
### cachetool\:clear\:apcu {#cachetool-clear-apcu}
145-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L100)
139+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L110)
146140

147141
Clears APCu system cache.
148142

149143
Clear APCu cache
150144

151145

152146
### cachetool\:clear\:stat {#cachetool-clear-stat}
153-
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L111)
147+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/cachetool.php#L121)
154148

155149
Clears file status and realpath caches.
156150

0 commit comments

Comments
 (0)