Skip to content

Commit

Permalink
API Complete tar and zip file generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Oct 6, 2015
1 parent 4f0789b commit a8c2c5c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/Commands/Release/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*
* @author dmooyman
*/
class Archive extends Release {
class Archive extends Publish {

/**
*
* @var string
*/
protected $name = 'release:archive';
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Release/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author dmooyman
*/
class Push extends Release {
class Push extends Publish {

/**
* @var string
Expand Down
9 changes: 0 additions & 9 deletions src/Commands/Release/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ protected function getInputVersion() {
return new ReleaseVersion($value);
}

/**
* Get the aws profile to use
*
* @return silverstripe
*/
public function getInputAWSProfile() {
return $this->input->getOption('aws-profile');
}

/**
* Determine the branch name that should be used
*
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Release/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*
* @author dmooyman
*/
class Tag extends Release {
class Tag extends Publish {

/**
*
* @var string
*/
protected $name = 'release:tag';
Expand Down
3 changes: 1 addition & 2 deletions src/Commands/Release/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*
* @author dmooyman
*/
class Upload extends Release {
class Upload extends Publish {

/**
*
* @var string
*/
protected $name = 'release:upload';
Expand Down
2 changes: 1 addition & 1 deletion src/Model/ReleaseVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function getReleaseFilenames() {
/**
* For this version, generate the filename
*
* @param bol $includeCMS Does this include CMS?
* @param bool $includeCMS Does this include CMS?
* @param string $extension archive extension (including period)
* @return string
*/
Expand Down
39 changes: 23 additions & 16 deletions src/Steps/Release/BuildArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Cow\Steps\Release;

use Exception;
use SilverStripe\Cow\Commands\Command;
use SilverStripe\Cow\Model\Project;
use SilverStripe\Cow\Model\ReleaseVersion;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function run(InputInterface $input, OutputInterface $output) {
$this->log($output, "Generating new archive files");
$path = $this->createProject($output);
$this->buildFiles($output, $path);
$this->log($output, 'Upload complete');
$this->log($output, 'Archive complete');
}

/**
Expand Down Expand Up @@ -99,22 +100,22 @@ protected function unlink($folder) {
*
* @param string $from
* @param string $to
* @throws \Exception
* @throws Exception
*/
protected function copy($from, $to) {
$this->unlink($to);

// Copy file if not a folder
if(!is_dir($from)) {
if(copy($from, $to) === false) {
throw new \Exception("Could not copy from {$from} to {$to}");
throw new Exception("Could not copy from {$from} to {$to}");
}
return;
}

// Create destination
if(mkdir($to) === false) {
throw new \Exception("Could not create destination folder {$to}");
throw new Exception("Could not create destination folder {$to}");
}

// Iterate files
Expand All @@ -133,12 +134,12 @@ protected function copy($from, $to) {
*
* @param string $path
* @param string $content
* @throws \Exception
* @throws Exception
*/
protected function write($path, $content) {
$result = file_put_contents($path, $content);
if($result === false) {
throw new \Exception("Could not write to {$path}");
throw new Exception("Could not write to {$path}");
}
}

Expand Down Expand Up @@ -216,20 +217,26 @@ protected function createProject(OutputInterface $output) {
* @param string $path Location of project to archive
*/
protected function buildFiles(OutputInterface $output, $path) {
/*
$version = $this->getVersion()->getValue();
$cmsArchive = "SilverStripe-cms-v{$version}";
$frameworkArchive = "SilverStripe-framework-v{$version}";
$destination = $this->getProject()->getDirectory();

// Build tar files
$phar = new PharData($destination . '/' . $cmsArchive);
foreach($this->getVersion()->getReleaseFilenames() as $filename) {
// Build paths
$this->log($output, "Uploading <info>{$filename}</info>");
$from = $this->getProject()->getDirectory() . '/' . $filename;
}*/
// Build each version
foreach(array($cmsArchive, $frameworkArchive) as $archive) {
$sourceDirArg = escapeshellarg("{$path}/{$archive}/");

// Build tar files
$tarFile = "{$destination}/{$archive}.tar.gz";
$this->log($output, "Building <info>$tarFile</info>");
$tarFileArg = escapeshellarg($tarFile);
$this->runCommand($output, "cd {$sourceDirArg} && tar -cvzf {$tarFileArg} .");

// Build zip files
$zipFile = "{$destination}/{$archive}.zip";
$this->log($output, "Building <info>{$zipFile}</info>");
$zipFileArg = escapeshellarg($zipFile);
$this->runCommand($output, "cd {$sourceDirArg} && zip -rv {$zipFileArg} .");
}
}
}

0 comments on commit a8c2c5c

Please sign in to comment.