Skip to content

Commit 315fecb

Browse files
authored
Add circleci parallel example (#392)
1 parent b7a4eed commit 315fecb

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

Diff for: examples/ruby_examples.md

+134
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,137 @@ after_script:
112112
- if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then ./cc-test-reporter upload-coverage; fi # Upload coverage/codeclimate.json
113113
```
114114

115+
## Example 3
116+
- Language: Ruby
117+
- CI: CircleCI
118+
- Coverage Tool: RSpec
119+
- File: .circleci/config.yml
120+
- Single/Parallel: Parallel
121+
- OSS Repo: [This repo](https://github.com/FlorinPopaCodes/bike_index/blob/master/.circleci/config.yml), based on [this conversation](https://github.com/codeclimate/test-reporter/issues/386#issuecomment-473684517)
122+
123+
```
124+
version: 2
125+
jobs:
126+
build:
127+
working_directory: ~/bikeindex/bike_index
128+
parallelism: 4
129+
shell: /bin/bash --login
130+
environment:
131+
RAILS_ENV: test
132+
RACK_ENV: test
133+
COVERAGE: true
134+
TZ: /usr/share/zoneinfo/America/Chicago
135+
docker:
136+
- image: circleci/ruby:2.5.1-stretch-node
137+
environment:
138+
PGHOST: 127.0.0.1
139+
PGUSER: root
140+
- image: circleci/postgres:10.4-alpine-postgis
141+
environment:
142+
POSTGRES_USER: root
143+
POSTGRES_DB: bikeindex_test
144+
- image: redis:4.0.9
145+
steps:
146+
- checkout
147+
- restore_cache:
148+
keys:
149+
# This branch if available
150+
- v2-dep-{{ .Branch }}-
151+
# Default branch if not
152+
- v2-dep-master-
153+
# Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
154+
- v2-dep-
155+
- run:
156+
name: install dockerize
157+
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
158+
environment:
159+
DOCKERIZE_VERSION: v0.6.1
160+
- run:
161+
name: install system libraries
162+
command: sudo apt-get update && sudo apt-get -y install imagemagick postgresql-client
163+
- run:
164+
name: install bundler
165+
command: gem install bundler
166+
- run:
167+
name: bundle gems
168+
command: bundle install --path=vendor/bundle --jobs=4 --retry=3
169+
# So that we can compile assets, since we use node & yarn
170+
- run:
171+
name: Yarn Install
172+
command: yarn install --cache-folder ~/.cache/yarn
173+
- run: bundle exec rake assets:precompile
174+
- run:
175+
name: Install Code Climate Test Reporter
176+
command: |
177+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
178+
chmod +x ./cc-test-reporter
179+
- run:
180+
name: Wait for PostgreSQL to start
181+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
182+
- save_cache:
183+
key: v2-dep-{{ .Branch }}-{{ epoch }}
184+
paths:
185+
- ./vendor/bundle
186+
- ~/.bundle
187+
- public/assets
188+
- tmp/cache/assets/sprockets
189+
- ~/.cache/yarn
190+
- run:
191+
name: Setup Database
192+
command: |
193+
bundle exec rake db:create db:structure:load
194+
- run:
195+
name: Run tests
196+
command: |
197+
mkdir -p test-results/rspec test-artifacts
198+
./cc-test-reporter before-build
199+
TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
200+
bundle exec rspec --profile 10 \
201+
--color \
202+
--order random \
203+
--format RspecJunitFormatter \
204+
--out test-results/rspec/rspec.xml \
205+
--format progress \
206+
-- ${TESTFILES}
207+
- run:
208+
name: Code Climate Test Coverage
209+
command: |
210+
./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
211+
- persist_to_workspace:
212+
root: coverage
213+
paths:
214+
- codeclimate.*.json
215+
- store_test_results:
216+
path: test-results
217+
- store_artifacts:
218+
path: test-artifacts
219+
220+
upload-coverage:
221+
docker:
222+
- image: circleci/ruby:2.5.1-stretch-node
223+
environment:
224+
CC_TEST_REPORTER_ID: c3ff91e23ea0fea718bb62dae0a8a5440dc082d5d2bb508af6b33d0babac479a
225+
working_directory: ~/bikeindex/bike_index
226+
227+
steps:
228+
- attach_workspace:
229+
at: ~/bikeindex/bike_index
230+
- run:
231+
name: Install Code Climate Test Reporter
232+
command: |
233+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
234+
chmod +x ./cc-test-reporter
235+
- run:
236+
command: |
237+
./cc-test-reporter sum-coverage --output - codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
238+
239+
workflows:
240+
version: 2
241+
242+
commit:
243+
jobs:
244+
- build
245+
- upload-coverage:
246+
requires:
247+
- build
248+
```

0 commit comments

Comments
 (0)