Skip to content

Commit

Permalink
Merge pull request #163 from openeuropa/EWPP-2006
Browse files Browse the repository at this point in the history
EWPP-2006: Support for --zip in create-archive.
  • Loading branch information
hernani authored Feb 21, 2022
2 parents db314c9 + b36384c commit d6c1015
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/Commands/ReleaseCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public function setRuntimeConfig(ConsoleCommandEvent $event)
* This command creates a .tag.gz archive for the current project named as
* follow:
*
* [PROJECT-NAME]-[CURRENT-TAG].tar.gz
* [PROJECT-NAME]-[CURRENT-TAG].[file-format]
*
* Where [file-format] can be tar.gz or zip, in case --zip option is used.
*
* If the current commit is not tagged then the current local branch name will
* be used:
*
* [PROJECT-NAME]-[BRANCH-NAME].tar.gz
* [PROJECT-NAME]-[BRANCH-NAME].[file-format]
*
* When running the release command will create a temporary release directory
* named after the project itself. Such a directory will be deleted after
Expand All @@ -65,6 +67,8 @@ public function setRuntimeConfig(ConsoleCommandEvent $event)
*
* If you wish to override the current tag use the "--tag" option.
*
* If you wish to use zip format use "--zip" option.
*
* Before the release directory is archived you can run a list of packaging
* commands in your runner.yml.dist, as shown below:
*
Expand All @@ -84,17 +88,20 @@ public function setRuntimeConfig(ConsoleCommandEvent $event)
*
* @option tag Release tag, will override current repository tag.
* @option keep Whereas to keep the temporary release directory or not.
* @option zip Create archive in zip file format.
*
* @aliases release:ca,rca
*/
public function createRelease(array $options = [
'tag' => InputOption::VALUE_OPTIONAL,
'keep' => false,
'zip' => false
])
{
$file_format = $options['zip'] ? 'zip' : 'tar.gz';
$name = $this->composer->getProject();
$version = $options['tag'] !== null ? $options['tag'] : $this->getVersionString();
$archive = "$name-$version.tar.gz";
$archive = "$name-$version." . $file_format;

$tasks = [
// Make sure we do not have a release directory yet.
Expand All @@ -111,8 +118,11 @@ public function createRelease(array $options = [
$tasks[] = $this->taskCollectionFactory($releaseTasks);

// Create archive.
$tasks[] = $this->taskExecStack()->exec("tar -czf $archive $name");

if ($options['zip']) {
$tasks[] = $this->taskExecStack()->exec("zip -r $archive $name");
} else {
$tasks[] = $this->taskExecStack()->exec("tar -czf $archive $name");
}
// Remove release directory, if not specified otherwise.
if (!$options['keep']) {
$tasks[] = $this->taskFilesystemStack()->remove($name);
Expand Down
10 changes: 5 additions & 5 deletions src/TaskRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private function createConfiguration()
$processor = (new ConfigProcessor())->add($config->export());
$this->config->import($processor->export());
// Keep the container in sync.
$this->container->share('config', $this->config);
$this->container->add('config', $this->config);
}

/**
Expand Down Expand Up @@ -270,10 +270,10 @@ private function createContainer(
) {
$container = Robo::createDefaultContainer($input, $output, $application, $config, $classLoader);
$container->get('commandFactory')->setIncludeAllPublicMethods(false);
$container->share('task_runner.composer', Composer::class)->addArgument($this->workingDir);
$container->share('task_runner.time', Time::class);
$container->share('repository', Repository::class)->addArgument($this->workingDir);
$container->share('filesystem', Filesystem::class);
$container->add('task_runner.composer', Composer::class)->addArgument($this->workingDir);
$container->add('task_runner.time', Time::class);
$container->add('repository', Repository::class)->addArgument($this->workingDir);
$container->add('filesystem', Filesystem::class);

// Add service inflectors.
$container->inflector(ComposerAwareInterface::class)
Expand Down
36 changes: 36 additions & 0 deletions tests/fixtures/commands/release-create-archive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,39 @@
- "[Simulator] { task: copy, from: fonts, to: test_project/fonts }"
- "[Simulator] { task: copy, from: images, to: test_project/images }"
not_contains: []

- configuration:
release:
tasks: []
options: "--zip"
repository:
hash: "19di3458"
revision: "refs/heads/master"
tag: "1.2.0"
branches:
- { name: "develop", local: false, revision: "refs/heads/develop" }
- { name: "master", local: true, revision: "refs/heads/master" }
contains:
- |
[Simulator] Simulating Filesystem\FilesystemStack()
->remove(array (
0 => 'test_project-1.2.0.zip',
1 => 'test_project',
))
[Simulator] Simulating Vcs\GitStack('git')
->exec(array (
0 => 'archive',
1 => 'HEAD',
2 => '-o test_project.zip',
))
[Simulator] Simulating Archive\Extract('test_project.zip')
->to('test_project')
[Simulator] Simulating Filesystem\FilesystemStack()
->remove('test_project.zip')
[Simulator] Simulating OpenEuropa\TaskRunner\Tasks\CollectionFactory\CollectionFactory(array (
))
[Simulator] Simulating ExecStack()
->exec('zip -r test_project-1.2.0.zip test_project')
[Simulator] Simulating Filesystem\FilesystemStack()
->remove('test_project')
not_contains: []

0 comments on commit d6c1015

Please sign in to comment.