forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPackageBuild.php
More file actions
86 lines (71 loc) · 2.4 KB
/
Copy pathPackageBuild.php
File metadata and controls
86 lines (71 loc) · 2.4 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace PHPCensor\Plugin;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Plugin;
/**
* Create a ZIP or TAR.GZ archive of the entire build.
*
* @author Dan Cryer <dan@block8.co.uk>
*/
class PackageBuild extends Plugin
{
protected $directory;
protected $filename;
protected $format;
/**
* @return string
*/
public static function pluginName()
{
return 'package_build';
}
/**
* {@inheritdoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$path = $this->builder->buildPath;
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
$this->filename = isset($options['filename']) ? $options['filename'] : 'build';
$this->format = isset($options['format']) ? $options['format'] : 'zip';
}
/**
* Executes Composer and runs a specified command (e.g. install / update)
*/
public function execute()
{
$path = $this->builder->buildPath;
$build = $this->build;
if ($this->directory == $path) {
return false;
}
$filename = str_replace('%build.commit%', $build->getCommitId(), $this->filename);
$filename = str_replace('%build.id%', $build->getId(), $filename);
$filename = str_replace('%build.branch%', $build->getBranch(), $filename);
$filename = str_replace('%project.title%', $build->getProject()->getTitle(), $filename);
$filename = str_replace('%date%', date('Y-m-d'), $filename);
$filename = str_replace('%time%', date('Hi'), $filename);
$filename = preg_replace('/([^a-zA-Z0-9_-]+)/', '', $filename);
$curdir = getcwd();
chdir($this->builder->buildPath);
if (!is_array($this->format)) {
$this->format = [$this->format];
}
foreach ($this->format as $format) {
switch ($format) {
case 'tar':
$cmd = 'tar cfz "%s/%s.tar.gz" ./*';
break;
default:
case 'zip':
$cmd = 'zip -rq "%s/%s.zip" ./*';
break;
}
$success = $this->builder->executeCommand($cmd, $this->directory, $filename);
}
chdir($curdir);
return $success;
}
}