File tree Expand file tree Collapse file tree 4 files changed +78
-0
lines changed
GenerateQuestions/Choices Expand file tree Collapse file tree 4 files changed +78
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BlameButton \LaravelDockerBuilder \Commands ;
4
+
5
+ use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \Choices \CiPlatform ;
6
+ use BlameButton \LaravelDockerBuilder \Detector \CiPlatformDetector ;
7
+
8
+ class DockerCiCommand extends BaseCommand
9
+ {
10
+ protected $ name = 'docker:ci ' ;
11
+
12
+ protected $ description = '' ;
13
+
14
+ public function handle (): int
15
+ {
16
+ $ detected = app (CiPlatformDetector::class)->detect ();
17
+
18
+ if (CiPlatform::GITLAB_CI === $ detected ) {
19
+ $ output = base_path ('.gitlab-ci.yml ' );
20
+
21
+ if (file_exists ($ output )) {
22
+ return self ::SUCCESS ;
23
+ }
24
+
25
+ copy (package_path ('resources/templates/.gitlab-ci.yml ' ), $ output );
26
+ }
27
+
28
+ return self ::SUCCESS ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \Choices ;
4
+
5
+ class CiPlatform
6
+ {
7
+ public const GITLAB_CI = 'gitlab ' ;
8
+
9
+ public const GITHUB_ACTIONS = 'github ' ;
10
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace BlameButton \LaravelDockerBuilder \Detector ;
4
+
5
+ use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \Choices \CiPlatform ;
6
+ use Illuminate \Support \Str ;
7
+
8
+ class CiPlatformDetector implements DetectorContract
9
+ {
10
+ public function detect (): string |false
11
+ {
12
+ $ base = base_path ();
13
+
14
+ do {
15
+ $ git = $ base .'/.git/config ' ;
16
+
17
+ if (! file_exists ($ git )) {
18
+ $ base = Str::beforeLast ($ base , '/ ' );
19
+
20
+ continue ;
21
+ }
22
+
23
+ $ git = file_get_contents ($ git );
24
+
25
+ if (Str::contains ($ git , 'gitlab ' )) {
26
+ return CiPlatform::GITLAB_CI ;
27
+ }
28
+
29
+ if (Str::contains ($ git , 'github ' )) {
30
+ return CiPlatform::GITHUB_ACTIONS ;
31
+ }
32
+ } while (Str::contains ($ base , '/ ' ));
33
+
34
+ return false ;
35
+ }
36
+ }
Original file line number Diff line number Diff line change 3
3
namespace BlameButton \LaravelDockerBuilder ;
4
4
5
5
use BlameButton \LaravelDockerBuilder \Commands \DockerBuildCommand ;
6
+ use BlameButton \LaravelDockerBuilder \Commands \DockerCiCommand ;
6
7
use BlameButton \LaravelDockerBuilder \Commands \DockerGenerateCommand ;
7
8
use BlameButton \LaravelDockerBuilder \Commands \DockerPushCommand ;
8
9
use Illuminate \Support \ServiceProvider ;
@@ -14,6 +15,7 @@ public function boot(): void
14
15
if ($ this ->app ->runningInConsole ()) {
15
16
$ this ->commands ([
16
17
DockerBuildCommand::class,
18
+ DockerCiCommand::class,
17
19
DockerGenerateCommand::class,
18
20
DockerPushCommand::class,
19
21
]);
You can’t perform that action at this time.
0 commit comments