1 | <?php |
||
2 | /** |
||
3 | * DevCheckCommand.php |
||
4 | * |
||
5 | * -Description- |
||
6 | * |
||
7 | * This program is free software: you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation, either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
19 | * |
||
20 | * @link https://www.librenms.org |
||
21 | * |
||
22 | * @copyright 2020 Tony Murray |
||
23 | * @author Tony Murray <[email protected]> |
||
24 | */ |
||
25 | |||
26 | namespace App\Console\Commands; |
||
27 | |||
28 | use App\Console\LnmsCommand; |
||
29 | use Illuminate\Support\Arr; |
||
30 | use LibreNMS\Util\CiHelper; |
||
31 | use Symfony\Component\Console\Input\InputArgument; |
||
32 | use Symfony\Component\Console\Input\InputOption; |
||
33 | |||
34 | class DevCheckCommand extends LnmsCommand |
||
35 | { |
||
36 | protected $developer = true; |
||
37 | protected $name = 'dev:check'; |
||
38 | |||
39 | /** @var CiHelper */ |
||
40 | protected $helper; |
||
41 | |||
42 | public function __construct() |
||
43 | { |
||
44 | parent::__construct(); |
||
45 | $this->addArgument('check', InputArgument::OPTIONAL, __('commands.dev:check.arguments.check', ['checks' => '[unit, lint, style, dusk]']), 'all'); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
46 | $this->addOption('os', 'o', InputOption::VALUE_REQUIRED); |
||
47 | $this->addOption('module', 'm', InputOption::VALUE_REQUIRED); |
||
48 | $this->addOption('fail-fast', 'f', InputOption::VALUE_NONE); |
||
49 | $this->addOption('quiet', 'q', InputOption::VALUE_NONE); |
||
50 | $this->addOption('db', null, InputOption::VALUE_NONE); |
||
51 | $this->addOption('snmpsim', null, InputOption::VALUE_NONE); |
||
52 | $this->addOption('full', null, InputOption::VALUE_NONE); |
||
53 | $this->addOption('commands', 'c', InputOption::VALUE_NONE); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Execute the console command. |
||
58 | * |
||
59 | * @return mixed |
||
60 | */ |
||
61 | public function handle() |
||
62 | { |
||
63 | $this->helper = new CiHelper(); |
||
64 | $this->parseInput(); |
||
65 | $this->helper->detectChangedFiles(); |
||
66 | $this->helper->checkEnvSkips(); |
||
67 | |||
68 | $result = $this->helper->run(); |
||
69 | |||
70 | if ($result == 0 && $this->helper->allChecksComplete()) { |
||
71 | $this->line("\033[32mTests ok, submit away :)\033[0m"); |
||
72 | } |
||
73 | |||
74 | return $result; |
||
75 | } |
||
76 | |||
77 | private function parseInput() |
||
78 | { |
||
79 | $check = $this->argument('check'); |
||
80 | if (! in_array($check, ['all', 'lint', 'style', 'unit', 'web', 'ci'])) { |
||
81 | $this->error("Invalid check: $check"); |
||
82 | exit(1); |
||
0 ignored issues
–
show
|
|||
83 | } |
||
84 | |||
85 | $this->helper->setFlags(Arr::only($this->options(), ['quiet', 'commands', 'fail-fast', 'full'])); |
||
86 | |||
87 | $this->helper->enable('style', $check == 'all' || $check === 'style'); |
||
88 | $this->helper->enable('lint', $check == 'all' || $check == 'ci' || $check === 'lint'); |
||
89 | $this->helper->enable('unit', $check == 'all' || $check == 'ci' || $check === 'unit'); |
||
90 | $this->helper->enable('web', $check == 'ci' || $check === 'web'); |
||
91 | |||
92 | if ($os = $this->option('os')) { |
||
93 | $this->helper->setFlags(['style_enable' => false, 'lint_enable' => false, 'unit_enable' => true, 'web_enable' => false]); |
||
94 | $this->helper->setOS(explode(',', $os)); |
||
95 | } |
||
96 | |||
97 | if ($modules = $this->option('module')) { |
||
98 | $this->helper->setFlags(['style_enable' => false, 'lint_enable' => false, 'unit_enable' => true, 'web_enable' => false]); |
||
99 | $this->helper->setModules(explode(',', $modules)); |
||
100 | } |
||
101 | |||
102 | if ($check == 'ci') { |
||
103 | $this->helper->setFlags(['ci' => true, 'fail-fast' => true]); |
||
104 | $this->helper->duskHeadless(); |
||
105 | $this->helper->enableSnmpsim(); |
||
106 | $this->helper->enableDb(); |
||
107 | } |
||
108 | |||
109 | if ($this->option('snmpsim')) { |
||
110 | $this->helper->enableSnmpsim(); |
||
111 | } |
||
112 | |||
113 | if ($this->option('db')) { |
||
114 | $this->helper->enableDb(); |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 |