1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sfneal\Cruise\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Contracts\Console\PromptsForMissingInput; |
7
|
|
|
use Illuminate\Support\Facades\Process; |
8
|
|
|
use Sfneal\Cruise\Utils\ScriptsPath; |
9
|
|
|
|
10
|
|
|
use function Laravel\Prompts\select; |
11
|
|
|
|
12
|
|
|
class Bump extends Command implements PromptsForMissingInput |
13
|
|
|
{ |
14
|
|
|
use ScriptsPath; |
15
|
|
|
|
16
|
|
|
const TYPES = ['major', 'minor', 'patch']; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The name and signature of the console command. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $signature = 'bump |
24
|
|
|
{type : major, minor or patch version bump} |
25
|
|
|
{--commit : commit the updated version files to git} |
26
|
|
|
{--no-commit : disabling commiting the updated version files}'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The console command description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $description = 'Bump the application to the next major, minor or patch version'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The current application version. |
37
|
|
|
* |
38
|
|
|
* @var string|null |
39
|
|
|
*/ |
40
|
|
|
protected ?string $version = null; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Execute the console command. |
44
|
|
|
*/ |
45
|
|
|
public function handle(): int |
46
|
|
|
{ |
47
|
|
|
$this->version = Version::get(); |
48
|
|
|
|
49
|
|
|
// Run bump command |
50
|
|
|
$bumpProcess = Process::path(base_path())->run([ |
51
|
|
|
'bash', $this->getVersionScriptPath('bump.sh'), |
52
|
|
|
'--'.$this->argument('type'), |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
// Display output in the console |
56
|
|
|
$message = $bumpProcess->output(); |
57
|
|
|
|
58
|
|
|
// Exit process if bump failed or the 'commit' option is NOT enabled |
59
|
|
|
if ($bumpProcess->failed()) { |
60
|
|
|
return $bumpProcess->exitCode(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ($this->isCommitEnabled()) { |
64
|
|
|
// Run the commit process |
65
|
|
|
$commitProcess = Process::path(base_path())->run([ |
66
|
|
|
'bash', $this->getVersionScriptPath('commit.sh'), |
67
|
|
|
$message, |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
if ($commitProcess->failed()) { |
71
|
|
|
return $commitProcess->exitCode(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->info($message); |
76
|
|
|
|
77
|
|
|
return self::SUCCESS; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Prompt for missing input arguments using the returned questions. |
82
|
|
|
* |
83
|
|
|
* @return array<string, string> |
84
|
|
|
*/ |
85
|
|
|
protected function promptForMissingArgumentsUsing(): array |
86
|
|
|
{ |
87
|
|
|
return [ |
88
|
|
|
'type' => function () { |
89
|
|
|
// Display table with bump options |
90
|
|
|
$this->displaySemverOptions(); |
91
|
|
|
|
92
|
|
|
return select( |
93
|
|
|
label: 'Which semver segment would you like to bump?', |
94
|
|
|
options: self::TYPES, |
95
|
|
|
default: 'patch', |
96
|
|
|
hint: 'E.g. major, minor or patch', |
97
|
|
|
); |
98
|
|
|
}, |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function isCommitEnabled(): bool |
103
|
|
|
{ |
104
|
|
|
if ($this->option('no-commit')) { |
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $this->option('commit') || config('cruise.bump.auto-commit'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
private function isCommitDisabled(): bool |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
return ! $this->isCommitEnabled(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
private function displaySemverOptions(): void |
117
|
|
|
{ |
118
|
|
|
$data = []; |
119
|
|
|
|
120
|
|
|
foreach (self::TYPES as $type) { |
121
|
|
|
$process = Process::path(base_path())->run([ |
122
|
|
|
'bash', $this->getVersionScriptPath('semver.sh'), |
123
|
|
|
"--$type", |
124
|
|
|
]); |
125
|
|
|
|
126
|
|
|
$data[] = [ |
127
|
|
|
'type' => ucwords($type), |
128
|
|
|
'old' => $this->version, |
129
|
|
|
'new' => trim($process->output()), |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$this->table(['Type', 'Old', 'New'], $data); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.