-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.php
executable file
·52 lines (41 loc) · 1.04 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env php
<?php
define("ROOTPATH", realpath(__DIR__));
$projectsPath = ROOTPATH . '/projects';
$errors = [];
function validateFile(string $file)
{
$result = yaml_parse_file($file);
if (!$result) {
throw new Exception("Invalid format");
}
if (empty($result['name'])) {
throw new Exception('Name must be set!');
}
if (empty($result['alias'])) {
throw new Exception('Alias must be set!');
}
$projects = $result['projects'];
foreach ($projects as $index => $prj) {
if (empty($prj['name'])) {
throw new Exception("Name of project {$index} must be set!");
}
}
}
foreach (glob("{$projectsPath}/*.yml") as $file) {
$filename = basename($file);
try {
validateFile($file);
} catch (Throwable $exception) {
$errors[$filename] = $exception->getMessage();
}
}
if (empty($errors)) {
echo "Passed\n";
exit(0);
}
foreach ($errors as $file => $message) {
echo " == {$file} == \n";
echo " == {$message} \n\n";
}
exit(1);