forked from salesdemocf/rails-app-with-knapsack_pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.yml
217 lines (165 loc) · 10.6 KB
/
config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Ruby CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
#
version: 2
jobs:
build:
parallelism: 2
docker:
# specify the version you desire here
- image: circleci/ruby:2.6.3-node-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.
KNAPSACK_PRO_ENDPOINT: https://api-staging.knapsackpro.com
# Tokens are set in CircleCI settings so you can't read them from this file.
# KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: rspec-token
# KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER: cucumber-token
# 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:9.4.12-alpine
environment:
POSTGRES_DB: rails-app-with-knapsack_pro_test
POSTGRES_PASSWORD: ""
POSTGRES_USER: rails-app-with-knapsack_pro
working_directory: ~/repo
steps:
- checkout
- 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: cd ~/gems/knapsack_pro-ruby && git log -n 1 | more
- 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
- save_cache:
paths:
- ./vendor/bundle
key: v2-dependencies-bundler-{{ checksum "Gemfile.lock" }}
# wait for postgres to be available
- run: dockerize -wait tcp:https://localhost:5432 -timeout 1m
# Database setup
- run: bin/rails db:setup
# Database setup for parallel_tests gem
- run: 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: 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.
- 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 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.
- 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]"
# Queue mode retry CI with the same test suite split as 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
- 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
- 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 Minitest
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_MINITEST bundle exec rake knapsack_pro:queue:minitest[--verbose]
# Regular mode
- run: KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false bundle exec rake knapsack_pro:rspec
# 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
- 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
- run: bundle exec rake "knapsack_pro:cucumber[--tag @Test]"
- run: bundle exec rake "knapsack_pro:cucumber[--format junit --out tmp/test-reports/cucumber/regular_mode]"
# Queue Mode in Cucumber
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_CUCUMBER bundle exec rake knapsack_pro:queue:cucumber
- 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: bundle exec rake knapsack_pro:minitest[--verbose]
- run: KNAPSACK_PRO_TEST_DIR=test-unit KNAPSACK_PRO_TEST_FILE_PATTERN="test-unit/**{,/*/**}/*_test.rb" bundle exec rake "knapsack_pro:test_unit[--verbose]"
- run: KNAPSACK_PRO_TEST_FILE_PATTERN="spinach_features/**{,/*/**}/*.feature" bundle exec rake knapsack_pro:spinach
# Check if https endpoint is working
- run: KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false KNAPSACK_PRO_ENDPOINT=https://api-staging.knapsackpro.com bundle exec rake knapsack_pro:rspec
- run: KNAPSACK_PRO_ENDPOINT=https://api-staging.knapsackpro.com bundle exec rake knapsack_pro:cucumber
- run: KNAPSACK_PRO_ENDPOINT=https://api-staging.knapsackpro.com bundle exec rake knapsack_pro:minitest[--verbose]
# Example of encrypted test files names
# 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
- 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
- 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
- run: KNAPSACK_PRO_ENDPOINT=https://api-fake.knapsackpro.com bundle exec rake knapsack_pro:rspec
- run: KNAPSACK_PRO_LOG_LEVEL=warn bundle exec rake knapsack_pro:rspec
# post checking after tests
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_test_file_names[rspec]
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_test_file_names[minitest]
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_test_file_names[cucumber]
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_test_file_names[spinach]
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_branch_names
- run: KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_FOR_ENCRYPTED_QUEUE_TEST_SUITE_TOKEN_RSPEC bundle exec rake knapsack_pro:encrypted_branch_names[feature-branch]
- run:
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:
- codeclimate.*.json
- store_test_results:
path: tmp/test-reports
- store_artifacts:
path: tmp/test-reports
upload-coverage:
docker:
- image: circleci/ruby:2.6.3-node
environment:
CC_TEST_REPORTER_ID: dd360701bd9bd47abdea789fe94c9a9b118bc9f7fbce6d3cdc1dd3709866e460
working_directory: ~/repo
steps:
- attach_workspace:
at: ~/repo
- 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:
command: |
./cc-test-reporter sum-coverage --output - codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
workflows:
version: 2
commit:
jobs:
- build
- upload-coverage:
requires:
- build