return $dir;
}
/**
 * Create a tar or the extension and return the location of the create .tar
 *
 * @param $location
 * @param $archiveName
 * @param array $extensions
 * @return string
 */
function _createArchive($location, $archiveName, array $extensions)
{
    $path = $location . DIRECTORY_SEPARATOR . $archiveName;
    echo "Creating archive @ {$path}\n";
    $cmdPat = "cd '%s' && tar --exclude 'EbayEnterprise/*/Test' -rpf '{$path}' .";
    shell_exec(sprintf($cmdPat, 'src'));
    foreach ($extensions as $dir) {
        shell_exec(sprintf($cmdPat, "extensions/{$dir}/src"));
    }
    return $path;
}
// Get the latest reachable tag as the current, to become old version
$newVersion = trim(shell_exec('git describe --abbrev=0'));
$oldVersion = trim(shell_exec(sprintf('git describe --abbrev=0 %s~', $newVersion)));
echo "Setup config for upgrade from {$oldVersion} to {$newVersion}\n";
$tempDir = _createTempDir();
$archiveName = 'eBay_Retail_Order_Management.tar';
$extensions = array('magento-file-transfer', 'magento-log', 'php-dom');
_createArchive($tempDir, $archiveName, $extensions);
$releaseNotes = trim(shell_exec(sprintf("git log --pretty=format:'%%s' \"%s\"..", $oldVersion)));
return array('base_dir' => $tempDir, 'archive_files' => $archiveName, 'extension_name' => 'eBay_Enterprise_Retail_Order_Management', 'extension_version' => $newVersion, 'skip_version_compare' => true, 'path_output' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'build', 'stability' => 'beta', 'license' => 'proprietary', 'channel' => 'community', 'summary' => 'eBay Enterprise Retail Order Management', 'description' => 'eBay Enterprise Retail Order Management', 'notes' => $releaseNotes, 'author_name' => 'Some Body', 'author_user' => 'somebody', 'author_email' => '*****@*****.**', 'php_min' => '5.3.0', 'php_max' => '5.3.99', 'extensions' => array());
    // this will create a temp file but as we need a temp
    // directory, delete the file and replace it with a directory
    $dir = tempnam(sys_get_temp_dir(), '_archtmp');
    @unlink($dir);
    @mkdir($dir, 0700);
    return $dir;
}
/**
 * Create a tar or the extension and return the location of the create .tar
 * @return string
 */
function _createArchive($location, $archiveName, array $extensions = array())
{
    $path = $location . DIRECTORY_SEPARATOR . $archiveName;
    echo "Creating archive @ {$path}\n";
    $cmdPat = "cd '%s' && tar --exclude 'EbayEnterprise/*/Test' --exclude='order_id_init.php' -rpf '{$path}' .";
    shell_exec(sprintf($cmdPat, 'src'));
    foreach ($extensions as $dir) {
        shell_exec(sprintf($cmdPat, "extensions/{$dir}/src"));
    }
    return $path;
}
// Get the latest reachable tag as the current, to become old version
$newVersion = trim(shell_exec('git describe --abbrev=0'));
$oldVersion = trim(shell_exec(sprintf('git describe --abbrev=0 %s~', $newVersion)));
echo "Setup config for upgrade from {$oldVersion} to {$newVersion}\n";
$tempDir = _createTempDir();
$archiveName = 'eBay_Enterprise_Display_Extension.tar';
_createArchive($tempDir, $archiveName);
$releaseNotes = trim(shell_exec(sprintf("git log --pretty=format:'%%s' \"%s\"..", $oldVersion)));
return array('base_dir' => $tempDir, 'archive_files' => $archiveName, 'extension_name' => 'eBay_Enterprise_Display_Extension', 'extension_version' => $newVersion, 'skip_version_compare' => true, 'path_output' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'build', 'stability' => 'stable', 'license' => 'OSL', 'channel' => 'community', 'summary' => 'eBay Enterprise Display Extension.', 'description' => 'eBay Enterprise Display Extension.', 'notes' => $releaseNotes, 'author_name' => 'Michael A. Smith', 'author_user' => 'msmith3', 'author_email' => '*****@*****.**', 'additional_authors' => array(array('author_name' => 'Michael Phang', 'author_user' => 'mphang', 'author_email' => '*****@*****.**'), array('author_name' => 'Mike West', 'author_user' => 'micwest', 'author_email' => '*****@*****.**'), array('author_name' => 'Reginald Gabriel', 'author_user' => 'rgabriel', 'author_email' => '*****@*****.**'), array('author_name' => 'Scott van Brug', 'author_user' => 'svanbrug', 'author_email' => '*****@*****.**')), 'php_min' => '5.3.0', 'php_max' => '5.6.99', 'extensions' => array());