2013-05-18 00:19:38 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-18 00:19:38 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Plugin;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\Model\Build;
|
2013-10-10 02:12:30 +02:00
|
|
|
|
2013-05-18 00:19:38 +02:00
|
|
|
/**
|
2013-05-20 15:06:53 +02:00
|
|
|
* Create a ZIP or TAR.GZ archive of the entire build.
|
2013-05-18 00:19:38 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Plugins
|
|
|
|
*/
|
|
|
|
class PackageBuild implements \PHPCI\Plugin
|
|
|
|
{
|
|
|
|
protected $directory;
|
|
|
|
protected $filename;
|
|
|
|
protected $format;
|
|
|
|
protected $phpci;
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Set up the plugin, configure options, etc.
|
|
|
|
* @param Builder $phpci
|
|
|
|
* @param Build $build
|
|
|
|
* @param array $options
|
|
|
|
*/
|
2013-10-10 02:12:30 +02:00
|
|
|
public function __construct(Builder $phpci, Build $build, array $options = array())
|
2013-05-18 00:19:38 +02:00
|
|
|
{
|
|
|
|
$path = $phpci->buildPath;
|
2013-10-10 02:01:06 +02:00
|
|
|
$this->build = $build;
|
2013-05-18 00:19:38 +02:00
|
|
|
$this->phpci = $phpci;
|
|
|
|
$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->phpci->buildPath;
|
2013-10-10 02:01:06 +02:00
|
|
|
$build = $this->build;
|
2013-05-18 00:19:38 +02:00
|
|
|
|
|
|
|
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->phpci->buildPath);
|
|
|
|
|
|
|
|
if (!is_array($this->format)) {
|
|
|
|
$this->format = array($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->phpci->executeCommand($cmd, $this->directory, $filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir($curdir);
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
}
|