From 398962d75c136f5bf7436101463ce8460245941d Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 10 Oct 2022 19:06:21 +0200 Subject: [PATCH 01/10] Setup dummy app ENV vars before requiring core support files --- lib/solidus_dev_support/rake_tasks.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/solidus_dev_support/rake_tasks.rb b/lib/solidus_dev_support/rake_tasks.rb index c24e04b8..5889d0ec 100644 --- a/lib/solidus_dev_support/rake_tasks.rb +++ b/lib/solidus_dev_support/rake_tasks.rb @@ -27,12 +27,12 @@ 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 + require 'rake/clean' + require 'spree/testing_support/extension_rake' + ::CLOBBER.include test_app_path namespace :extension do From b4197c2f7af77f46e4b370121e21334cff44a8a0 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 10 Oct 2022 19:05:58 +0200 Subject: [PATCH 02/10] Streamline the proposed CircleCI configuration - only install chrome, which is the default driver - stop using sqlite-memory - add a sqlite based job - test against different ruby version (with minimal redundancy) --- .../templates/extension/.circleci/config.yml | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) 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 From 4153af56eae61efbf64b918543d4d132883c1f6f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 9 Sep 2022 13:49:09 +0200 Subject: [PATCH 03/10] Streamline bin/sandbox - shadow the bundle command and make it run "with unbundled env" - shed support for the legacy `with_clean_env` - use local bundle config instead of the deprecated inline flags - generalize support for extensions installed by `solidus:install` - thinner layer between env variables and `rails new` options - mark the main operation to ease debugging issues --- .../templates/extension/bin/sandbox.tt | 81 +++++++++---------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index 00f421d6..0d36ff16 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -1,34 +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 bundle { + ruby -rbundler -e'Bundler.with_unbundled_env { system "bundle", *ARGV }' -- $@ } +echo "~~~> Removing the old sandbox" rm -rf ./sandbox -unbundled bundle exec rails new sandbox \ - --database="${DB:-sqlite3}" \ + +echo "~~~> Creating a pristine Rails app" +rails new sandbox \ + --database="$DB" \ --skip-bundle \ --skip-git \ --skip-keeps \ @@ -43,36 +40,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" +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" +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 +(bundle list | grep --quiet $extension_name) || ( + echo "~~~> Installing the extension" && + bundle add $extension_name && + ./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." From f5119d096e2098dc63c958423597c3f3910686cf Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 11:42:08 +0200 Subject: [PATCH 04/10] Support for Bundler.with_unbundled_env is now common --- spec/features/create_extension_spec.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/spec/features/create_extension_spec.rb b/spec/features/create_extension_spec.rb index 7a2d1472..19e2b80d 100644 --- a/spec/features/create_extension_spec.rb +++ b/spec/features/create_extension_spec.rb @@ -155,7 +155,7 @@ def check_sandbox def sh(*args) command = args.size == 1 ? args.first : args.shelljoin - output, status = with_unbundled_env do + output, status = Bundler.with_unbundled_env do Open3.capture2e({ 'CI' => nil }, command) end @@ -173,14 +173,6 @@ 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 - end - def bundle_install # Optimize the bundle path within the CI, in this context using bundler env # variables doesn't help because commands are run with a clean env. From 9943690ebab04c2cbf80662da2ac73a589595f76 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 11:42:46 +0200 Subject: [PATCH 05/10] Use the #sh helper in the spec to add debugging support --- spec/features/create_extension_spec.rb | 29 +++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/spec/features/create_extension_spec.rb b/spec/features/create_extension_spec.rb index 19e2b80d..ff31ca4b 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 @@ -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') @@ -143,11 +140,11 @@ def check_sandbox command = 'bin/rails-sandbox runner "puts %{The version of SolidusTestExtension is #{SolidusTestExtension::VERSION}}"' # rubocop:enable Lint/InterpolationCheck - first_run_output = sh(command) + first_run_output = unbundled_sh(command) 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 = Bundler.with_unbundled_env do - Open3.capture2e({ 'CI' => nil }, command) - end + output, status = Open3.capture2e({ 'CI' => nil }, command) if $DEBUG || ENV['DEBUG'] warn '~' * 80 @@ -173,17 +168,21 @@ def sh(*args) output.to_s end + def unbundled_sh(*args) + Bundler.with_unbundled_env { sh(*args) } + end + def bundle_install # Optimize the bundle path within the CI, in this context using bundler env # variables doesn't help because commands are run with a clean env. 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 From 0d482521ca7aaa6590dd723444462bf17ee4193d Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 12:07:54 +0200 Subject: [PATCH 06/10] Initialize the extension dir with git --- lib/solidus_dev_support/extension.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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" From f92a4ac2fc4b640218860f02b0371ecacf72c9ec Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 12:09:00 +0200 Subject: [PATCH 07/10] Use `bundle add --path` to setup the sandbox Require a version of bundler that supports `--path` in the `add` command. --- lib/solidus_dev_support/templates/extension/bin/sandbox.tt | 2 +- solidus_dev_support.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index 0d36ff16..38816d5b 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -60,7 +60,7 @@ bin/rails generate solidus:install --auto-accept $@ # If it's already in the bundle we can assume it was installed by solidus:install (bundle list | grep --quiet $extension_name) || ( echo "~~~> Installing the extension" && - bundle add $extension_name && + bundle add $extension_name --path '..' && ./bin/rails generate "${extension_name}:install" --auto-run-migrations ) 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 From d0095f765ef2ab85540c35a001ea119570223e87 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 12:38:37 +0200 Subject: [PATCH 08/10] Use an absolute path when adding dev-support to the gemfile --- spec/features/create_extension_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/create_extension_spec.rb b/spec/features/create_extension_spec.rb index ff31ca4b..b79e940c 100644 --- a/spec/features/create_extension_spec.rb +++ b/spec/features/create_extension_spec.rb @@ -93,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/) From cf334f47e2c91d89be5c7bee1d39d77a35b9199a Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 11 Oct 2022 18:19:50 +0200 Subject: [PATCH 09/10] Skip solidus_bolt when creating the dummy app We need to skip solidus bolt for Solidus v3.2, otherwise it will try to install it when creating the dummy app. --- lib/solidus_dev_support/rake_tasks.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/solidus_dev_support/rake_tasks.rb b/lib/solidus_dev_support/rake_tasks.rb index 5889d0ec..a93d086e 100644 --- a/lib/solidus_dev_support/rake_tasks.rb +++ b/lib/solidus_dev_support/rake_tasks.rb @@ -30,6 +30,10 @@ def install_test_app_task 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' From f7c8fbde5bfbfe58f5af58153d8372ef325e2b6b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 17 Oct 2022 14:09:11 +0200 Subject: [PATCH 10/10] elia/updates: [wip] --- .../templates/extension/bin/sandbox.tt | 17 ++++++++--------- spec/features/create_extension_spec.rb | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt index 38816d5b..c43e2b4c 100755 --- a/lib/solidus_dev_support/templates/extension/bin/sandbox.tt +++ b/lib/solidus_dev_support/templates/extension/bin/sandbox.tt @@ -16,17 +16,16 @@ echo '~~~> Using branch $SOLIDUS_BRANCH of solidus' # Override bundle in order to stay away from the # bundler env of the containing extension. -function bundle { - ruby -rbundler -e'Bundler.with_unbundled_env { system "bundle", *ARGV }' -- $@ +function with_unbundled_env { + ruby -rbundler -e'Bundler.with_unbundled_env { system *ARGV }' -- $@ } echo "~~~> Removing the old sandbox" rm -rf ./sandbox echo "~~~> Creating a pristine Rails app" -rails new sandbox \ +with_unbundled_env rails new sandbox \ --database="$DB" \ - --skip-bundle \ --skip-git \ --skip-keeps \ --skip-rc \ @@ -52,16 +51,16 @@ RUBY bundle config local.$extension_name "$PWD/.." bundle config gemfile "$PWD/Gemfile" -bundle install +with_unbundled_env bundle install echo "~~~> Running the solidus:install generator" -bin/rails generate solidus:install --auto-accept $@ +with_unbundled_env bin/rails generate solidus:install --auto-accept $@ # If it's already in the bundle we can assume it was installed by solidus:install -(bundle list | grep --quiet $extension_name) || ( +(with_unbundled_env bundle list | grep --quiet $extension_name) || ( echo "~~~> Installing the extension" && - bundle add $extension_name --path '..' && - ./bin/rails generate "${extension_name}:install" --auto-run-migrations + with_unbundled_env bundle add $extension_name --path '..' && + with_unbundled_env ./bin/rails generate "${extension_name}:install" --auto-run-migrations ) echo diff --git a/spec/features/create_extension_spec.rb b/spec/features/create_extension_spec.rb index b79e940c..f8f0f352 100644 --- a/spec/features/create_extension_spec.rb +++ b/spec/features/create_extension_spec.rb @@ -140,7 +140,7 @@ def check_sandbox command = 'bin/rails-sandbox runner "puts %{The version of SolidusTestExtension is #{SolidusTestExtension::VERSION}}"' # rubocop:enable Lint/InterpolationCheck - first_run_output = unbundled_sh(command) + first_run_output = sh(command) expect(first_run_output).to include("Creating the sandbox app...") expect(first_run_output).to include('The version of SolidusTestExtension is 0.0.1')