-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeDownloader.php
More file actions
56 lines (48 loc) · 1.94 KB
/
RuntimeDownloader.php
File metadata and controls
56 lines (48 loc) · 1.94 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
<?php
namespace Webteractive\Devstack;
use ZipArchive;
class RuntimeDownloader
{
use ShouldConfigure,
WithHttp;
protected $command;
public function __construct($command, $config)
{
$this->command = $command;
$this->config = $config;
}
public function download($shouldGetTheLatestRuntimes = true)
{
if ($shouldGetTheLatestRuntimes) {
$this->devstackStorage()->deleteDirectory('runtimes');
$this->command->info("Downloading fresh runtimes from {$this->config['repository']}.");
}
$archive = $this->homePath('runtimes.zip');
$downloadUrl = join('/', [$this->config['repository'], 'zipball', $this->config['branch']]);
$response = $this->http()->get($downloadUrl, [
'headers' => [
'Authorization' => 'token ' . $this->config['token'],
],
'sink' => $archive
]);
if ($response->getStatusCode() == 200) {
$zip = new ZipArchive;
if ($zip->open($archive)) {
$zip->extractTo($this->homePath('tmp'));
$zip->close();
$this->devstackStorage()->delete('runtimes.zip');
$extracted = $this->devstackStorage()->directories('tmp')[0];
$extractedName = explode('-', pathinfo($extracted, PATHINFO_BASENAME));
$hash = array_pop($extractedName);
$this->command->info("Now using runtimes from the commit {$hash}");
$runtimes = $this->devstackStorage()->directories($extracted);
foreach ($runtimes as $runtime) {
$runtimeName = pathinfo($runtime, PATHINFO_BASENAME);
$this->runtimes[$runtimeName] = $runtime;
$this->devstackStorage()->move($runtime, 'runtimes/' . $runtimeName);
}
$this->devstackStorage()->deleteDirectory('tmp');
}
}
}
}