-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrutinizer.php
More file actions
64 lines (42 loc) · 1.26 KB
/
scrutinizer.php
File metadata and controls
64 lines (42 loc) · 1.26 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require 'constants.php';
class Deploy
{
const URL = SCRUTINIZER_ENDPOINT . '?access_token=' . TOKEN;
public function getLastBuild()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, self::URL);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = json_decode(curl_exec($curl));
curl_close($curl);
$lastCommit = $this->getLastCommit();
$currentCommit = $this->saveCurrentCommit($output->_embedded->inspections[0]->metadata->source_reference);
if ($lastCommit == $currentCommit) {
print "Already updated" . "\n";
exit;
}
return $output->_embedded->inspections[0]->build->status;
}
public function getLastCommit()
{
return fgets(fopen('commit.txt', 'r'));
}
public function saveCurrentCommit($commit)
{
$file = fopen("commit.txt", "w") or die("Unable to open file!");
fwrite($file, $commit);
fclose($file);
return $commit;
}
public function run()
{
if ($this->getLastBuild() != "passed") {
throw new Exception("Last Build Failed");
}
shell_exec('cd ' . PATH_DEPLOY_SOURCE . ' && dep deploy:unlock -vvv');
shell_exec('cd ' . PATH_DEPLOY_SOURCE . ' && dep deploy -vvv');
}
}
$Deploy = new Deploy;
$Deploy->run();