From 7cae2dfaeda8d1859cb92be5807c0e85d1095565 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 6 Dec 2017 18:03:15 +1300 Subject: [PATCH] BUG Fix --repository so that it actually works --- src/Commands/Release/Archive.php | 3 +- src/Utility/Composer.php | 99 +++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/src/Commands/Release/Archive.php b/src/Commands/Release/Archive.php index e2c4ea2..8b9af48 100644 --- a/src/Commands/Release/Archive.php +++ b/src/Commands/Release/Archive.php @@ -22,13 +22,14 @@ protected function fire() // Get arguments $project = $this->getProject(); $releasePlan = $this->getReleasePlan(); + $repository = $this->getInputRepository(); // Ensure we wait, even if just building archive $wait = new WaitStep($this, $project, $releasePlan); $wait->run($this->input, $this->output); // Create packages - $package = new BuildArchive($this, $project, $releasePlan); + $package = new BuildArchive($this, $project, $releasePlan, $repository); $package->run($this->input, $this->output); } } diff --git a/src/Utility/Composer.php b/src/Utility/Composer.php index 7db86be..a4ac4f7 100644 --- a/src/Utility/Composer.php +++ b/src/Utility/Composer.php @@ -45,27 +45,100 @@ public static function createProject( $repository = null, $preferDist = false ) { - $command = [ - "composer", - "create-project", + // Create-options + $createOptions = [ + "--no-secure-http", "--no-interaction", "--ignore-platform-reqs", - $recipe, - $directory, - $version ]; + + // Set dev / stable options if ($preferDist) { - $command[] = "--prefer-dist"; - $command[] = "--no-dev"; + $createOptions[] = "--prefer-dist"; + $createOptions[] = "--no-dev"; } else { - $command[] = "--prefer-source"; - $command[] = "--keep-vcs"; + $createOptions[] = "--prefer-source"; + $createOptions[] = "--keep-vcs"; // create only } + + // If using a repository, we must delay for a later update + if ($repository) { + $createOptions[] = '--repository'; + $createOptions[] = $repository; + $createOptions[] = '--no-install'; + } + + // Create comand + $runner->runCommand(array_merge([ + "composer", + "create-project", + $recipe, + $directory, + $version + ], $createOptions), "Could not create project with version {$version}"); + + // Update un-installed project with custom repository if ($repository) { - $command[] = '--repository'; - $command[] = $repository; + // Add repository temporarily + $runner->runCommand([ + 'composer', + 'config', + 'repositories.temp', + 'composer', + $repository, + '--working-dir', + $directory, + ]); + // Enable http:// local repositories + $runner->runCommand([ + 'composer', + 'config', + 'secure-http', + 'false', + '--working-dir', + $directory, + ]); + + // update options + $updateOptions = [ + "--no-interaction", + "--ignore-platform-reqs", + ]; + + // Set dev / stable options + if ($preferDist) { + $updateOptions[] = "--prefer-dist"; + $updateOptions[] = "--no-dev"; + } else { + $updateOptions[] = "--prefer-source"; + } + + // Update with the given repository + $runner->runCommand(array_merge([ + 'composer', + 'update', + '--working-dir', + $directory, + ], $updateOptions), "Could not update project"); + + // Revert changes made above + $runner->runCommand([ + 'composer', + 'config', + '--unset', + 'repositories.temp', + '--working-dir', + $directory, + ]); + $runner->runCommand([ + 'composer', + 'config', + '--unset', + 'secure-http', + '--working-dir', + $directory, + ]); } - $runner->runCommand($command, "Could not create project with version {$version}"); } /**