diff --git a/lib/solidus_dev_support/extension.rb b/lib/solidus_dev_support/extension.rb index d192ebd2..28c395ff 100644 --- a/lib/solidus_dev_support/extension.rb +++ b/lib/solidus_dev_support/extension.rb @@ -2,6 +2,7 @@ require 'thor' require 'pathname' +require 'shellwords' require 'solidus_dev_support/version' @@ -16,7 +17,7 @@ class Extension < Thor def generate(raw_path = '.') self.path = raw_path - empty_directory path + run "git init #{path.shellescape} --quiet" directory 'app', "#{path}/app" directory 'lib', "#{path}/lib" diff --git a/lib/solidus_dev_support/rake_tasks.rb b/lib/solidus_dev_support/rake_tasks.rb index c24e04b8..a93d086e 100644 --- a/lib/solidus_dev_support/rake_tasks.rb +++ b/lib/solidus_dev_support/rake_tasks.rb @@ -27,12 +27,16 @@ def install end def install_test_app_task - require 'rake/clean' - require 'spree/testing_support/extension_rake' - ENV['DUMMY_PATH'] = test_app_path.to_s ENV['LIB_NAME'] = gemspec.name + # We need to skip solidus bolt for Solidus v3.2, + # otherwise it will try to install it when creating the dummy app. + ENV['SKIP_SOLIDUS_BOLT'] = 'true' + + require 'rake/clean' + require 'spree/testing_support/extension_rake' + ::CLOBBER.include test_app_path namespace :extension do diff --git a/lib/solidus_dev_support/templates/extension/.circleci/config.yml b/lib/solidus_dev_support/templates/extension/.circleci/config.yml index 28d70ebd..4f308922 100644 --- a/lib/solidus_dev_support/templates/extension/.circleci/config.yml +++ b/lib/solidus_dev_support/templates/extension/.circleci/config.yml @@ -17,17 +17,37 @@ jobs: - browser-tools/install-chrome - solidusio_extensions/run-tests run-specs-with-postgres: - executor: solidusio_extensions/postgres + executor: + name: solidusio_extensions/postgres + ruby_version: '3.1' steps: + - checkout - browser-tools/install-chrome - - solidusio_extensions/run-tests + - solidusio_extensions/run-tests-solidus-master + - solidusio_extensions/store-test-results + run-specs-with-mysql: - executor: solidusio_extensions/mysql + executor: + name: solidusio_extensions/mysql + ruby_version: '3.0' steps: + - checkout - browser-tools/install-chrome - - solidusio_extensions/run-tests + - solidusio_extensions/run-tests-solidus-current + - solidusio_extensions/store-test-results + + run-specs-with-sqlite: + executor: + name: solidusio_extensions/sqlite + ruby_version: '2.7' + steps: + - checkout + - browser-tools/install-chrome + - solidusio_extensions/run-tests-solidus-older + - solidusio_extensions/store-test-results + lint-code: - executor: solidusio_extensions/sqlite-memory + executor: solidusio_extensions/sqlite steps: - solidusio_extensions/lint-code @@ -37,6 +57,7 @@ workflows: - run-specs-with-sqlite - run-specs-with-postgres - run-specs-with-mysql + - run-specs-with-sqlite - lint-code "Weekly run specs against master": @@ -51,3 +72,4 @@ workflows: - run-specs-with-sqlite - run-specs-with-postgres - run-specs-with-mysql + - run-specs-with-sqlite diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index 00f421d6..c43e2b4c 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -1,35 +1,31 @@ #!/usr/bin/env bash +# Set the extension name +extension_name="<%= file_name %>" + set -e test -z "${DEBUG+empty_string}" || set -x +test -n "$DB" || echo "~~~> Use 'export DB=[postgres|mysql|sqlite3]' to control the DB adapter" +# Support CircleCI runs in which DB is set to "sqlite" by the extension ORB. test "$DB" = "sqlite" && export DB="sqlite3" +echo '~~~> Using $DB as the database engine' -if [ -z "$SOLIDUS_BRANCH" ] -then - echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch" - SOLIDUS_BRANCH="master" -fi -echo "~~> Using branch $SOLIDUS_BRANCH of solidus" - -if [ -z "$SOLIDUS_FRONTEND" ] -then - echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend" - SOLIDUS_FRONTEND="solidus_frontend" -fi -echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend" +test -n "$SOLIDUS_BRANCH" || echo "~~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch" +echo '~~~> Using branch $SOLIDUS_BRANCH of solidus' -extension_name="<%= file_name %>" - -# Stay away from the bundler env of the containing extension. -function unbundled { - ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ +# Override bundle in order to stay away from the +# bundler env of the containing extension. +function with_unbundled_env { + ruby -rbundler -e'Bundler.with_unbundled_env { system *ARGV }' -- $@ } +echo "~~~> Removing the old sandbox" rm -rf ./sandbox -unbundled bundle exec rails new sandbox \ - --database="${DB:-sqlite3}" \ - --skip-bundle \ + +echo "~~~> Creating a pristine Rails app" +with_unbundled_env rails new sandbox \ + --database="$DB" \ --skip-git \ --skip-keeps \ --skip-rc \ @@ -43,36 +39,30 @@ if [ ! -d "sandbox" ]; then fi cd ./sandbox -cat <> Gemfile -gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' -gem 'rails-i18n' -gem 'solidus_i18n' -gem '$extension_name', path: '..' +# Ensure any previous sandbox DB is recreated +bin/rails db:drop db:create -group :test, :development do - platforms :mri do - gem 'pry-byebug' - end -end +echo "~~~> Adding solidus to the Gemfile" +cat <> Gemfile +gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH' +gem 'pry-byebug', group: [:test, :development], platforms: [:mri] RUBY -unbundled bundle install --gemfile Gemfile - -unbundled bundle exec rake db:drop db:create +bundle config local.$extension_name "$PWD/.." +bundle config gemfile "$PWD/Gemfile" +with_unbundled_env bundle install -unbundled bundle exec rails generate solidus:install \ - --auto-accept \ - --user_class=Spree::User \ - --enforce_available_locales=true \ - --with-authentication=<%= file_name != 'solidus_auth_devise' %> \ - --payment-method=none \ - --frontend=${SOLIDUS_FRONTEND} \ - $@ +echo "~~~> Running the solidus:install generator" +with_unbundled_env bin/rails generate solidus:install --auto-accept $@ -unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations -unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations +# If it's already in the bundle we can assume it was installed by solidus:install +(with_unbundled_env bundle list | grep --quiet $extension_name) || ( + echo "~~~> Installing the extension" && + with_unbundled_env bundle add $extension_name --path '..' && + with_unbundled_env ./bin/rails generate "${extension_name}:install" --auto-run-migrations +) echo -echo "๐Ÿš€ Sandbox app successfully created for $extension_name!" -echo "๐Ÿงช This app is intended for test purposes." +echo "~~~> ๐Ÿš€ Sandbox app successfully created for $extension_name!" +echo "~~~> ๐Ÿงช This app is intended for test purposes." diff --git a/solidus_dev_support.gemspec b/solidus_dev_support.gemspec index 0a0e5510..0272c5be 100644 --- a/solidus_dev_support.gemspec +++ b/solidus_dev_support.gemspec @@ -48,6 +48,6 @@ Gem::Specification.new do |spec| spec.add_dependency 'solidus_core', ['>= 2.0', '< 4'] spec.add_dependency 'webdrivers', '>= 4.4' - spec.add_development_dependency 'bundler' + spec.add_development_dependency 'bundler', '>= 2.3.22' spec.add_development_dependency 'rake' end diff --git a/spec/features/create_extension_spec.rb b/spec/features/create_extension_spec.rb index 7a2d1472..f8f0f352 100644 --- a/spec/features/create_extension_spec.rb +++ b/spec/features/create_extension_spec.rb @@ -40,8 +40,7 @@ def step(method_name) def check_solidus_cmd cd(tmp_path) do - output = `#{solidus_cmd} -h` - expect($?).to be_success + output = sh "#{solidus_cmd} -h" expect(output).to include('Commands:') end end @@ -53,8 +52,7 @@ def check_gem_version cd(tmp_path) do gem_version_commands.each do |gem_version_cmd| - output = `#{solidus_cmd} #{gem_version_cmd}` - expect($?).to be_success + output = sh "#{solidus_cmd} #{gem_version_cmd}" expect(output).to include("Solidus version #{solidus_version}") expect(output).to include("Solidus Dev Support version #{gem_version}") end @@ -63,8 +61,7 @@ def check_gem_version def check_create_extension cd(tmp_path) do - output = `#{solidus_cmd} extension #{extension_name}` - expect($?).to be_success + output = sh "#{solidus_cmd} extension #{extension_name}" expect(output).to include(gemspec_name) expect(output).to include('.circleci') end @@ -96,7 +93,7 @@ def check_create_extension def check_bundle_install cd(install_path) do - open('Gemfile', 'a') { |f| f.puts "gem 'solidus_dev_support', path: '../../..'" } + open('Gemfile', 'a') { |f| f.puts "gem 'solidus_dev_support', path: #{gem_root.inspect}" } end expect { bundle_install }.to raise_error(command_failed_error, /invalid gemspec/) @@ -115,7 +112,7 @@ def check_bundle_install def check_default_task cd(install_path) do - output = sh('bin/rake') + output = unbundled_sh('bin/rake') expect(output).to include('Generating dummy Rails application') expect(output).to include('0 examples, 0 failures') end @@ -130,7 +127,7 @@ def check_run_specs "require 'spec_helper'\nRSpec.describe 'Some test' do it { expect(true).to be_truthy } end\n" ) cd(install_path) do - output = sh('bundle exec rspec') + output = unbundled_sh('bundle exec rspec') expect(output).to include('loading test_extension factories') expect(output).to include('1 example, 0 failures') expect(output).to include(ENV['CODECOV_TOKEN'] ? 'Coverage reports upload successfully' : 'Provide a CODECOV_TOKEN environment variable to enable Codecov uploads') @@ -147,7 +144,7 @@ def check_sandbox expect(first_run_output).to include("Creating the sandbox app...") expect(first_run_output).to include('The version of SolidusTestExtension is 0.0.1') - second_run_output = sh(command) + second_run_output = unbundled_sh(command) expect(second_run_output).not_to include("Creating the sandbox app...") expect(second_run_output).to include('The version of SolidusTestExtension is 0.0.1') end @@ -155,9 +152,7 @@ def check_sandbox def sh(*args) command = args.size == 1 ? args.first : args.shelljoin - output, status = with_unbundled_env do - Open3.capture2e({ 'CI' => nil }, command) - end + output, status = Open3.capture2e({ 'CI' => nil }, command) if $DEBUG || ENV['DEBUG'] warn '~' * 80 @@ -173,12 +168,8 @@ def sh(*args) output.to_s end - def with_unbundled_env(&block) - if Bundler.respond_to?(:with_unbundled_env) - Bundler.with_unbundled_env(&block) - else - Bundler.with_clean_env(&block) - end + def unbundled_sh(*args) + Bundler.with_unbundled_env { sh(*args) } end def bundle_install @@ -187,11 +178,11 @@ def bundle_install bundle_path = "#{gem_root}/vendor/bundle" if File.exist?(bundle_path) - sh "bundle config set --local path #{bundle_path.shellescape}" + unbundled_sh "bundle config set --local path #{bundle_path.shellescape}" end output = nil - cd(install_path) { output = sh 'bundle install' } + cd(install_path) { output = unbundled_sh 'bundle install' } output end end