forked from dustinvanbuskirk/rails-app-with-knapsack_pro
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.yml
299 lines (240 loc) · 14.8 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# 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
# https://circleci.com/developer/images/image/cimg/ruby
- image: cimg/ruby:3.2.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.
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:13.3-ram
environment:
POSTGRES_DB: rails-app-with-knapsack_pro_test
POSTGRES_PASSWORD: "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:
name: Show last commit
command: |
cd ~/gems/knapsack_pro-ruby
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
- 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: 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 - 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
- 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.
- 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
command: |
report_dir=tmp/test-reports/rspec/queue_mode/
if [ -d $report_dir ] && [ `ls $report_dir | wc -l` -gt 0 ]; then
curl -X POST \
-H "x-api-key:$CALLIOPE_API_KEY" \
-H "Content-Type:multipart/form-data" \
-F "file[]=@tmp/test-reports/rspec/queue_mode/rspec.xml" \
"https://app.calliope.pro/api/v2/profile/3416/import/junit?build=$CIRCLE_BUILD_NUM"
else
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
- 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 - RSpec split by test examples
- run:
name: RSpec split by test cases (Queue Mode)
command: |
export KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=$KNAPSACK_PRO_QUEUE_TEST_SUITE_TOKEN_RSPEC_SPLIT_BY_TEST_CASES
export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true
bundle exec rake knapsack_pro:queue:rspec
- run:
name: RSpec split by test cases (Regular Mode), use 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
- 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
- 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]"
- run:
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/
if [ -d $report_dir ] && [ `ls $report_dir | wc -l` -gt 0 ]; then
echo "All report files:"
ls -la $report_dir
echo
for file in $report_dir*
do
echo
echo "Import file: $file"
# use double quote in @\"$file\" to import file name with spaces in the name
curl -X POST -H "x-api-key:$CALLIOPE_API_KEY" -H "Content-Type:multipart/form-data" -F "file[]=@\"$file\"" "https://app.calliope.pro/api/v2/profile/3418/import/junit?build=$CIRCLE_BUILD_NUM&merge_containers=true"
echo
done
else
echo "Report files not found. Nothing to import to Calliope.pro"
fi
# 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:
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/
if [ -d $report_dir ] && [ `ls $report_dir | wc -l` -gt 0 ]; then
echo "All report files:"
ls -la $report_dir
echo
for file in $report_dir*
do
echo
echo "Import file: $file"
# use double quote in @\"$file\" to import file name with spaces in the name
curl -X POST -H "x-api-key:$CALLIOPE_API_KEY" -H "Content-Type:multipart/form-data" -F "file[]=@\"$file\"" "https://app.calliope.pro/api/v2/profile/3419/import/junit?build=$CIRCLE_BUILD_NUM&merge_containers=true"
echo
done
else
echo "Report files not found. Nothing to import to Calliope.pro"
fi
- run: KNAPSACK_PRO_RSPEC_DISABLED=true 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_RSPEC_DISABLED=true 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 KNAPSACK_PRO_MAX_REQUEST_RETRIES=1 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: cimg/ruby:3.2.2-browsers
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