Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Use default value when some config is not set in TravisCi, avoid exce…
Browse files Browse the repository at this point in the history
…ption when template for a language / version does not exist
  • Loading branch information
joelwurtz committed Feb 21, 2014
1 parent 7100908 commit 01e0f2b
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/Joli/JoliCi/BuildStrategy/TravisCiBuildStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public function createBuilds($directory)
foreach ($config[$versionKey] as $version) {
$this->builder->setTemplateName(sprintf("%s/Dockerfile-%s.twig", $language, $version));
$this->builder->setVariables(array(
'before_install' => $this->getAsArray($config, 'before_install'),
'install' => $this->getAsArray($config, 'install'),
'before_script' => $this->getAsArray($config, 'before_script'),
'script' => $this->getAsArray($config, 'script')
'before_install' => $this->getConfigValue($config, $language, 'before_install'),
'install' => $this->getConfigValue($config, $language, 'install'),
'before_script' => $this->getConfigValue($config, $language, 'before_script'),
'script' => $this->getConfigValue($config, $language, 'script')
));

$buildName = sprintf("%s-%s", $language, $version);
Expand All @@ -102,9 +102,14 @@ public function createBuilds($directory)
$this->filesystem->rcopy($directory, $buildDir, true);

$this->builder->setOutputName('Dockerfile');
$this->builder->writeOnDisk($buildDir);

$builds[] = new Build($buildName, $buildDir);
try {
$this->builder->writeOnDisk($buildDir);

$builds[] = new Build($buildName, $buildDir);
} catch (\Twig_Error_Loader $e) {
//Do nothing, template does not exist so language-php is not supported by JoliCI (emit a warning ?)
}
}

return $builds;
Expand All @@ -126,9 +131,22 @@ public function supportProject($directory)
return file_exists($directory.DIRECTORY_SEPARATOR.".travis.yml") && is_file($directory.DIRECTORY_SEPARATOR.".travis.yml");
}

private function getAsArray($config, $key)
/**
* Get command lines to add for a configuration value in .travis.yml file
*
* @param array $config Configuration of travis ci parsed
* @param string $language Language for getting the default value if no value is set
* @param string $key Configuration key
*
* @return array A list of command to add to Dockerfile
*/
private function getConfigValue($config, $language, $key)
{
if (!isset($config[$key])) {
if (!isset($config[$key]) || empty($config[$key])) {
if (isset($this->defaults[$language][$key])) {
return $this->defaults[$language][$key];
}

return array();
}

Expand Down

0 comments on commit 01e0f2b

Please sign in to comment.