Skip to content

Commit

Permalink
Merge pull request #477 from nishigori/composer-version-specify
Browse files Browse the repository at this point in the history
Support composer.phar version specify
  • Loading branch information
willdurand committed Feb 19, 2014
2 parents 7480363 + c0d343f commit ff8b64f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/capifony_symfony2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def self.load_into(configuration)
# If set to false, Capifony will download/install composer
set :composer_bin, false

# Release number to composer
# If you would like to instead update to a specific release simply specify it (for example '1.0.0-alpha8')
set :composer_version, ""

# Options to pass to composer when installing/updating
set :composer_options, "--no-dev --verbose --prefer-dist --optimize-autoloader --no-progress"

Expand Down
11 changes: 8 additions & 3 deletions lib/symfony2/symfony.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,25 @@
namespace :composer do
desc "Gets composer and installs it"
task :get, :roles => :app, :except => { :no_release => true } do
install_options = ''
unless composer_version.empty?
install_options += " -- --version=#{composer_version}"
end

if use_composer_tmp
# Because we always install to temp location we assume that we download composer every time.
logger.debug "Downloading composer to #{$temp_destination}"
capifony_pretty_print "--> Downloading Composer to temp location"
run_locally "cd #{$temp_destination} && curl -s http://getcomposer.org/installer | #{php_bin}"
run_locally "cd #{$temp_destination} && curl -s http://getcomposer.org/installer | #{php_bin}#{install_options}"
else
if !remote_file_exists?("#{latest_release}/composer.phar")
capifony_pretty_print "--> Downloading Composer"

run "#{try_sudo} sh -c 'cd #{latest_release} && curl -s http://getcomposer.org/installer | #{php_bin}'"
run "#{try_sudo} sh -c 'cd #{latest_release} && curl -s http://getcomposer.org/installer | #{php_bin}#{install_options}'"
else
capifony_pretty_print "--> Updating Composer"

run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} composer.phar self-update'"
run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} composer.phar self-update #{composer_version}'" \
end
end
capifony_puts_ok
Expand Down
29 changes: 27 additions & 2 deletions spec/capifony_symfony2_symfony_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,21 @@
it { should_not have_run('vendorDir=/var/www/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/releases/20120927; fi;') }
it { should_not have_run(' sh -c \'cp /var/www/releases/20120920/composer.phar /var/www/releases/20120927/\'') }
it { should_not have_run(' sh -c \'cd /var/www/releases/20120927 && curl -s http://getcomposer.org/installer | php\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php composer.phar self-update\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php composer.phar self-update \'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && SYMFONY_ENV=prod php composer.phar install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress\'') }
end

context "when running symfony:composer:install with an existing composer.phar in the previous release and given composer_version" do
before do
@configuration.set :composer_version, "1.0.0-alpha8"
@configuration.stub(:remote_file_exists?).and_return(true)
@configuration.find_and_execute_task('symfony:composer:install')
end

it { should_not have_run('vendorDir=/var/www/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/releases/20120927; fi;') }
it { should_not have_run(' sh -c \'cp /var/www/releases/20120920/composer.phar /var/www/releases/20120927/\'') }
it { should_not have_run(' sh -c \'cd /var/www/releases/20120927 && curl -s http://getcomposer.org/installer | php -- --version=1.0.0-alpha8\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php composer.phar self-update 1.0.0-alpha8\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && SYMFONY_ENV=prod php composer.phar install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress\'') }
end

Expand All @@ -225,7 +239,7 @@
it { should_not have_run('vendorDir=/var/www/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/releases/20120927; fi;') }
it { should_not have_run(' sh -c \'cp /var/www/releases/20120920/composer.phar /var/www/releases/20120927/\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && curl -s http://getcomposer.org/installer | php\'') }
it { should_not have_run(' sh -c \'cd /var/www/releases/20120927 && php composer.phar self-update\'') }
it { should_not have_run(' sh -c \'cd /var/www/releases/20120927 && php composer.phar self-update \'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && SYMFONY_ENV=prod php composer.phar install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress\'') }
end

Expand Down Expand Up @@ -259,6 +273,17 @@
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && SYMFONY_ENV=prod my_composer install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress\'') }
end

context "when running symfony:composer:install with a given composer_version" do
before do
@configuration.set :composer_version, "1.0.0-alpha8"
@configuration.find_and_execute_task('symfony:composer:install')
end

it { should_not have_run('vendorDir=/var/www/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/releases/20120927; fi;') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && curl -s http://getcomposer.org/installer | php -- --version=1.0.0-alpha8\'') }
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && SYMFONY_ENV=prod php composer.phar install --no-dev --verbose --prefer-dist --optimize-autoloader --no-progress\'') }
end

context "when running symfony:composer:install with enabled copy_vendors" do
before do
@configuration.set :copy_vendors, true
Expand Down

0 comments on commit ff8b64f

Please sign in to comment.