Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1Add the orbs stanza below your version, invoking the orb:
1
2
orbs:
standard: tablexi/standard@0.0.13Use standard elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
check to ensure that we can migrate from scratch and end up with the schema.rb
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
mysql_db_type - | - | No | false type: boolean | boolean |
run the rubocop command
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
run the bundle-audit command
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
run the haml-lint command
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
Run Rspec after waiting for db and loading schema
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
store_screenshots - | - | No | true type: boolean | boolean |
mysql_db_type - | - | No | false type: boolean | boolean |
parallelism - | - | No | 1 type: integer | integer |
report_coverage - | - | No | false type: boolean | boolean |
install_browsers - | - | No | false type: boolean | boolean |
install_phantomjs - | - | No | false type: boolean | boolean |
Run teaspoon after waiting for db and loading schema
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
mysql_db_type - | - | No | false type: boolean | boolean |
run rake annotate and check for changes
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
mysql_db_type - | - | No | false type: boolean | boolean |
Wait for the database to be ready to accept connections
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
mysql_db_type - | - | No | false type: boolean | boolean |
Create DB and load the database schema, no matter the db type
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
mysql_db_type - | - | No | false type: boolean | boolean |
Read the Gemfile.lock and install the appropriate version of bundler
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
install phantomjs on the system for use in javascript-enabled specs
| PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
|---|---|---|---|---|
executor - Required | - | Yes | - type: executor | executor |
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
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
description: "A set of standard steps which we use for projects at Table XI"
version: 2.1
orbs:
browser-tools: circleci/browser-tools@1.4.6
commands:
wait_for_other_builds:
description: "Ensure no earlier numbered job (of this branch) is running"
steps:
- run:
name: Wait for other builds to finish before running
command: |
mkdir -p ~/bin
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -O ~/bin/jq
wget https://raw.githubusercontent.com/bellkev/circle-lock-test/02d45b47f8bf8e6009aa7fca9e9a7257a77a0404/do-exclusively -O ~/bin/do-exclusively
chmod +x ~/bin/jq ~/bin/do-exclusively
export PATH=$PATH:$HOME/bin
do-exclusively --branch $CIRCLE_BRANCH echo "We have an exclusive lock on the current branch"
wait_for_db:
description: "Wait for the database to be ready to accept connections"
parameters:
executor:
type: executor
mysql_db_type:
type: boolean
default: false
steps:
- when:
condition: << parameters.mysql_db_type >>
steps:
- run: dockerize -wait tcp://localhost:3306 -timeout 2m
- unless:
condition: << parameters.mysql_db_type >>
steps:
- run: dockerize -wait tcp://localhost:5432 -timeout 2m
load_db_schema:
description: "Create DB and load the database schema, no matter the db type"
parameters:
executor:
type: executor
mysql_db_type:
type: boolean
default: false
steps:
- run: sudo apt install -y ca-certificates && sudo apt-get --allow-releaseinfo-change update && sudo apt-get install -y tzdata
# Install the database library, so that we can run rake db:structure:load
- when:
condition: << parameters.mysql_db_type >>
steps:
- run: sudo apt-get install -y default-mysql-client libmysqlclient-dev
- unless:
condition: << parameters.mysql_db_type >>
steps:
- run: sudo apt-get install -y postgresql-client
- run: bundle exec rake db:create
- run: if [ -e db/schema.rb ]; then bundle exec rake db:schema:load; fi
- run: if [ -e db/structure.sql ]; then bundle exec rake db:structure:load; fi
install_bundler:
description: "Read the Gemfile.lock and install the appropriate version of bundler"
parameters:
executor:
type: executor
steps:
- run:
name: Install specified bundler version
command: gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"
install_phantomjs:
description: "install phantomjs on the system for use in javascript-enabled specs"
parameters:
executor:
type: executor
steps:
# https://www.vultr.com/docs/how-to-install-phantomjs-on-ubuntu-16-04/
- run: sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
- run: sudo tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C /usr/local/share/
- run: sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/
jobs:
check_db_schema:
description: check to ensure that we can migrate from scratch and end up with the schema.rb
parameters:
executor:
type: executor
mysql_db_type:
type: boolean
default: false
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- wait_for_db:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- install_bundler:
executor: << parameters.executor >>
- run: bundle exec rake db:drop db:create db:migrate RAILS_ENV=test
# # check that the schema.rb/structure.sql is the same result
- run: if [ -e db/schema.rb ]; then git diff --exit-code db/schema.rb; fi
- run: if [ -e db/structure.sql ]; then git diff --exit-code db/structure.sql; fi
rubocop:
description: run the rubocop command
parameters:
executor:
type: executor
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- install_bundler:
executor: << parameters.executor >>
- run: bundle exec rubocop --config .rubocop.yml
bundle_audit:
description: run the bundle-audit command
parameters:
executor:
type: executor
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- install_bundler:
executor: << parameters.executor >>
- run: bundle exec bundle-audit update
# If a .bundlerauditignore file EXISTS and HAS CONTENTS
# then we read the CVEs from this file and pass them to the bundler-audit command
# Otherwise, we invoke bundler-audit without --ignore args.
#
# Based upno https://github.com/rubysec/ruby-advisory-db/pull/390#issuecomment-509186921
# and https://github.com/rubysec/bundler-audit/pull/215
- run: if [ `egrep "^[^#]" .bundlerauditignore | cut -f1 | wc -l` -ne 0 ]; then egrep "^[^#]" .bundlerauditignore | cut -f1 | xargs bundle exec bundle-audit --ignore; else bundle exec bundle-audit; fi
haml_lint:
description: run the haml-lint command
parameters:
executor:
type: executor
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- install_bundler:
executor: << parameters.executor >>
- run: bundle exec haml-lint
rspec:
description: Run Rspec after waiting for db and loading schema
parameters:
executor:
type: executor
store_screenshots:
type: boolean
default: true
mysql_db_type:
type: boolean
default: false
parallelism:
type: integer
default: 1
report_coverage:
type: boolean
default: false
install_browsers:
type: boolean
default: false
install_phantomjs:
type: boolean
default: false
executor: << parameters.executor >>
parallelism: << parameters.parallelism >>
steps:
- attach_workspace:
at: ~/tmp
- wait_for_db:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- when:
condition: << parameters.install_browsers >>
steps:
- browser-tools/install-browser-tools
- install_bundler:
executor: << parameters.executor >>
# Setup DB in this job, because it cannot be shared through the attach_workspace
- run: bundle exec rake db:create
- load_db_schema:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
# install phantomjs, optionally
- when:
condition: << parameters.install_phantomjs >>
steps:
- install_phantomjs:
executor: << parameters.executor >>
# Run rspec in parallel
- run:
shell: /bin/bash -eo pipefail -O globstar
name: rspec
command: |
bundle exec rspec --profile 10 \
--format RspecJunitFormatter \
--out test_results/rspec.xml \
--format progress \
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
# Save test results for timing analysis
- store_test_results:
path: test_results
- when:
condition: << parameters.store_screenshots >>
steps:
- store_artifacts:
path: tmp/screenshots
- when:
condition: << parameters.report_coverage >>
steps:
- store_artifacts:
path: coverage/.resultset.json
prefix: coverage
- deploy:
name: Merge and copy coverage data
command: bundle exec report_coverage --branch develop
teaspoon:
description: Run teaspoon after waiting for db and loading schema
parameters:
executor:
type: executor
mysql_db_type:
type: boolean
default: false
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- wait_for_db:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- install_bundler:
executor: << parameters.executor >>
# Setup DB in this job, because it cannot be shared through the attach_workspace
- run: bundle exec rake db:create
- load_db_schema:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- run: mkdir -p ~/teaspoon
- run:
command: |
bundle exec teaspoon \
--suppress-log \
--format junit > ~/teaspoon/teaspoon.xml
check_annotate:
description: run rake annotate and check for changes
parameters:
executor:
type: executor
mysql_db_type:
type: boolean
default: false
executor: << parameters.executor >>
steps:
- attach_workspace:
at: ~/tmp
- wait_for_db:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- install_bundler:
executor: << parameters.executor >>
# Setup DB in this job, because it cannot be shared through the attach_workspace
- run: bundle exec rake db:create
- load_db_schema:
mysql_db_type: << parameters.mysql_db_type >>
executor: << parameters.executor >>
- run: bundle exec annotate
- run: git diff --exit-code