version: 2.1 commands: setup_knapsack_pro_ruby: steps: - checkout - restore_cache: keys: - v1-bundler-ruby-{{ checksum "knapsack_pro.gemspec" }} - v1-bundler-ruby- - run: command: | bundle config set --local path './vendor/bundle' bundle install --jobs=4 --retry=3 - save_cache: paths: - ./vendor/bundle key: v1-bundler-ruby-{{ checksum "knapsack_pro.gemspec" }} setup_rails_app_with_knapsack_pro: parameters: path: type: string ruby: type: string rspec: type: string default: "" steps: - run: working_directory: << parameters.path >> command: | git clone --depth 1 --branch $CIRCLE_BRANCH --single-branch git@github.com:KnapsackPro/rails-app-with-knapsack_pro.git ./ || git clone --depth 1 git@github.com:KnapsackPro/rails-app-with-knapsack_pro.git ./ if [[ "<< parameters.rspec >>" != "" ]]; then sed -i 's/.*gem.*rspec-core.*/gem "rspec-core", "<< parameters.rspec >>"/g' ./Gemfile echo "Updated RSpec version in Gemfile" fi - restore_cache: keys: - v1-bundler-rails-{{ checksum "Gemfile.lock" }}-ruby-<< parameters.ruby >>-rspec-<< parameters.rspec >> - v1-bundler-rails-{{ checksum "Gemfile.lock" }}-ruby-<< parameters.ruby >>- - v1-bundler-rails-{{ checksum "Gemfile.lock" }}- - v1-bundler-rails- - run: working_directory: << parameters.path >> command: | bundle config set --local path './vendor/bundle' bundle install --jobs=4 --retry=3 - save_cache: paths: - << parameters.path >>/vendor/bundle key: v1-bundler-rails-{{ checksum "Gemfile.lock" }}-ruby-<< parameters.ruby >>-rspec-<< parameters.rspec >> jobs: unit: parallelism: 1 working_directory: ~/knapsack_pro-ruby resource_class: small docker: - image: cimg/ruby:3.3 steps: - setup_knapsack_pro_ruby - run: gem install rubocop - run: rubocop --fail-level A --only Style/FrozenStringLiteralComment,Layout/EmptyLineAfterMagicComment lib/ - run: bundle exec rspec spec - run: bundle exec ruby spec/knapsack_pro/formatters/time_tracker_specs.rb integration-rspec: parallelism: 1 working_directory: ~/knapsack_pro-ruby resource_class: small parameters: ruby: type: string rspec: type: string docker: - image: cimg/ruby:<< parameters.ruby >> steps: - checkout - run: command: | if [[ "<< parameters.rspec >>" != "" ]]; then sed -i 's/.*gem.*rspec-core.*/gem "rspec-core", "<< parameters.rspec >>"/g' ./Gemfile echo "Updated RSpec version in Gemfile" fi - restore_cache: keys: - v1-bundler-gem-{{ checksum "knapsack_pro.gemspec" }}-ruby-<< parameters.ruby >>-rspec-<< parameters.rspec >> - v1-bundler-gem-{{ checksum "knapsack_pro.gemspec" }}-ruby-<< parameters.ruby >>- - v1-bundler-gem-{{ checksum "knapsack_pro.gemspec" }}- - v1-bundler-gem- - run: command: | bundle config set --local path './vendor/bundle' bundle install --jobs=4 --retry=3 - save_cache: paths: - ./vendor/bundle key: v1-bundler-gem-{{ checksum "knapsack_pro.gemspec" }}-ruby-<< parameters.ruby >>-rspec-<< parameters.rspec >> - run: command: | ruby --version bundle exec rspec --version RSPEC=$(bundle exec rspec --version | grep rspec-core | head -n1 | cut -d " " -f5) [ $RSPEC != << parameters.rspec >> ] && exit 1 || echo "Correct version of RSpec installed: $RSPEC" - run: bundle exec rspec spec/integration/runners/queue/rspec_runner_spec.rb e2e-regular-rspec: parallelism: 2 working_directory: ~/knapsack_pro-ruby resource_class: small parameters: ruby: type: string rspec: type: string docker: - image: cimg/ruby:<< parameters.ruby >>-browsers environment: PGHOST: 127.0.0.1 PGUSER: rails-app-with-knapsack_pro RAILS_ENV: test RACK_ENV: test KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: $KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC EXTRA_TEST_FILES_DELAY: 10 - image: cimg/postgres:14.7 environment: POSTGRES_DB: rails-app-with-knapsack_pro_test POSTGRES_PASSWORD: password POSTGRES_USER: rails-app-with-knapsack_pro steps: - setup_knapsack_pro_ruby - setup_rails_app_with_knapsack_pro: path: ~/rails-app-with-knapsack_pro ruby: << parameters.ruby >> rspec: << parameters.rspec >> - run: dockerize -wait tcp://localhost:5432 -timeout 1m - run: working_directory: ~/rails-app-with-knapsack_pro command: | ruby --version bundle exec rspec --version RSPEC=$(bundle exec rspec --version | grep rspec-core | head -n1 | cut -d " " -f5) [ $RSPEC != << parameters.rspec >> ] && exit 1 || echo "Correct version of RSpec installed: $RSPEC" - run: working_directory: ~/rails-app-with-knapsack_pro command: bin/rails db:setup - run: working_directory: ~/rails-app-with-knapsack_pro command: | export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular" bundle exec rake knapsack_pro:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # retry the same split || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular" bundle exec rake knapsack_pro:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # fallback || export KNAPSACK_PRO_ENDPOINT=https://api-fake.knapsackpro.com export KNAPSACK_PRO_MAX_REQUEST_RETRIES=1 bundle exec rake knapsack_pro:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # ensures KnapsackPro::Formatters::TimeTracker works when the .rspec file does not exist export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular--no-dot-rspec-file" mv .rspec .rspec.off # load test files that require spec_helper explicitly export KNAPSACK_PRO_TEST_FILE_PATTERN="{spec/time_tracker_spec.rb}" bundle exec rake knapsack_pro:rspec RSPEC_EXIT_CODE=$? mv .rspec.off .rspec exit $RSPEC_EXIT_CODE - run: working_directory: ~/rails-app-with-knapsack_pro command: | # split by test examples || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular--split" export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true bundle exec rake knapsack_pro:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # split custom files by test examples || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular--split-custom-files" export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true export KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN="spec/features/calculator_spec.rb" bundle exec rake knapsack_pro:rspec e2e-queue-rspec: parameters: ruby: type: string rspec: type: string parallelism: 2 working_directory: ~/knapsack_pro-ruby resource_class: small docker: - image: cimg/ruby:<< parameters.ruby >>-browsers environment: PGHOST: 127.0.0.1 PGUSER: rails-app-with-knapsack_pro RAILS_ENV: test RACK_ENV: test KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: $KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC EXTRA_TEST_FILES_DELAY: 10 - image: cimg/postgres:14.7 environment: POSTGRES_DB: rails-app-with-knapsack_pro_test POSTGRES_PASSWORD: password POSTGRES_USER: rails-app-with-knapsack_pro steps: - setup_knapsack_pro_ruby - setup_rails_app_with_knapsack_pro: path: ~/rails-app-with-knapsack_pro ruby: << parameters.ruby >> rspec: << parameters.rspec >> - run: dockerize -wait tcp://localhost:5432 -timeout 1m - run: working_directory: ~/rails-app-with-knapsack_pro command: | ruby --version bundle exec rspec --version RSPEC=$(bundle exec rspec --version | grep rspec-core | head -n1 | cut -d " " -f5) [ $RSPEC != << parameters.rspec >> ] && exit 1 || echo "Correct version of RSpec installed: $RSPEC" - run: working_directory: ~/rails-app-with-knapsack_pro command: bin/rails db:setup - run: working_directory: ~/rails-app-with-knapsack_pro command: | export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue" bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # run 0 tests as queue is consumed || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # retry the same split || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # fallback || export KNAPSACK_PRO_ENDPOINT=https://api-fake.knapsackpro.com export KNAPSACK_PRO_MAX_REQUEST_RETRIES=1 bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # split by test examples || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--split" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # split by test examples above the slow test file threshold || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--split-above-slow-test-file-threshold" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true export KNAPSACK_PRO_SLOW_TEST_FILE_THRESHOLD=1 bundle exec rake knapsack_pro:queue:rspec - run: working_directory: ~/rails-app-with-knapsack_pro command: | # turnip || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--turnip" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true export KNAPSACK_PRO_TEST_DIR=turnip export KNAPSACK_PRO_TEST_FILE_PATTERN="turnip/**/*.feature" bundle exec rake "knapsack_pro:queue:rspec[-r turnip/rspec]" - run: working_directory: ~/rails-app-with-knapsack_pro command: | # turnip retry || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--turnip" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true export KNAPSACK_PRO_TEST_DIR=turnip export KNAPSACK_PRO_TEST_FILE_PATTERN="turnip/**/*.feature" bundle exec rake "knapsack_pro:queue:rspec[-r turnip/rspec]" e2e-regular-minitest: parallelism: 2 working_directory: ~/knapsack_pro-ruby resource_class: small parameters: ruby: type: string docker: - image: cimg/ruby:<< parameters.ruby >>-browsers environment: PGHOST: 127.0.0.1 PGUSER: rails-app-with-knapsack_pro RAILS_ENV: test RACK_ENV: test KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: $KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST KNAPSACK_PRO_RSPEC_DISABLED: true EXTRA_TEST_FILES_DELAY: 10 - image: cimg/postgres:14.7 environment: POSTGRES_DB: rails-app-with-knapsack_pro_test POSTGRES_PASSWORD: password POSTGRES_USER: rails-app-with-knapsack_pro steps: - setup_knapsack_pro_ruby - setup_rails_app_with_knapsack_pro: path: ~/rails-app-with-knapsack_pro ruby: << parameters.ruby >> - run: dockerize -wait tcp://localhost:5432 -timeout 1m - run: working_directory: ~/rails-app-with-knapsack_pro command: ruby --version - run: working_directory: ~/rails-app-with-knapsack_pro command: bin/rails db:setup - run: working_directory: ~/rails-app-with-knapsack_pro command: | export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular" bundle exec rake knapsack_pro:minitest[--verbose] - run: working_directory: ~/rails-app-with-knapsack_pro command: | # retry the same split || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--regular" bundle exec rake knapsack_pro:minitest[--verbose] e2e-queue-minitest: parameters: ruby: type: string parallelism: 2 working_directory: ~/knapsack_pro-ruby resource_class: small docker: - image: cimg/ruby:<< parameters.ruby >>-browsers environment: PGHOST: 127.0.0.1 PGUSER: rails-app-with-knapsack_pro RAILS_ENV: test RACK_ENV: test KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: $KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST KNAPSACK_PRO_RSPEC_DISABLED: true EXTRA_TEST_FILES_DELAY: 10 - image: cimg/postgres:14.7 environment: POSTGRES_DB: rails-app-with-knapsack_pro_test POSTGRES_PASSWORD: password POSTGRES_USER: rails-app-with-knapsack_pro steps: - setup_knapsack_pro_ruby - setup_rails_app_with_knapsack_pro: path: ~/rails-app-with-knapsack_pro ruby: << parameters.ruby >> - run: dockerize -wait tcp://localhost:5432 -timeout 1m - run: working_directory: ~/rails-app-with-knapsack_pro command: ruby --version - run: working_directory: ~/rails-app-with-knapsack_pro command: bin/rails db:setup - run: working_directory: ~/rails-app-with-knapsack_pro command: | # minitest || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--minitest" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true bundle exec rake knapsack_pro:queue:minitest[--verbose] - run: working_directory: ~/rails-app-with-knapsack_pro command: | # minitest retry || export KNAPSACK_PRO_BRANCH="$CIRCLE_BRANCH--$CIRCLE_BUILD_NUM--queue--minitest" export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true bundle exec rake knapsack_pro:queue:minitest[--verbose] workflows: tests: jobs: - unit - integration-rspec: name: integration__ruby-<< matrix.ruby >>__rspec-<< matrix.rspec >> matrix: parameters: ruby: ["3.0", "3.1", "3.2", "3.3"] rspec: ["3.10.2", "3.11.0", "3.12.2"] - e2e-regular-rspec: name: e2e-regular__ruby-<< matrix.ruby >>__rspec-<< matrix.rspec >> matrix: parameters: ruby: ["3.0", "3.1", "3.2", "3.3"] rspec: ["3.10.2", "3.11.0", "3.12.2"] - e2e-queue-rspec: name: e2e-queue__ruby-<< matrix.ruby >>__rspec-<< matrix.rspec >> matrix: parameters: ruby: ["3.0", "3.1", "3.2", "3.3"] rspec: ["3.10.2", "3.11.0", "3.12.2"] - e2e-regular-minitest: name: e2e-regular__ruby-<< matrix.ruby >>__minitest matrix: parameters: ruby: ["3.0", "3.1", "3.2", "3.3"] - e2e-queue-minitest: name: e2e-queue__ruby-<< matrix.ruby >>__minitest matrix: parameters: ruby: ["3.0", "3.1", "3.2", "3.3"]