schema_dev 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/prs.yml +49 -0
  3. data/.simplecov +20 -0
  4. data/Gemfile +2 -0
  5. data/README.md +7 -7
  6. data/Rakefile +3 -5
  7. data/bin/schema_dev +25 -21
  8. data/lib/schema_dev/config.rb +62 -44
  9. data/lib/schema_dev/executor.rb +9 -8
  10. data/lib/schema_dev/gem.rb +45 -37
  11. data/lib/schema_dev/gemfile_selector.rb +7 -7
  12. data/lib/schema_dev/gemfiles.rb +6 -5
  13. data/lib/schema_dev/github_actions.rb +266 -0
  14. data/lib/schema_dev/matrix_executor.rb +4 -2
  15. data/lib/schema_dev/readme.rb +17 -10
  16. data/lib/schema_dev/rspec/db.rb +44 -33
  17. data/lib/schema_dev/rspec.rb +4 -9
  18. data/lib/schema_dev/ruby_selector.rb +29 -14
  19. data/lib/schema_dev/runner.rb +14 -10
  20. data/lib/schema_dev/tasks/dbms.rb +34 -26
  21. data/lib/schema_dev/tasks.rb +2 -3
  22. data/lib/schema_dev/templates.rb +5 -5
  23. data/lib/schema_dev/version.rb +3 -1
  24. data/lib/schema_dev.rb +3 -1
  25. data/schema_dev.gemspec +23 -26
  26. data/spec/schema_dev/config_spec.rb +60 -0
  27. data/spec/schema_dev/gem_spec.rb +74 -0
  28. data/spec/schema_dev/gemfile_selector_spec.rb +11 -0
  29. data/spec/schema_dev/gemfiles_spec.rb +41 -0
  30. data/spec/schema_dev/github_actions_spec.rb +818 -0
  31. data/spec/schema_dev/runner_spec.rb +103 -0
  32. data/spec/spec_helper.rb +5 -6
  33. data/templates/README/uses.schema_dev.md.erb +1 -2
  34. data/templates/gem/GEM_NAME.gemspec.erb +15 -14
  35. data/templates/gem/Gemfile.erb +2 -0
  36. data/templates/gem/Gemfile.local.erb +2 -0
  37. data/templates/gem/README.md.erb +1 -2
  38. data/templates/gem/Rakefile.erb +2 -0
  39. data/templates/gem/schema_dev.yml.erb +4 -1
  40. data/templates/gem/simplecov.erb +20 -0
  41. metadata +38 -87
  42. data/.travis.yml +0 -4
  43. data/lib/schema_dev/tasks/coveralls.rb +0 -3
  44. data/lib/schema_dev/travis.rb +0 -147
  45. data/spec/config_spec.rb +0 -61
  46. data/spec/gem_spec.rb +0 -77
  47. data/spec/gemfile_sepector_spec.rb +0 -10
  48. data/spec/gemfiles_spec.rb +0 -41
  49. data/spec/runner_spec.rb +0 -106
  50. data/spec/travis_spec.rb +0 -392
@@ -0,0 +1,818 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'schema_dev/github_actions'
4
+
5
+ describe SchemaDev::GithubActions do
6
+ subject do
7
+ in_tmpdir do
8
+ described_class.update(get_config(config))
9
+ Pathname.new(described_class::WORKFLOW_FILE).read
10
+ end
11
+ end
12
+
13
+ let(:config) { {} }
14
+
15
+ context 'when only having sqlite3 enabled' do
16
+ let(:config) do
17
+ {
18
+ ruby: [2.5],
19
+ activerecord: [5.2, 6.0],
20
+ db: %w[sqlite3]
21
+ }
22
+ end
23
+
24
+ it 'creates a workflow file containing setup for just sqlite3' do
25
+ is_expected.to eq described_class::HEADER + <<~YAML
26
+ ---
27
+ name: CI PR Builds
28
+ 'on':
29
+ push:
30
+ branches:
31
+ - master
32
+ pull_request:
33
+ concurrency:
34
+ group: "${{ github.head_ref }}"
35
+ cancel-in-progress: true
36
+ jobs:
37
+ test:
38
+ runs-on: ubuntu-latest
39
+ strategy:
40
+ fail-fast: false
41
+ matrix:
42
+ ruby:
43
+ - '2.5'
44
+ activerecord:
45
+ - '5.2'
46
+ - '6.0'
47
+ db:
48
+ - sqlite3
49
+ env:
50
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
51
+ steps:
52
+ - uses: actions/checkout@v2
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+ with:
56
+ ruby-version: "${{ matrix.ruby }}"
57
+ bundler-cache: true
58
+ - name: Run bundle update
59
+ run: bundle update
60
+ - name: Run tests
61
+ run: bundle exec rake spec
62
+ - name: Coveralls Parallel
63
+ if: "${{ !env.ACT }}"
64
+ uses: coverallsapp/github-action@master
65
+ with:
66
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
67
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
68
+ parallel: true
69
+ finish:
70
+ needs: test
71
+ runs-on: ubuntu-latest
72
+ steps:
73
+ - name: Coveralls Finished
74
+ if: "${{ !env.ACT }}"
75
+ uses: coverallsapp/github-action@master
76
+ with:
77
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
78
+ parallel-finished: true
79
+ YAML
80
+ end
81
+ end
82
+
83
+ context 'when ruby 3 is included with AR < 6.0' do
84
+ let(:config) do
85
+ {
86
+ ruby: [2.5, 3.0],
87
+ activerecord: [5.2, 6.0],
88
+ db: %w[sqlite3]
89
+ }
90
+ end
91
+
92
+ it 'automatically excludes old AR on ruby 3' do
93
+ is_expected.to eq described_class::HEADER + <<~YAML
94
+ ---
95
+ name: CI PR Builds
96
+ 'on':
97
+ push:
98
+ branches:
99
+ - master
100
+ pull_request:
101
+ concurrency:
102
+ group: "${{ github.head_ref }}"
103
+ cancel-in-progress: true
104
+ jobs:
105
+ test:
106
+ runs-on: ubuntu-latest
107
+ strategy:
108
+ fail-fast: false
109
+ matrix:
110
+ ruby:
111
+ - '2.5'
112
+ - '3.0'
113
+ activerecord:
114
+ - '5.2'
115
+ - '6.0'
116
+ db:
117
+ - sqlite3
118
+ exclude:
119
+ - ruby: '3.0'
120
+ activerecord: '5.2'
121
+ env:
122
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
123
+ steps:
124
+ - uses: actions/checkout@v2
125
+ - name: Set up Ruby
126
+ uses: ruby/setup-ruby@v1
127
+ with:
128
+ ruby-version: "${{ matrix.ruby }}"
129
+ bundler-cache: true
130
+ - name: Run bundle update
131
+ run: bundle update
132
+ - name: Run tests
133
+ run: bundle exec rake spec
134
+ - name: Coveralls Parallel
135
+ if: "${{ !env.ACT }}"
136
+ uses: coverallsapp/github-action@master
137
+ with:
138
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
139
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
140
+ parallel: true
141
+ finish:
142
+ needs: test
143
+ runs-on: ubuntu-latest
144
+ steps:
145
+ - name: Coveralls Finished
146
+ if: "${{ !env.ACT }}"
147
+ uses: coverallsapp/github-action@master
148
+ with:
149
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
150
+ parallel-finished: true
151
+ YAML
152
+ end
153
+ end
154
+
155
+ context 'when notify is passed' do
156
+ let(:config) do
157
+ {
158
+ ruby: [2.5],
159
+ activerecord: [5.2],
160
+ db: %w[sqlite3],
161
+ notify: 'me@example.com'
162
+ }
163
+ end
164
+
165
+ around do |ex|
166
+ suppress_stdout_stderr(&ex)
167
+ end
168
+
169
+ it 'outputs a warning' do
170
+ expect { subject }.to output(/Notify is no longer supported/).to_stderr
171
+ end
172
+
173
+ it 'does not include it in the workflow' do
174
+ is_expected.to eq described_class::HEADER + <<~YAML
175
+ ---
176
+ name: CI PR Builds
177
+ 'on':
178
+ push:
179
+ branches:
180
+ - master
181
+ pull_request:
182
+ concurrency:
183
+ group: "${{ github.head_ref }}"
184
+ cancel-in-progress: true
185
+ jobs:
186
+ test:
187
+ runs-on: ubuntu-latest
188
+ strategy:
189
+ fail-fast: false
190
+ matrix:
191
+ ruby:
192
+ - '2.5'
193
+ activerecord:
194
+ - '5.2'
195
+ db:
196
+ - sqlite3
197
+ env:
198
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
199
+ steps:
200
+ - uses: actions/checkout@v2
201
+ - name: Set up Ruby
202
+ uses: ruby/setup-ruby@v1
203
+ with:
204
+ ruby-version: "${{ matrix.ruby }}"
205
+ bundler-cache: true
206
+ - name: Run bundle update
207
+ run: bundle update
208
+ - name: Run tests
209
+ run: bundle exec rake spec
210
+ - name: Coveralls Parallel
211
+ if: "${{ !env.ACT }}"
212
+ uses: coverallsapp/github-action@master
213
+ with:
214
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
215
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
216
+ parallel: true
217
+ finish:
218
+ needs: test
219
+ runs-on: ubuntu-latest
220
+ steps:
221
+ - name: Coveralls Finished
222
+ if: "${{ !env.ACT }}"
223
+ uses: coverallsapp/github-action@master
224
+ with:
225
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
226
+ parallel-finished: true
227
+ YAML
228
+ end
229
+ end
230
+
231
+ context 'when only having postgresql enabled' do
232
+ let(:config) do
233
+ {
234
+ ruby: [2.5],
235
+ activerecord: [5.2, 6.0],
236
+ db: %w[postgresql]
237
+ }
238
+ end
239
+
240
+ it 'creates a workflow file containing setup for just postgresql' do
241
+ is_expected.to eq described_class::HEADER + <<~YAML
242
+ ---
243
+ name: CI PR Builds
244
+ 'on':
245
+ push:
246
+ branches:
247
+ - master
248
+ pull_request:
249
+ concurrency:
250
+ group: "${{ github.head_ref }}"
251
+ cancel-in-progress: true
252
+ jobs:
253
+ test:
254
+ runs-on: ubuntu-latest
255
+ strategy:
256
+ fail-fast: false
257
+ matrix:
258
+ ruby:
259
+ - '2.5'
260
+ activerecord:
261
+ - '5.2'
262
+ - '6.0'
263
+ db:
264
+ - skip
265
+ dbversion:
266
+ - skip
267
+ exclude:
268
+ - db: skip
269
+ dbversion: skip
270
+ include:
271
+ - ruby: '2.5'
272
+ activerecord: '5.2'
273
+ db: postgresql
274
+ dbversion: '9.6'
275
+ - ruby: '2.5'
276
+ activerecord: '6.0'
277
+ db: postgresql
278
+ dbversion: '9.6'
279
+ env:
280
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
281
+ POSTGRESQL_DB_HOST: 127.0.0.1
282
+ POSTGRESQL_DB_USER: schema_plus_test
283
+ POSTGRESQL_DB_PASS: database
284
+ steps:
285
+ - uses: actions/checkout@v2
286
+ - name: Set up Ruby
287
+ uses: ruby/setup-ruby@v1
288
+ with:
289
+ ruby-version: "${{ matrix.ruby }}"
290
+ bundler-cache: true
291
+ - name: Run bundle update
292
+ run: bundle update
293
+ - name: Start Postgresql
294
+ if: matrix.db == 'postgresql'
295
+ run: |
296
+ docker run --rm --detach \\
297
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \\
298
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \\
299
+ -p 5432:5432 \\
300
+ --health-cmd "pg_isready -q" \\
301
+ --health-interval 5s \\
302
+ --health-timeout 5s \\
303
+ --health-retries 5 \\
304
+ --name database postgres:${{ matrix.dbversion }}
305
+ - name: Wait for database to start
306
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
307
+ run: |
308
+ COUNT=0
309
+ ATTEMPTS=20
310
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
311
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
312
+ echo $(( COUNT++ )) > /dev/null
313
+ sleep 2
314
+ done
315
+ - name: Create testing database
316
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
317
+ run: bundle exec rake create_ci_database
318
+ - name: Run tests
319
+ run: bundle exec rake spec
320
+ - name: Shutdown database
321
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
322
+ run: docker stop database
323
+ - name: Coveralls Parallel
324
+ if: "${{ !env.ACT }}"
325
+ uses: coverallsapp/github-action@master
326
+ with:
327
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
328
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
329
+ parallel: true
330
+ finish:
331
+ needs: test
332
+ runs-on: ubuntu-latest
333
+ steps:
334
+ - name: Coveralls Finished
335
+ if: "${{ !env.ACT }}"
336
+ uses: coverallsapp/github-action@master
337
+ with:
338
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
339
+ parallel-finished: true
340
+ YAML
341
+ end
342
+ end
343
+
344
+ context 'when only having mysql2 enabled' do
345
+ let(:config) do
346
+ {
347
+ ruby: [2.5],
348
+ activerecord: [5.2, 6.0],
349
+ db: %w[mysql2]
350
+ }
351
+ end
352
+
353
+ it 'creates a workflow file containing setup for just mysql2' do
354
+ is_expected.to eq described_class::HEADER + <<~YAML
355
+ ---
356
+ name: CI PR Builds
357
+ 'on':
358
+ push:
359
+ branches:
360
+ - master
361
+ pull_request:
362
+ concurrency:
363
+ group: "${{ github.head_ref }}"
364
+ cancel-in-progress: true
365
+ jobs:
366
+ test:
367
+ runs-on: ubuntu-latest
368
+ strategy:
369
+ fail-fast: false
370
+ matrix:
371
+ ruby:
372
+ - '2.5'
373
+ activerecord:
374
+ - '5.2'
375
+ - '6.0'
376
+ db:
377
+ - mysql2
378
+ env:
379
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
380
+ MYSQL_DB_HOST: 127.0.0.1
381
+ MYSQL_DB_USER: root
382
+ MYSQL_DB_PASS: database
383
+ steps:
384
+ - uses: actions/checkout@v2
385
+ - name: Set up Ruby
386
+ uses: ruby/setup-ruby@v1
387
+ with:
388
+ ruby-version: "${{ matrix.ruby }}"
389
+ bundler-cache: true
390
+ - name: Run bundle update
391
+ run: bundle update
392
+ - name: Start Mysql
393
+ if: matrix.db == 'mysql2'
394
+ run: |
395
+ docker run --rm --detach \\
396
+ -e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \\
397
+ -p 3306:3306 \\
398
+ --health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \\
399
+ --health-interval 5s \\
400
+ --health-timeout 5s \\
401
+ --health-retries 5 \\
402
+ --name database mysql:5.6
403
+ - name: Wait for database to start
404
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
405
+ run: |
406
+ COUNT=0
407
+ ATTEMPTS=20
408
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
409
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
410
+ echo $(( COUNT++ )) > /dev/null
411
+ sleep 2
412
+ done
413
+ - name: Create testing database
414
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
415
+ run: bundle exec rake create_ci_database
416
+ - name: Run tests
417
+ run: bundle exec rake spec
418
+ - name: Shutdown database
419
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
420
+ run: docker stop database
421
+ - name: Coveralls Parallel
422
+ if: "${{ !env.ACT }}"
423
+ uses: coverallsapp/github-action@master
424
+ with:
425
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
426
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
427
+ parallel: true
428
+ finish:
429
+ needs: test
430
+ runs-on: ubuntu-latest
431
+ steps:
432
+ - name: Coveralls Finished
433
+ if: "${{ !env.ACT }}"
434
+ uses: coverallsapp/github-action@master
435
+ with:
436
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
437
+ parallel-finished: true
438
+ YAML
439
+ end
440
+ end
441
+
442
+ context 'when only having postgresql with multiple DB versions' do
443
+ let(:config) do
444
+ {
445
+ ruby: [2.5],
446
+ activerecord: [5.2, 6.0],
447
+ db: %w[postgresql],
448
+ dbversions: { postgresql: [9.6, 10] }
449
+ }
450
+ end
451
+
452
+ it 'creates a workflow file containing setup for just postgresql' do
453
+ is_expected.to eq described_class::HEADER + <<~YAML
454
+ ---
455
+ name: CI PR Builds
456
+ 'on':
457
+ push:
458
+ branches:
459
+ - master
460
+ pull_request:
461
+ concurrency:
462
+ group: "${{ github.head_ref }}"
463
+ cancel-in-progress: true
464
+ jobs:
465
+ test:
466
+ runs-on: ubuntu-latest
467
+ strategy:
468
+ fail-fast: false
469
+ matrix:
470
+ ruby:
471
+ - '2.5'
472
+ activerecord:
473
+ - '5.2'
474
+ - '6.0'
475
+ db:
476
+ - skip
477
+ dbversion:
478
+ - skip
479
+ exclude:
480
+ - db: skip
481
+ dbversion: skip
482
+ include:
483
+ - ruby: '2.5'
484
+ activerecord: '5.2'
485
+ db: postgresql
486
+ dbversion: '9.6'
487
+ - ruby: '2.5'
488
+ activerecord: '5.2'
489
+ db: postgresql
490
+ dbversion: '10'
491
+ - ruby: '2.5'
492
+ activerecord: '6.0'
493
+ db: postgresql
494
+ dbversion: '9.6'
495
+ - ruby: '2.5'
496
+ activerecord: '6.0'
497
+ db: postgresql
498
+ dbversion: '10'
499
+ env:
500
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
501
+ POSTGRESQL_DB_HOST: 127.0.0.1
502
+ POSTGRESQL_DB_USER: schema_plus_test
503
+ POSTGRESQL_DB_PASS: database
504
+ steps:
505
+ - uses: actions/checkout@v2
506
+ - name: Set up Ruby
507
+ uses: ruby/setup-ruby@v1
508
+ with:
509
+ ruby-version: "${{ matrix.ruby }}"
510
+ bundler-cache: true
511
+ - name: Run bundle update
512
+ run: bundle update
513
+ - name: Start Postgresql
514
+ if: matrix.db == 'postgresql'
515
+ run: |
516
+ docker run --rm --detach \\
517
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \\
518
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \\
519
+ -p 5432:5432 \\
520
+ --health-cmd "pg_isready -q" \\
521
+ --health-interval 5s \\
522
+ --health-timeout 5s \\
523
+ --health-retries 5 \\
524
+ --name database postgres:${{ matrix.dbversion }}
525
+ - name: Wait for database to start
526
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
527
+ run: |
528
+ COUNT=0
529
+ ATTEMPTS=20
530
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
531
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
532
+ echo $(( COUNT++ )) > /dev/null
533
+ sleep 2
534
+ done
535
+ - name: Create testing database
536
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
537
+ run: bundle exec rake create_ci_database
538
+ - name: Run tests
539
+ run: bundle exec rake spec
540
+ - name: Shutdown database
541
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
542
+ run: docker stop database
543
+ - name: Coveralls Parallel
544
+ if: "${{ !env.ACT }}"
545
+ uses: coverallsapp/github-action@master
546
+ with:
547
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
548
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
549
+ parallel: true
550
+ finish:
551
+ needs: test
552
+ runs-on: ubuntu-latest
553
+ steps:
554
+ - name: Coveralls Finished
555
+ if: "${{ !env.ACT }}"
556
+ uses: coverallsapp/github-action@master
557
+ with:
558
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
559
+ parallel-finished: true
560
+ YAML
561
+ end
562
+ end
563
+
564
+ context 'when only having postgresql with multiple DB versions with excludes' do
565
+ let(:config) do
566
+ {
567
+ ruby: [2.5],
568
+ activerecord: [5.2, 6.0],
569
+ db: %w[postgresql],
570
+ dbversions: { postgresql: [9.6, 10] },
571
+ exclude: [{ db: 'postgresql', dbversion: 9.6, activerecord: 5.2 }]
572
+ }
573
+ end
574
+
575
+ it 'creates a workflow file containing setup for just postgresql' do
576
+ is_expected.to eq described_class::HEADER + <<~YAML
577
+ ---
578
+ name: CI PR Builds
579
+ 'on':
580
+ push:
581
+ branches:
582
+ - master
583
+ pull_request:
584
+ concurrency:
585
+ group: "${{ github.head_ref }}"
586
+ cancel-in-progress: true
587
+ jobs:
588
+ test:
589
+ runs-on: ubuntu-latest
590
+ strategy:
591
+ fail-fast: false
592
+ matrix:
593
+ ruby:
594
+ - '2.5'
595
+ activerecord:
596
+ - '5.2'
597
+ - '6.0'
598
+ db:
599
+ - skip
600
+ dbversion:
601
+ - skip
602
+ exclude:
603
+ - db: skip
604
+ dbversion: skip
605
+ include:
606
+ - ruby: '2.5'
607
+ activerecord: '5.2'
608
+ db: postgresql
609
+ dbversion: '10'
610
+ - ruby: '2.5'
611
+ activerecord: '6.0'
612
+ db: postgresql
613
+ dbversion: '9.6'
614
+ - ruby: '2.5'
615
+ activerecord: '6.0'
616
+ db: postgresql
617
+ dbversion: '10'
618
+ env:
619
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
620
+ POSTGRESQL_DB_HOST: 127.0.0.1
621
+ POSTGRESQL_DB_USER: schema_plus_test
622
+ POSTGRESQL_DB_PASS: database
623
+ steps:
624
+ - uses: actions/checkout@v2
625
+ - name: Set up Ruby
626
+ uses: ruby/setup-ruby@v1
627
+ with:
628
+ ruby-version: "${{ matrix.ruby }}"
629
+ bundler-cache: true
630
+ - name: Run bundle update
631
+ run: bundle update
632
+ - name: Start Postgresql
633
+ if: matrix.db == 'postgresql'
634
+ run: |
635
+ docker run --rm --detach \\
636
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \\
637
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \\
638
+ -p 5432:5432 \\
639
+ --health-cmd "pg_isready -q" \\
640
+ --health-interval 5s \\
641
+ --health-timeout 5s \\
642
+ --health-retries 5 \\
643
+ --name database postgres:${{ matrix.dbversion }}
644
+ - name: Wait for database to start
645
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
646
+ run: |
647
+ COUNT=0
648
+ ATTEMPTS=20
649
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
650
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
651
+ echo $(( COUNT++ )) > /dev/null
652
+ sleep 2
653
+ done
654
+ - name: Create testing database
655
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
656
+ run: bundle exec rake create_ci_database
657
+ - name: Run tests
658
+ run: bundle exec rake spec
659
+ - name: Shutdown database
660
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
661
+ run: docker stop database
662
+ - name: Coveralls Parallel
663
+ if: "${{ !env.ACT }}"
664
+ uses: coverallsapp/github-action@master
665
+ with:
666
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
667
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
668
+ parallel: true
669
+ finish:
670
+ needs: test
671
+ runs-on: ubuntu-latest
672
+ steps:
673
+ - name: Coveralls Finished
674
+ if: "${{ !env.ACT }}"
675
+ uses: coverallsapp/github-action@master
676
+ with:
677
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
678
+ parallel-finished: true
679
+ YAML
680
+ end
681
+ end
682
+
683
+ context 'when configured multiple DBs' do
684
+ let(:config) do
685
+ {
686
+ ruby: [2.5, 3.0],
687
+ activerecord: [5.2, 6.0],
688
+ db: %w[sqlite3 mysql2 postgresql]
689
+ }
690
+ end
691
+
692
+ it 'creates a workflow file containing the complex setup' do
693
+ is_expected.to eq described_class::HEADER + <<~YAML
694
+ ---
695
+ name: CI PR Builds
696
+ 'on':
697
+ push:
698
+ branches:
699
+ - master
700
+ pull_request:
701
+ concurrency:
702
+ group: "${{ github.head_ref }}"
703
+ cancel-in-progress: true
704
+ jobs:
705
+ test:
706
+ runs-on: ubuntu-latest
707
+ strategy:
708
+ fail-fast: false
709
+ matrix:
710
+ ruby:
711
+ - '2.5'
712
+ - '3.0'
713
+ activerecord:
714
+ - '5.2'
715
+ - '6.0'
716
+ db:
717
+ - sqlite3
718
+ - mysql2
719
+ - skip
720
+ dbversion:
721
+ - skip
722
+ exclude:
723
+ - ruby: '3.0'
724
+ activerecord: '5.2'
725
+ - db: skip
726
+ dbversion: skip
727
+ include:
728
+ - ruby: '2.5'
729
+ activerecord: '5.2'
730
+ db: postgresql
731
+ dbversion: '9.6'
732
+ - ruby: '2.5'
733
+ activerecord: '6.0'
734
+ db: postgresql
735
+ dbversion: '9.6'
736
+ - ruby: '3.0'
737
+ activerecord: '6.0'
738
+ db: postgresql
739
+ dbversion: '9.6'
740
+ env:
741
+ BUNDLE_GEMFILE: "${{ github.workspace }}/gemfiles/activerecord-${{ matrix.activerecord }}/Gemfile.${{ matrix.db }}"
742
+ MYSQL_DB_HOST: 127.0.0.1
743
+ MYSQL_DB_USER: root
744
+ MYSQL_DB_PASS: database
745
+ POSTGRESQL_DB_HOST: 127.0.0.1
746
+ POSTGRESQL_DB_USER: schema_plus_test
747
+ POSTGRESQL_DB_PASS: database
748
+ steps:
749
+ - uses: actions/checkout@v2
750
+ - name: Set up Ruby
751
+ uses: ruby/setup-ruby@v1
752
+ with:
753
+ ruby-version: "${{ matrix.ruby }}"
754
+ bundler-cache: true
755
+ - name: Run bundle update
756
+ run: bundle update
757
+ - name: Start Mysql
758
+ if: matrix.db == 'mysql2'
759
+ run: |
760
+ docker run --rm --detach \\
761
+ -e MYSQL_ROOT_PASSWORD=$MYSQL_DB_PASS \\
762
+ -p 3306:3306 \\
763
+ --health-cmd "mysqladmin ping --host=127.0.0.1 --password=$MYSQL_DB_PASS --silent" \\
764
+ --health-interval 5s \\
765
+ --health-timeout 5s \\
766
+ --health-retries 5 \\
767
+ --name database mysql:5.6
768
+ - name: Start Postgresql
769
+ if: matrix.db == 'postgresql'
770
+ run: |
771
+ docker run --rm --detach \\
772
+ -e POSTGRES_USER=$POSTGRESQL_DB_USER \\
773
+ -e POSTGRES_PASSWORD=$POSTGRESQL_DB_PASS \\
774
+ -p 5432:5432 \\
775
+ --health-cmd "pg_isready -q" \\
776
+ --health-interval 5s \\
777
+ --health-timeout 5s \\
778
+ --health-retries 5 \\
779
+ --name database postgres:${{ matrix.dbversion }}
780
+ - name: Wait for database to start
781
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
782
+ run: |
783
+ COUNT=0
784
+ ATTEMPTS=20
785
+ until [[ $COUNT -eq $ATTEMPTS ]]; do
786
+ [ "$(docker inspect -f {{.State.Health.Status}} database)" == "healthy" ] && break
787
+ echo $(( COUNT++ )) > /dev/null
788
+ sleep 2
789
+ done
790
+ - name: Create testing database
791
+ if: "(matrix.db == 'postgresql' || matrix.db == 'mysql2')"
792
+ run: bundle exec rake create_ci_database
793
+ - name: Run tests
794
+ run: bundle exec rake spec
795
+ - name: Shutdown database
796
+ if: always() && (matrix.db == 'postgresql' || matrix.db == 'mysql2')
797
+ run: docker stop database
798
+ - name: Coveralls Parallel
799
+ if: "${{ !env.ACT }}"
800
+ uses: coverallsapp/github-action@master
801
+ with:
802
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
803
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.activerecord }}-${{ matrix.db }}-${{ matrix.dbversion }}
804
+ parallel: true
805
+ finish:
806
+ needs: test
807
+ runs-on: ubuntu-latest
808
+ steps:
809
+ - name: Coveralls Finished
810
+ if: "${{ !env.ACT }}"
811
+ uses: coverallsapp/github-action@master
812
+ with:
813
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
814
+ parallel-finished: true
815
+ YAML
816
+ end
817
+ end
818
+ end