gemika 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +122 -0
  3. data/.gitignore +1 -1
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +75 -0
  6. data/{gemfiles/Gemfile.3.2.mysql2 → Gemfile.3.2.mysql2} +3 -2
  7. data/{gemfiles/Gemfile.3.2.mysql2.lock → Gemfile.3.2.mysql2.lock} +19 -5
  8. data/{gemfiles/Gemfile.4.2.mysql2 → Gemfile.4.2.mysql2} +3 -2
  9. data/{gemfiles/Gemfile.4.2.mysql2.lock → Gemfile.4.2.mysql2.lock} +11 -4
  10. data/{gemfiles/Gemfile.4.2.pg → Gemfile.4.2.pg} +2 -1
  11. data/{gemfiles/Gemfile.4.2.pg.lock → Gemfile.4.2.pg.lock} +9 -3
  12. data/{gemfiles/Gemfile.5.0.mysql2 → Gemfile.5.2.mysql2} +4 -3
  13. data/{gemfiles/Gemfile.5.0.mysql2.lock → Gemfile.5.2.mysql2.lock} +28 -20
  14. data/{gemfiles/Gemfile.5.0.pg → Gemfile.5.2.pg} +3 -2
  15. data/{gemfiles/Gemfile.5.0.pg.lock → Gemfile.5.2.pg.lock} +26 -18
  16. data/Gemfile.5.2.sqlite3 +17 -0
  17. data/Gemfile.5.2.sqlite3.lock +67 -0
  18. data/Gemfile.6.0.pg +17 -0
  19. data/Gemfile.6.0.pg.lock +67 -0
  20. data/README.md +144 -71
  21. data/gemika.gemspec +2 -2
  22. data/lib/gemika/database.rb +13 -3
  23. data/lib/gemika/env.rb +6 -0
  24. data/lib/gemika/errors.rb +2 -0
  25. data/lib/gemika/github_actions_generator.rb +150 -0
  26. data/lib/gemika/matrix.rb +38 -33
  27. data/lib/gemika/matrix/github_actions_config.rb +61 -0
  28. data/lib/gemika/matrix/travis_config.rb +42 -0
  29. data/lib/gemika/tasks.rb +1 -0
  30. data/lib/gemika/tasks/gemika.rb +14 -0
  31. data/lib/gemika/tasks/matrix.rb +4 -4
  32. data/lib/gemika/version.rb +1 -1
  33. data/spec/fixtures/github_actions_yml/Gemfile_without_gemika +1 -0
  34. data/spec/fixtures/github_actions_yml/excludes.yml +13 -0
  35. data/spec/fixtures/github_actions_yml/gemfile_without_gemika.yml +8 -0
  36. data/spec/fixtures/github_actions_yml/includes.yml +20 -0
  37. data/spec/fixtures/github_actions_yml/invalid.yml +8 -0
  38. data/spec/fixtures/github_actions_yml/missing_gemfile.yml +8 -0
  39. data/spec/fixtures/github_actions_yml/multiple_jobs.yml +16 -0
  40. data/spec/fixtures/github_actions_yml/two_by_two.yml +10 -0
  41. data/spec/fixtures/migrate/expected_github_actions.yml +129 -0
  42. data/spec/fixtures/migrate/travis.yml +66 -0
  43. data/spec/fixtures/travis_yml/includes.yml +12 -0
  44. data/spec/gemika/matrix_spec.rb +116 -0
  45. data/spec/spec_helper.rb +1 -0
  46. data/spec/support/database.github.yml +13 -0
  47. metadata +35 -19
  48. data/.travis.yml +0 -58
  49. data/gemfiles/Gemfile.2.3.mysql2 +0 -17
  50. data/gemfiles/Gemfile.2.3.mysql2.lock +0 -34
  51. data/spec/support/database.travis.yml +0 -9
  52. data/spec/support/database.yml +0 -10
@@ -1,3 +1,3 @@
1
1
  module Gemika
2
- VERSION = '0.3.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1,13 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby:
6
+ - "2.1.8"
7
+ - "2.3.1"
8
+ gemfile:
9
+ - gemfiles/Gemfile1
10
+ - gemfiles/Gemfile2
11
+ exclude:
12
+ - ruby: 2.1.8
13
+ gemfile: gemfiles/Gemfile1
@@ -0,0 +1,8 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby:
6
+ - 2.1.8
7
+ gemfile:
8
+ - spec/fixtures/travis_yml/Gemfile_without_gemika
@@ -0,0 +1,20 @@
1
+ matrix:
2
+ jobs:
3
+ first_job:
4
+ strategy:
5
+ matrix:
6
+ ruby:
7
+ - "2.1.8"
8
+ - "2.3.1"
9
+ gemfile:
10
+ - gemfiles/Gemfile1
11
+ - gemfiles/Gemfile2
12
+ include:
13
+ - ruby: 2.6.3
14
+ gemfile: gemfiles/Gemfile3
15
+ second_job:
16
+ strategy:
17
+ matrix:
18
+ include:
19
+ - ruby: 2.7.1
20
+ gemfile: gemfiles/Gemfile3
@@ -0,0 +1,8 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby_version:
6
+ - "2.1.8"
7
+ gemfile:
8
+ - gemfiles/Gemfile1
@@ -0,0 +1,8 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby:
6
+ - 2.1.8
7
+ gemfile:
8
+ - gemfiles/nonexisting_gemfile
@@ -0,0 +1,16 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby:
6
+ - "2.1.8"
7
+ gemfile:
8
+ - gemfiles/Gemfile1
9
+
10
+ second_job:
11
+ strategy:
12
+ matrix:
13
+ ruby:
14
+ - "2.3.1"
15
+ gemfile:
16
+ - gemfiles/Gemfile2
@@ -0,0 +1,10 @@
1
+ jobs:
2
+ first_job:
3
+ strategy:
4
+ matrix:
5
+ ruby:
6
+ - "2.1.8"
7
+ - "2.3.1"
8
+ gemfile:
9
+ - gemfiles/Gemfile1
10
+ - gemfiles/Gemfile2
@@ -0,0 +1,129 @@
1
+ name: Tests
2
+ 'on':
3
+ push:
4
+ branches:
5
+ - master
6
+ pull_request:
7
+ branches:
8
+ - master
9
+ jobs:
10
+ test_mysql:
11
+ runs-on: ubuntu-20.04
12
+ services:
13
+ mysql:
14
+ image: mysql:5.6
15
+ env:
16
+ MYSQL_ROOT_PASSWORD: password
17
+ options: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout
18
+ 5s --health-retries 5
19
+ ports:
20
+ - 3306:3306
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ include:
25
+ - ruby: 1.8.7
26
+ gemfile: Gemfile.2.3.mysql2
27
+ - ruby: 1.8.7
28
+ gemfile: Gemfile.3.2.mysql2
29
+ - ruby: 2.1.8
30
+ gemfile: Gemfile.3.2.mysql2
31
+ - ruby: 2.2.4
32
+ gemfile: Gemfile.3.2.mysql2
33
+ - ruby: 2.1.8
34
+ gemfile: Gemfile.4.2.mysql2
35
+ - ruby: 2.2.4
36
+ gemfile: Gemfile.4.2.mysql2
37
+ - ruby: 2.3.1
38
+ gemfile: Gemfile.4.2.mysql2
39
+ - ruby: 2.2.4
40
+ gemfile: Gemfile.5.2.mysql2
41
+ - ruby: 2.3.1
42
+ gemfile: Gemfile.5.2.mysql2
43
+ env:
44
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
45
+ steps:
46
+ - uses: actions/checkout@v2
47
+ - name: Install ruby
48
+ uses: ruby/setup-ruby@v1
49
+ with:
50
+ ruby-version: "${{ matrix.ruby }}"
51
+ - name: Setup database
52
+ run: |
53
+ sudo apt-get install -y mysql-client libmariadbclient-dev
54
+ mysql -e 'create database IF NOT EXISTS test;' -u root --password=password -P 3306 -h 127.0.0.1
55
+ - name: Bundle
56
+ run: |
57
+ gem install bundler:1.17.3
58
+ bundle install --no-deployment
59
+ - name: Run tests
60
+ run: bundle exec rspec
61
+ test_pg:
62
+ runs-on: ubuntu-20.04
63
+ services:
64
+ postgres:
65
+ image: postgres
66
+ env:
67
+ POSTGRES_PASSWORD: postgres
68
+ options: "--health-cmd pg_isready --health-interval 10s --health-timeout 5s
69
+ --health-retries 5"
70
+ ports:
71
+ - 5432:5432
72
+ strategy:
73
+ fail-fast: false
74
+ matrix:
75
+ include:
76
+ - ruby: 2.1.8
77
+ gemfile: Gemfile.4.2.pg
78
+ - ruby: 2.2.4
79
+ gemfile: Gemfile.4.2.pg
80
+ - ruby: 2.3.1
81
+ gemfile: Gemfile.4.2.pg
82
+ - ruby: 2.2.4
83
+ gemfile: Gemfile.5.2.pg
84
+ - ruby: 2.3.1
85
+ gemfile: Gemfile.5.2.pg
86
+ - ruby: 2.6.4
87
+ gemfile: Gemfile.6.0.pg
88
+ env:
89
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
90
+ steps:
91
+ - uses: actions/checkout@v2
92
+ - name: Install ruby
93
+ uses: ruby/setup-ruby@v1
94
+ with:
95
+ ruby-version: "${{ matrix.ruby }}"
96
+ - name: Setup database
97
+ run: |
98
+ sudo apt-get install -y postgresql-client
99
+ PGPASSWORD=postgres psql -c 'create database test;' -U postgres -p 5432 -h localhost
100
+ - name: Bundle
101
+ run: |
102
+ gem install bundler:1.17.3
103
+ bundle install --no-deployment
104
+ - name: Run tests
105
+ run: bundle exec rspec
106
+ test_sqlite:
107
+ runs-on: ubuntu-20.04
108
+ strategy:
109
+ fail-fast: false
110
+ matrix:
111
+ include:
112
+ - ruby: 2.2.4
113
+ gemfile: Gemfile.5.2.sqlite3
114
+ - ruby: 2.3.1
115
+ gemfile: Gemfile.5.2.sqlite3
116
+ env:
117
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
118
+ steps:
119
+ - uses: actions/checkout@v2
120
+ - name: Install ruby
121
+ uses: ruby/setup-ruby@v1
122
+ with:
123
+ ruby-version: "${{ matrix.ruby }}"
124
+ - name: Bundle
125
+ run: |
126
+ gem install bundler:1.17.3
127
+ bundle install --no-deployment
128
+ - name: Run tests
129
+ run: bundle exec rspec
@@ -0,0 +1,66 @@
1
+ language: ruby
2
+
3
+ dist: trusty
4
+
5
+ services:
6
+ - postgresql
7
+
8
+ matrix:
9
+ include:
10
+ # Rails 2.3
11
+ - gemfile: Gemfile.2.3.mysql2
12
+ rvm: 1.8.7
13
+ # Rails 3.2
14
+ - gemfile: Gemfile.3.2.mysql2
15
+ rvm: 1.8.7
16
+ - gemfile: Gemfile.3.2.mysql2
17
+ rvm: 2.1.8
18
+ - gemfile: Gemfile.3.2.mysql2
19
+ rvm: 2.2.4
20
+ # Rails 4.2
21
+ - gemfile: Gemfile.4.2.mysql2
22
+ rvm: 2.1.8
23
+ - gemfile: Gemfile.4.2.pg
24
+ rvm: 2.1.8
25
+ - gemfile: Gemfile.4.2.mysql2
26
+ rvm: 2.2.4
27
+ - gemfile: Gemfile.4.2.pg
28
+ rvm: 2.2.4
29
+ - gemfile: Gemfile.4.2.mysql2
30
+ rvm: 2.3.1
31
+ - gemfile: Gemfile.4.2.pg
32
+ rvm: 2.3.1
33
+ # Rails 5.2
34
+ - gemfile: Gemfile.5.2.mysql2
35
+ rvm: 2.2.4
36
+ - gemfile: Gemfile.5.2.pg
37
+ rvm: 2.2.4
38
+ - gemfile: Gemfile.5.2.sqlite3
39
+ rvm: 2.2.4
40
+ - gemfile: Gemfile.5.2.mysql2
41
+ rvm: 2.3.1
42
+ - gemfile: Gemfile.5.2.pg
43
+ rvm: 2.3.1
44
+ - gemfile: Gemfile.5.2.sqlite3
45
+ rvm: 2.3.1
46
+ # Rails 6.0
47
+ - gemfile: Gemfile.6.0.pg
48
+ rvm: 2.6.4
49
+
50
+ install:
51
+ # Replace default Travis CI bundler script with a version that doesn't
52
+ # explode when lockfile doesn't match recently bumped version
53
+ - bundle install --no-deployment --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
54
+
55
+ before_script:
56
+ - psql -c 'create database gemika_test;' -U postgres
57
+ - mysql -e 'create database IF NOT EXISTS gemika_test;'
58
+
59
+ script: bundle exec rake current_rspec
60
+
61
+ sudo: false
62
+
63
+ cache: bundler
64
+
65
+ addons:
66
+ postgresql: 9.3
@@ -0,0 +1,12 @@
1
+ rvm:
2
+ - 2.1.8
3
+ - 2.3.1
4
+
5
+ gemfile:
6
+ - gemfiles/Gemfile1
7
+ - gemfiles/Gemfile2
8
+
9
+ matrix:
10
+ include:
11
+ - rvm: 2.6.3
12
+ gemfile: gemfiles/Gemfile3
@@ -131,6 +131,22 @@ EOF
131
131
  matrix.rows[2].gemfile.should == 'gemfiles/Gemfile2'
132
132
  end
133
133
 
134
+ it 'allows to include rows to the matrix' do
135
+ path = 'spec/fixtures/travis_yml/includes.yml'
136
+ matrix = Gemika::Matrix.from_travis_yml(:path => path, :validate => false)
137
+ matrix.rows.size.should == 5
138
+ matrix.rows[0].ruby.should == '2.1.8'
139
+ matrix.rows[0].gemfile.should == 'gemfiles/Gemfile1'
140
+ matrix.rows[1].ruby.should == '2.1.8'
141
+ matrix.rows[1].gemfile.should == 'gemfiles/Gemfile2'
142
+ matrix.rows[2].ruby.should == '2.3.1'
143
+ matrix.rows[2].gemfile.should == 'gemfiles/Gemfile1'
144
+ matrix.rows[3].ruby.should == '2.3.1'
145
+ matrix.rows[3].gemfile.should == 'gemfiles/Gemfile2'
146
+ matrix.rows[4].ruby.should == '2.6.3'
147
+ matrix.rows[4].gemfile.should == 'gemfiles/Gemfile3'
148
+ end
149
+
134
150
  it 'raises an error if a Gemfile does not exist' do
135
151
  path = 'spec/fixtures/travis_yml/missing_gemfile.yml'
136
152
  expect { Gemika::Matrix.from_travis_yml(:path => path) }.to raise_error(Gemika::MissingGemfile, /gemfile not found/i)
@@ -143,4 +159,104 @@ EOF
143
159
 
144
160
  end
145
161
 
162
+ describe '.from_github_actions_yml' do
163
+
164
+ it 'builds a matrix by combining Ruby versions and gemfiles from a Github Actions workflow configuration file' do
165
+ path = 'spec/fixtures/github_actions_yml/two_by_two.yml'
166
+ matrix = Gemika::Matrix.from_github_actions_yml(:path => path, :validate => false)
167
+ matrix.rows.size.should == 4
168
+ matrix.rows[0].ruby.should == '2.1.8'
169
+ matrix.rows[0].gemfile.should == 'gemfiles/Gemfile1'
170
+ matrix.rows[1].ruby.should == '2.1.8'
171
+ matrix.rows[1].gemfile.should == 'gemfiles/Gemfile2'
172
+ matrix.rows[2].ruby.should == '2.3.1'
173
+ matrix.rows[2].gemfile.should == 'gemfiles/Gemfile1'
174
+ matrix.rows[3].ruby.should == '2.3.1'
175
+ matrix.rows[3].gemfile.should == 'gemfiles/Gemfile2'
176
+ end
177
+
178
+ it 'combines matrixes of multiple jobs' do
179
+ path = 'spec/fixtures/github_actions_yml/multiple_jobs.yml'
180
+ matrix = Gemika::Matrix.from_github_actions_yml(:path => path, :validate => false)
181
+ matrix.rows.size.should == 2
182
+ matrix.rows[0].ruby.should == '2.1.8'
183
+ matrix.rows[0].gemfile.should == 'gemfiles/Gemfile1'
184
+ matrix.rows[1].ruby.should == '2.3.1'
185
+ matrix.rows[1].gemfile.should == 'gemfiles/Gemfile2'
186
+ end
187
+
188
+ it 'allows to exclude rows from the matrix' do
189
+ path = 'spec/fixtures/github_actions_yml/excludes.yml'
190
+ matrix = Gemika::Matrix.from_github_actions_yml(:path => path, :validate => false)
191
+ matrix.rows.size.should == 3
192
+ matrix.rows[0].ruby.should == '2.1.8'
193
+ matrix.rows[0].gemfile.should == 'gemfiles/Gemfile2'
194
+ matrix.rows[1].ruby.should == '2.3.1'
195
+ matrix.rows[1].gemfile.should == 'gemfiles/Gemfile1'
196
+ matrix.rows[2].ruby.should == '2.3.1'
197
+ matrix.rows[2].gemfile.should == 'gemfiles/Gemfile2'
198
+ end
199
+
200
+ it 'allows to include rows to the matrix' do
201
+ path = 'spec/fixtures/github_actions_yml/includes.yml'
202
+ matrix = Gemika::Matrix.from_github_actions_yml(:path => path, :validate => false)
203
+ matrix.rows.size.should == 6
204
+ matrix.rows[0].ruby.should == '2.1.8'
205
+ matrix.rows[0].gemfile.should == 'gemfiles/Gemfile1'
206
+ matrix.rows[1].ruby.should == '2.1.8'
207
+ matrix.rows[1].gemfile.should == 'gemfiles/Gemfile2'
208
+ matrix.rows[2].ruby.should == '2.3.1'
209
+ matrix.rows[2].gemfile.should == 'gemfiles/Gemfile1'
210
+ matrix.rows[3].ruby.should == '2.3.1'
211
+ matrix.rows[3].gemfile.should == 'gemfiles/Gemfile2'
212
+ matrix.rows[4].ruby.should == '2.6.3'
213
+ matrix.rows[4].gemfile.should == 'gemfiles/Gemfile3'
214
+ matrix.rows[5].ruby.should == '2.7.1'
215
+ matrix.rows[5].gemfile.should == 'gemfiles/Gemfile3'
216
+ end
217
+
218
+ it 'complains about missing keys' do
219
+ path = 'spec/fixtures/github_actions_yml/invalid.yml'
220
+ expect { Gemika::Matrix.from_github_actions_yml(:path => path) }.to raise_error(Gemika::InvalidMatrixDefinition)
221
+ end
222
+
223
+ it 'raises an error if a Gemfile does not exist' do
224
+ path = 'spec/fixtures/github_actions_yml/missing_gemfile.yml'
225
+ expect { Gemika::Matrix.from_github_actions_yml(:path => path) }.to raise_error(Gemika::MissingGemfile, /gemfile not found/i)
226
+ end
227
+
228
+ it 'raises an error if a Gemfile does not depend on "gemika"' do
229
+ path = 'spec/fixtures/github_actions_yml/gemfile_without_gemika.yml'
230
+ expect { Gemika::Matrix.from_github_actions_yml(:path => path) }.to raise_error(Gemika::UnusableGemfile, /missing gemika dependency/i)
231
+ end
232
+
233
+ end
234
+
235
+ describe '.from_ci_config' do
236
+ it 'parses the .travis.yml if it exists' do
237
+ File.should_receive(:exists?).with('.travis.yml').and_return(true)
238
+ Gemika::Matrix.should_receive(:from_travis_yml).and_return('travis matrix')
239
+ Gemika::Matrix.from_ci_config.should == 'travis matrix'
240
+ end
241
+
242
+ it 'parses the .github/workflows/test.yml if it exists' do
243
+ File.should_receive(:exists?).with('.travis.yml').and_return(false)
244
+ File.should_receive(:exists?).with('.github/workflows/test.yml').and_return(true)
245
+ Gemika::Matrix.should_receive(:from_github_actions_yml).and_return('github matrix')
246
+ Gemika::Matrix.from_ci_config.should == 'github matrix'
247
+ end
248
+
249
+ it 'raises an error if no ci definition exists' do
250
+ File.should_receive(:exists?).with('.travis.yml').and_return(false)
251
+ File.should_receive(:exists?).with('.github/workflows/test.yml').and_return(false)
252
+ expect { Gemika::Matrix.from_ci_config }.to raise_error(Gemika::MissingMatrixDefinition)
253
+ end
254
+ end
255
+
256
+ describe '.generate_github_actions_workflow' do
257
+ github_actions_workflow = Gemika::Matrix.generate_github_actions_workflow(path: 'spec/fixtures/migrate/travis.yml')
258
+ expected_github_actions_workflow = YAML.load_file('spec/fixtures/migrate/expected_github_actions.yml')
259
+ github_actions_workflow.should == expected_github_actions_workflow
260
+ end
261
+
146
262
  end
@@ -2,6 +2,7 @@ $: << File.join(File.dirname(__FILE__), "/../../lib" )
2
2
 
3
3
  require 'active_record'
4
4
  require 'gemika'
5
+ require 'pry'
5
6
 
6
7
  ActiveRecord::Base.default_timezone = :local
7
8