1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Deployer; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Run an artisan command. |
7
|
|
|
* |
8
|
|
|
* Supported options: |
9
|
|
|
* - 'min' => #.#: The minimum Laravel version required (included). |
10
|
|
|
* - 'max' => #.#: The maximum Laravel version required (included). |
11
|
|
|
* - 'skipIfNoEnv': Skip and warn the user if `.env` file is inexistant or empty. |
12
|
|
|
* - 'failIfNoEnv': Fail the command if `.env` file is inexistant or empty. |
13
|
|
|
* - 'runInCurrent': Run the artisan command in the current directory. |
14
|
|
|
* - 'showOutput': Show the output of the command if given. |
15
|
|
|
* |
16
|
|
|
* @param string $command The artisan command (with cli options if any). |
17
|
|
|
* @param array $options The options that define the behaviour of the command. |
18
|
|
|
* @return callable A function that can be used as a task. |
19
|
|
|
*/ |
20
|
|
|
function artisan($command, $options = []) |
21
|
|
|
{ |
22
|
|
|
return function () use ($command, $options) { |
23
|
|
|
$versionTooEarly = array_key_exists('min', $options) |
24
|
|
|
&& laravel_version_compare($options['min'], '<'); |
25
|
|
|
|
26
|
|
|
$versionTooLate = array_key_exists('max', $options) |
27
|
|
|
&& laravel_version_compare($options['max'], '>'); |
28
|
|
|
|
29
|
|
|
if ($versionTooEarly || $versionTooLate) { |
30
|
|
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (in_array('failIfNoEnv', $options) && ! test('[ -s {{release_path}}/.env ]')) { |
34
|
|
|
throw new \Exception('Your .env file is empty! Cannot proceed.'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
if (in_array('skipIfNoEnv', $options) && ! test('[ -s {{release_path}}/.env ]')) { |
38
|
|
|
writeln('<fg=yellow;options=bold;>Warning: </><fg=yellow;>Your .env file is empty! Skipping...</>'); |
39
|
|
|
|
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$artisan = in_array('runInCurrent', $options) |
|
|
|
|
44
|
|
|
? '{{deploy_path}}/current/artisan' |
45
|
|
|
: '{{release_path}}/artisan'; |
46
|
|
|
|
47
|
|
|
$output = run("{{bin/php}} {{release_path}}/artisan $command"); |
48
|
|
|
|
49
|
|
|
if (in_array('showOutput', $options)) { |
50
|
|
|
writeln("<info>$output</info>"); |
51
|
|
|
} |
52
|
|
|
}; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function laravel_version_compare($version, $comparator) |
56
|
|
|
{ |
57
|
|
|
return version_compare(get('laravel_version'), $version, $comparator); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function copyShared($from, $to) |
61
|
|
|
{ |
62
|
|
View Code Duplication |
foreach (get('shared_dirs') as $dir) { |
|
|
|
|
63
|
|
|
if (test("[ -d $from/$dir ]")) { |
64
|
|
|
run("mkdir -p $to/$dir"); |
65
|
|
|
run("rsync -r --ignore-existing $from/$dir $to/".dirname(parse($dir))); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
View Code Duplication |
foreach (get('shared_files') as $file) { |
|
|
|
|
69
|
|
|
if (test("[ -f $from/$file ]")) { |
70
|
|
|
run("mkdir -p $to/".dirname(parse($file))); |
71
|
|
|
run("rsync --ignore-existing $from/$file $to/$file"); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.