diff --git a/.circleci/config.yml b/.circleci/config.yml index 885969ab06..2c181d52e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,186 +1,107 @@ version: 2.1 defaults: &defaults + parameters: &default_parameters + ruby_image: + type: string + redis_image: + type: string + restore_cache_key_1: + type: string + default: 'spree-bundle-v10-ruby-3-2-{{ .Branch }}' + restore_cache_key_2: + type: string + default: spree-bundle-v10-ruby-3-2 + save_cache_key: + type: string + default: "n" + run_file_path: + type: string + rails_version: + type: string + default: '~> 7.0.0' + store_artefacts: + type: boolean + default: false environment: &environment - CIRCLE_TEST_REPORTS: /tmp/test-results - CIRCLE_ARTIFACTS: /tmp/test-artifacts - BUNDLE_JOBS: 4 - BUNDLE_RETRY: 3 - BUNDLE_PATH: ~/spree/vendor/bundle - RAILS_VERSION: '~> 7.1.0' + CIRCLE_TEST_REPORTS: /tmp/test-results + CIRCLE_ARTIFACTS: /tmp/test-artifacts + BUNDLE_JOBS: 4 + BUNDLE_RETRY: 3 + BUNDLE_PATH: ~/spree/vendor/bundle + RAILS_VERSION: << parameters.rails_version >> working_directory: ~/spree docker: - - image: &ruby_3_0_image circleci/ruby:3.0-node-browsers - - image: &redis_image circleci/redis:6.2-alpine + - image: &ruby_image << parameters.ruby_image >> + - image: &redis_image << parameters.redis_image >> -defaults_3_2: &defaults_3_2 - <<: *defaults - docker: - - image: &ruby_3_2_image cimg/ruby:3.2.0-browsers - - image: *redis_image - -run_tests_3_0: &run_tests_3_0 - <<: *defaults - parallelism: 8 - steps: - - checkout - - restore_cache: - keys: - - spree-dashboard-bundle-v10-ruby-3-0-{{ .Branch }} - - spree-dashboard-bundle-v10-ruby-3-0 - - run: - name: Add keyserver - command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B - - run: - name: Install libvips - command: sudo apt-get update && sudo apt-get install libvips - - run: - name: Set bundle path - command: bundle config --local path vendor/bundle - - run: - name: Ensure bundle Install - command: | - bundle check || bundle install - - run: - name: Create test app - command: | - bundle exec rake test_app - - run: - name: Unlink NPM package - command: | - cd spec/dummy && yarn unlink @spree/dashboard - - run: - name: Run Rspec - command: | - TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) - bundle exec rspec --format documentation \ - --format RspecJunitFormatter \ - -o ~/rspec/rspec.xml \ - -- ${TESTFILES} - - store_test_results: - path: ~/rspec - - store_artifacts: - path: /tmp/test-artifacts - -run_tests_3_2: &run_tests_3_2 - <<: *defaults_3_2 - parallelism: 8 - steps: - - checkout - - restore_cache: - keys: - - spree-dashboard-bundle-v10-ruby-3-2-{{ .Branch }} - - spree-dashboard-bundle-v10-ruby-3-2 - - run: - name: Install libvips - command: sudo apt-get update && sudo apt-get install libvips42 - - run: - name: Set bundle path - command: bundle config --local path vendor/bundle - - run: - name: Ensure bundle Install - command: | - bundle check || bundle install - - run: - name: Create test app - command: | - bundle exec rake test_app - - run: - name: Unlink NPM package - command: | - cd spec/dummy && yarn unlink @spree/dashboard - - run: - name: Run Rspec - command: | - TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) - bundle exec rspec --format documentation \ - --format RspecJunitFormatter \ - -o ~/rspec/rspec.xml \ - -- ${TESTFILES} - - store_test_results: - path: ~/rspec - - store_artifacts: - path: /tmp/test-artifacts jobs: - bundle_ruby_3_0: + run_test: &run_test <<: *defaults - steps: + steps: &default_steps - checkout - restore_cache: keys: - - spree-dashboard-bundle-v10-ruby-3-0-{{ .Branch }} - - spree-dashboard-bundle-v10-ruby-3-0 + - << parameters.restore_cache_key_1 >> + - << parameters.restore_cache_key_2 >> - run: - name: Add keyserver - command: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B + name: Allow executing given file + command: chmod +x << parameters.run_file_path >> - run: - name: Install libvips - command: sudo apt-get update && sudo apt-get install libvips - - run: - name: Set bundle path - command: bundle config --local path vendor/bundle - - run: - name: Bundle Install - command: | - bundle check || bundle install - - save_cache: - paths: - - vendor/bundle - key: spree-dashboard-bundle-v10-ruby-3-0-{{ checksum "Gemfile.lock" }} + name: Run << parameters.run_file_path >> file + command: bash << parameters.run_file_path >> + - when: + condition: << parameters.save_cache_key >> + steps: + - save_cache: + key: << parameters.save_cache_key >> + paths: + - ~/spree/vendor/bundle + - when: + condition: << parameters.store_artefacts >> + steps: + - store_artifacts: + path: /tmp/test-artifacts + destination: test-artifacts + - store_artifacts: + path: /tmp/test-results + destination: raw-test-output + - store_test_results: + path: ~/rspec - bundle_ruby_3_2: - <<: *defaults_3_2 - steps: - - checkout - - restore_cache: - keys: - - spree-dashboard-bundle-v10-ruby-3-2-{{ .Branch }} - - spree-dashboard-bundle-v10-ruby-3-2 - - run: - name: Install libvips - command: sudo apt-get update && sudo apt-get install libvips42 - - run: - name: Set bundle path - command: bundle config --local path vendor/bundle - - run: - name: Bundle Install - command: | - bundle check || bundle install - - save_cache: - paths: - - vendor/bundle - key: spree-dashboard-bundle-v10-ruby-3-2-{{ checksum "Gemfile.lock" }} - - tests_ruby_3_0_rails_7_0_postgres: - <<: *run_tests_3_0 + tests_postgres: + <<: *run_test + parallelism: << parameters.parallelism >> + parameters: + <<: *default_parameters + postgres_image: + type: string + parallelism: + type: integer + default: 8 environment: <<: *environment DB: postgres DB_HOST: localhost DB_USERNAME: postgres - RAILS_VERSION: '~> 7.0.0' docker: - - image: *ruby_3_0_image - - image: &postgres_image circleci/postgres:12-alpine + - image: *ruby_image + - image: << parameters.postgres_image >> environment: POSTGRES_USER: postgres - image: *redis_image - tests_ruby_3_2_rails_7_1_postgres: - <<: *run_tests_3_2 - environment: - <<: *environment - DB: postgres - DB_HOST: localhost - DB_USERNAME: postgres - docker: - - image: *ruby_3_2_image - - image: *postgres_image - - image: *redis_image - - tests_ruby_3_2_rails_7_1_mysql: - <<: *run_tests_3_2 + tests_mysql: + <<: *run_test + parallelism: << parameters.parallelism >> + parameters: + <<: *default_parameters + mysql_image: + type: string + parallelism: + type: integer + default: 8 environment: <<: *environment DB: mysql @@ -189,22 +110,71 @@ jobs: COVERAGE: true COVERAGE_DIR: /tmp/workspace/simplecov docker: - - image: *ruby_3_2_image + - image: *ruby_image - image: *redis_image - - image: &mysql_image circleci/mysql:8-ram + - image: << parameters.mysql_image >> + command: [--default-authentication-plugin=mysql_native_password] + + send_test_coverage: + <<: *defaults + steps: + - checkout + - attach_workspace: + at: /tmp/workspace + - run: + name: Allow executing given file + command: chmod +x << parameters.run_file_path >> + - run: + name: Send test coverage + command: bash << parameters.run_file_path >> + workflows: version: 2 main: jobs: - - bundle_ruby_3_0 - - bundle_ruby_3_2 - - tests_ruby_3_2_rails_7_1_postgres: + - run_test: + name: bundle_ruby_3_0 + restore_cache_key_1: "spree-dashboard-bundle-v10-ruby-3-0-{{ .Branch }}" + restore_cache_key_2: "spree-dashboard-bundle-v10-ruby-3-0" + ruby_image: circleci/ruby:3.0-node-browsers + redis_image: circleci/redis:6.2-alpine + run_file_path: ./bin/bundle_ruby_3_0.sh + save_cache_key: spree-dashboard-bundle-v10-ruby-3-0-{{ checksum "Gemfile.lock" }} + - run_test: + name: bundle_ruby_3_2 + ruby_image: cimg/ruby:3.2.0-browsers + redis_image: circleci/redis:6.2-alpine + run_file_path: ./bin/bundle_ruby.sh + save_cache_key: spree-dashboard-bundle-v10-ruby-3-2-{{ checksum "Gemfile.lock" }} + - tests_postgres: + name: tests_ruby_3_2_rails_7_1_postgres + rails_version: '~> 7.1.0' + ruby_image: cimg/ruby:3.2.0-browsers + redis_image: circleci/redis:6.2-alpine + postgres_image: circleci/postgres:12-alpine + store_artefacts: true + run_file_path: ./bin/tests_database_ci.sh requires: - - bundle_ruby_3_2 - - tests_ruby_3_0_rails_7_0_postgres: + - bundle_ruby_3_2 + - tests_postgres: + name: tests_ruby_3_0_rails_7_0_postgres + rails_version: '~> 7.0.0' + ruby_image: circleci/ruby:3.0-node-browsers + redis_image: circleci/redis:6.2-alpine + postgres_image: circleci/postgres:12-alpine + store_artefacts: true + run_file_path: ./bin/tests_database_ci.sh requires: - - bundle_ruby_3_0 - - tests_ruby_3_2_rails_7_1_mysql: + - bundle_ruby_3_0 + - tests_mysql: + name: tests_ruby_3_2_rails_7_1_mysql + rails_version: '~> 7.1.0' + ruby_image: cimg/ruby:3.2.0-browsers + redis_image: circleci/redis:6.2-alpine + mysql_image: circleci/mysql:8-ram + store_artefacts: true + run_file_path: ./bin/tests_database_ci.sh requires: - - bundle_ruby_3_2 + - bundle_ruby_3_2 + diff --git a/bin/bundle_ruby.sh b/bin/bundle_ruby.sh new file mode 100644 index 0000000000..2539cdeb07 --- /dev/null +++ b/bin/bundle_ruby.sh @@ -0,0 +1,3 @@ +sudo apt-get update && sudo apt-get install libvips42 +bundle config --local path vendor/bundle +bundle check || bundle install \ No newline at end of file diff --git a/bin/bundle_ruby_3_0.sh b/bin/bundle_ruby_3_0.sh new file mode 100644 index 0000000000..15d0dfcbd4 --- /dev/null +++ b/bin/bundle_ruby_3_0.sh @@ -0,0 +1,4 @@ +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B +sudo apt-get update && sudo apt-get install libvips +bundle config --local path vendor/bundle +bundle check || bundle install \ No newline at end of file diff --git a/bin/tests_database_ci.sh b/bin/tests_database_ci.sh new file mode 100644 index 0000000000..e5861ba6ae --- /dev/null +++ b/bin/tests_database_ci.sh @@ -0,0 +1,10 @@ +sudo apt-get update && sudo apt-get install libvips42 +bundle config --local path vendor/bundle +bundle check || bundle install +bundle exec rake test_app +cd spec/dummy && yarn unlink @spree/dashboard && cd ../.. +TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) + bundle exec rspec --format documentation \ + --format RspecJunitFormatter \ + -o ~/rspec/rspec.xml \ + -- ${TESTFILES}