Skip to content

Commit

Permalink
ci: use circleci 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Dec 19, 2023
1 parent f4632d4 commit 9309c7f
Showing 1 changed file with 50 additions and 72 deletions.
122 changes: 50 additions & 72 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
version: 2.1

jobs:
build:
parallelism: 2
working_directory: ~/repo
docker:
# specify the version you desire here
# https://circleci.com/developer/images/image/cimg/ruby
- image: cimg/ruby:3.2.2-browsers
- image: cimg/ruby:3.2-browsers
environment:
PGHOST: 127.0.0.1
PGUSER: rails-app-with-knapsack_pro
RAILS_ENV: test
RACK_ENV: test
KNAPSACK_PRO_REPO_PATH: ~/gems/knapsack_pro-ruby

# In production you should use endpoint https://api.knapsackpro.com
# which is default so it means you don't need to set KNAPSACK_PRO_ENDPOINT
# Below endpoint is just for internal tests by KnapsackPro developers.
# You can ignore this ENV variable: it's for internal testing by Knapsack Pro devs.
KNAPSACK_PRO_REPO_PATH: ~/knapsack_pro-ruby
# You can ignore this ENV variable: it's for internal testing by Knapsack Pro devs.
KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com

# Tokens are set in CircleCI settings so you can't read them from this file.
Expand All @@ -28,85 +22,74 @@ jobs:
# KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: minitest-token
# KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH: spinach-token

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/postgres:13.3-ram
- image: cimg/postgres:16.1
environment:
POSTGRES_DB: rails-app-with-knapsack_pro_test
POSTGRES_PASSWORD: "password"
POSTGRES_PASSWORD: password
POSTGRES_USER: rails-app-with-knapsack_pro

working_directory: ~/repo

steps:
- checkout
- run:
working_directory: ~/knapsack_pro-ruby
command: git clone --depth 1 --branch $CIRCLE_BRANCH --single-branch [email protected]:KnapsackPro/knapsack_pro-ruby.git ./ || git clone --depth 1 [email protected]:KnapsackPro/knapsack_pro-ruby.git ./

- run: mkdir ~/gems
- run: cd ~/gems && (git clone -b $CIRCLE_BRANCH --single-branch [email protected]:KnapsackPro/knapsack_pro-ruby.git || git clone -b master --single-branch [email protected]:KnapsackPro/knapsack_pro-ruby.git)
- run: cd ~/gems/knapsack_pro-ruby && git branch
- run:
working_directory: ~/knapsack_pro-ruby
command: git branch
- run:
name: Show last commit
command: |
cd ~/gems/knapsack_pro-ruby
git log -n 1 --pretty=oneline
working_directory: ~/knapsack_pro-ruby
command: git log -n 1 --pretty=oneline
- run: mkdir -p tmp/test-reports/rspec/regular_mode/
- run: mkdir -p tmp/test-reports/rspec/queue_mode/
- run: mkdir -p tmp/test-reports/cucumber/regular_mode/
- run: mkdir -p tmp/test-reports/cucumber/queue_mode/

- run:
name: Install Code Climate Test Reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- run: ./cc-test-reporter before-build

# Download and cache dependencies
- restore_cache:
keys:
- v2-dependencies-bundler-{{ checksum "Gemfile.lock" }}
# fallback to using the latest cache if no exact match is found
- v2-dependencies-bundler-

- run:
name: install ruby dependencies
command: |
bundle install --jobs=4 --retry=3 --path vendor/bundle
bundle config set --local path './vendor/bundle'
bundle install --jobs=4 --retry=3
- save_cache:
paths:
- ./vendor/bundle
key: v2-dependencies-bundler-{{ checksum "Gemfile.lock" }}

# wait for postgres to be available
- run: dockerize -wait tcp://localhost:5432 -timeout 1m
# Database setup
- run:
name: Wait for postgres to be available
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run: bin/rails db:setup
# Database setup for parallel_tests gem
- run: TEST_ENV_NUMBER=2 bin/rails db:setup
- run:
name: Database setup for parallel_tests gem
command: TEST_ENV_NUMBER=2 bin/rails db:setup

# run tests!
# Queue mode
# We run queue tests first because test suite is small so we want to CI nodes
# to start at the same time so they will use the same queue
# Run tests with Knapsack Pro!
#
# Queue Mode
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:queue:rspec

# Queue mode retry CI with the same test suite split as last dynamic queue run
# Test --profile formatter to show only once the profile summary.
# Queue Mode: retry CI with the same test suite split as the last dynamic queue run.
# (Test --profile formatter to show only once the profile summary.)
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake "knapsack_pro:queue:rspec[--profile]"

# Queue Mode - retry the CI build with the same test suite split as the last knapsack_pro command execution for this CI build
# add the RSpec order option to ensure we print a seed in the log output
# Queue Mode: retry CI with the same test suite split as the last dynamic queue run.
# (Add the RSpec order option to ensure we print a seed in the log output.)
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake "knapsack_pro:queue:rspec[--order random]"

# Queue mode with junit formatter
# Retry CI with the same test suite split as last dynamic queue run
# The rspec.xml will have tests from all intermediate requests to API.
# Queue Mode: retry CI with the same test suite split as the last dynamic queue run with junit formatter.
# (The rspec.xml file will have tests from all intermediate requests to API.)
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake "knapsack_pro:queue:rspec[--format documentation --format RspecJunitFormatter --out tmp/test-reports/rspec/queue_mode/rspec.xml]"

- run:
name: import JUnit XML reports to Calliope.pro for RSpec in Knapsack Pro Queue Mode
name: Import JUnit XML reports to Calliope.pro for RSpec in Knapsack Pro Queue Mode
command: |
report_dir=tmp/test-reports/rspec/queue_mode/
if [ -d $report_dir ] && [ `ls $report_dir | wc -l` -gt 0 ]; then
Expand All @@ -119,16 +102,16 @@ jobs:
echo "Report files not found. Nothing to import to Calliope.pro"
fi
# Queue mode retry CI with the same test suite split as last dynamic queue run
# Queue Mode: retry CI with the same test suite split as the last dynamic queue run.
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:queue:rspec

# Second run should not allow to initialize a new queue for the same CI build ID
# Queue Mode: connect to a queue of tests that was already all consumed (no tests will run).
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:queue:rspec

# parallel_tests gem and knapsack_pro in Queue Mode
# Queue Mode and parallel_tests gem
- run: export PARALLEL_TESTS_CONCURRENCY=2; KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC KNAPSACK_PRO_CI_NODE_TOTAL=$CIRCLE_NODE_TOTAL KNAPSACK_PRO_CI_NODE_INDEX=$CIRCLE_NODE_INDEX bundle exec parallel_test -n $PARALLEL_TESTS_CONCURRENCY -e './bin/parallel_tests'

# Queue Mode - RSpec split by test examples
# Queue Mode: RSpec split by test examples
- run:
name: RSpec split by test cases (Queue Mode)
command: |
Expand All @@ -137,24 +120,24 @@ jobs:
bundle exec rake knapsack_pro:queue:rspec
- run:
name: RSpec split by test cases (Regular Mode), use KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN
name: RSpec split by test cases (Regular Mode) with KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN
command: |
export KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC_SPLIT_BY_TEST_CASES
export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true
export KNAPSACK_PRO_SLOW_TEST_FILE_PATTERN="{spec/timecop_spec.rb}"
bundle exec rake knapsack_pro:rspec
# Queue Mode Minitest
# Queue Mode: Minitest
- run: KNAPSACK_PRO_RSPEC_DISABLED=true KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_MINITEST bundle exec rake knapsack_pro:queue:minitest[--verbose]


# Regular mode
# Regular Mode
- run: KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false bundle exec rake knapsack_pro:rspec

# Regular mode with junit formatter
# Regular Mode with junit formatter
- run: KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false bundle exec rake "knapsack_pro:rspec[--format documentation --format RspecJunitFormatter --out tmp/test-reports/rspec/regular_mode/rspec.xml]"

# Regular mode with custom test_dir
# Regular mode With custom test_dir
- run: KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false KNAPSACK_PRO_TEST_DIR=spec KNAPSACK_PRO_TEST_FILE_PATTERN="{spec,engines/*/spec}/**/*_spec.rb" bundle exec rake knapsack_pro:rspec

- run: bundle exec rake knapsack_pro:cucumber
Expand All @@ -164,7 +147,7 @@ jobs:
- run: bundle exec rake "knapsack_pro:cucumber[--format junit --out tmp/test-reports/cucumber/regular_mode]"

- run:
name: import JUnit XML report to Calliope.pro for Cucumber in Knapsack Pro Regular Mode
name: Import JUnit XML report to Calliope.pro for Cucumber in Knapsack Pro Regular Mode
command: |
# ensure there is / at the end of a directory name
report_dir=tmp/test-reports/cucumber/regular_mode/
Expand All @@ -191,7 +174,7 @@ jobs:
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_CUCUMBER bundle exec rake "knapsack_pro:queue:cucumber[--format junit --out tmp/test-reports/cucumber/queue_mode/]"

- run:
name: import JUnit XML reports to Calliope.pro for Cucumber in Knapsack Pro Queue Mode
name: Import JUnit XML reports to Calliope.pro for Cucumber in Knapsack Pro Queue Mode
command: |
# ensure there is / at the end of a directory name
report_dir=tmp/test-reports/cucumber/queue_mode/
Expand Down Expand Up @@ -229,11 +212,10 @@ jobs:
# KNAPSACK_PRO_SALT is set in CircleCI settings
- run: KNAPSACK_PRO_TEST_FILES_ENCRYPTED=true KNAPSACK_PRO_BRANCH_ENCRYPTED=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:rspec

# Queue mode with encrypted test files names
# Queue Mode with encrypted test files names
- run: KNAPSACK_PRO_TEST_FILES_ENCRYPTED=true KNAPSACK_PRO_BRANCH_ENCRYPTED=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:queue:rspec

# Queue mode retry CI with the same test suite split as last dynamic queue run
# with encrypted test files names
# Queue Mode: retry CI with the same test suite split as the last dynamic queue run with encrypted test files names.
- run: KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true KNAPSACK_PRO_TEST_FILES_ENCRYPTED=true KNAPSACK_PRO_BRANCH_ENCRYPTED=true KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:queue:rspec

# Fallback when cannot connect to API
Expand All @@ -259,7 +241,6 @@ jobs:
name: Code Climate Test Coverage
command: |
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
- persist_to_workspace:
root: coverage
paths:
Expand All @@ -270,12 +251,11 @@ jobs:
path: tmp/test-reports

upload-coverage:
working_directory: ~/repo
docker:
- image: cimg/ruby:3.2.2-browsers
- image: cimg/ruby:3.2-browsers
environment:
CC_TEST_REPORTER_ID: dd360701bd9bd47abdea789fe94c9a9b118bc9f7fbce6d3cdc1dd3709866e460
working_directory: ~/repo

steps:
- attach_workspace:
at: ~/repo
Expand All @@ -289,8 +269,6 @@ jobs:
./cc-test-reporter sum-coverage --output - codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
workflows:
version: 2

commit:
jobs:
- build
Expand Down

0 comments on commit 9309c7f

Please sign in to comment.