travis_check_rubies 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a243f7a9ee9c49601007f8f17c7aba32dd69203521976ecbc5a14887c46e54db
4
- data.tar.gz: 9a409034a7d17c73f43b1209ffb25b1322cb80fa055d982b0cadc36c1f1766f6
3
+ metadata.gz: 15957908f03062b38d455967278099f4dfe2c238b776dd7b857085b65d8a2874
4
+ data.tar.gz: c669a1631123c15e642b57c62a1c50a0ce9a00aa538a9382604fb4f57680f7d2
5
5
  SHA512:
6
- metadata.gz: 2001eaef85bfee1bbfb69eab2d5c06716c74abd711e801d227a23ab1f99325b9b08fe1bd973dc3190f5c11c8b37eb352f33bb6a88c77b7c349e1110ade2199be
7
- data.tar.gz: 60e6630469d3ae1af191e61c92eb15b4048f3cbe7abd4345e3547170a351e3510de63b02702de27942146a5c70d59ff12e907214932e688a2729395dbde0bf20
6
+ metadata.gz: 860cbc5c33ecf76f270430024f3c0d6e352431b0b095b7fb011214a57e60f5b0b57297b009f5792b6795968430458d8aeeb5ac6edd77350e9d465a754b50ff42
7
+ data.tar.gz: '08a6fe9982b9d32b29b063585574655d6f24ec5e4539ae079d61f8e1c0d0ad6f0a568ab5b53c284b16c452401d997bad4723de3d29576445b39ac6473b8cfe10'
@@ -1,11 +1,13 @@
1
1
  sudo: false
2
+ dist: trusty
2
3
  language: ruby
3
4
  rvm:
4
5
  - '2.3.8'
5
- - '2.4.6'
6
- - '2.5.5'
7
- - '2.6.2'
8
- - 'jruby-9.1.9.0'
6
+ - '2.4.7'
7
+ - '2.5.6'
8
+ - '2.6.4'
9
+ - 'jruby-9.1.17.0'
10
+ - 'jruby-9.2.7.0'
9
11
  before_script:
10
12
  - env
11
13
  - rvm debug
@@ -1,4 +1,4 @@
1
- require 'travis_check_rubies/version'
1
+ require_relative 'travis_check_rubies/version'
2
2
 
3
3
  module TravisCheckRubies
4
4
  end
@@ -0,0 +1,44 @@
1
+ require 'digest'
2
+ require 'fspath'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module TravisCheckRubies
7
+ class Fetcher
8
+ CACHE_TIME = 24 * 60 * 60
9
+
10
+ attr_reader :url
11
+
12
+ def initialize(url)
13
+ @url = url
14
+ end
15
+
16
+ def data
17
+ cached_data || fetch_data
18
+ end
19
+
20
+ private
21
+
22
+ def cache_path
23
+ @cache_path ||= FSPath(ENV['XDG_CACHE_HOME'] || '~/.cache').expand_path / "travis_check_rubies.#{Digest::SHA1.hexdigest url}"
24
+ end
25
+
26
+ def cached_data
27
+ return unless cache_path.size?
28
+ return unless cache_path.mtime + CACHE_TIME > Time.now
29
+ cache_path.read
30
+ end
31
+
32
+ def fetch_data
33
+ data = Net::HTTP.get(URI(url))
34
+
35
+ cache_path.dirname.mkpath
36
+ FSPath.temp_file('travis_check_rubies', cache_path.dirname) do |f|
37
+ f.write(data)
38
+ f.path.rename(cache_path)
39
+ end
40
+
41
+ data
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'fetcher'
2
+
3
+ module TravisCheckRubies
4
+ class RvmIndex
5
+ URL = 'https://raw.githubusercontent.com/rvm/rvm/stable/config/known_strings'
6
+
7
+ def version_strings
8
+ TravisCheckRubies::Fetcher.new(URL).data.split("\n")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'fetcher'
2
+
3
+ module TravisCheckRubies
4
+ class TravisIndex
5
+ ROOT_URL = 'https://rubies.travis-ci.org/'
6
+
7
+ def version_strings
8
+ index_urls.select do |url|
9
+ url.start_with?(base_url)
10
+ end.map do |url|
11
+ url[%r{([^/]+)\.tar\.(?:gz|bz2)$}, 1]
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def index_urls
18
+ @index_urls ||= TravisCheckRubies::Fetcher.new(ROOT_URL + 'index.txt').data.split("\n")
19
+ end
20
+
21
+ def base_url
22
+ @base_url ||= if ENV['TRAVIS']
23
+ sys_path = `rvm debug`[/(?:system|remote.path):\s*"(.*?)"/, 1]
24
+ "#{ROOT_URL}#{sys_path}/"
25
+ else
26
+ base_ubuntu_url = "#{ROOT_URL}ubuntu/"
27
+ first_ubuntu_url = index_urls.sort.find{ |url| url.start_with?(base_ubuntu_url) }
28
+ fail "First ubuntu url (#{ROOT_URL}ubuntu/*) not fount out of:\n#{index_urls.join("\n")}" unless first_ubuntu_url
29
+ first_ubuntu_url[%r{^.*/}]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,8 @@
1
1
  require 'fspath'
2
2
  require 'yaml'
3
- require 'travis_check_rubies/updater'
4
- require 'travis_check_rubies/version'
3
+
4
+ require_relative 'updater'
5
+ require_relative 'version'
5
6
 
6
7
  module TravisCheckRubies
7
8
  class TravisYml
@@ -1,26 +1,17 @@
1
- require 'net/http'
2
- require 'fspath'
3
1
  require 'set'
4
- require 'uri'
2
+
3
+ require_relative 'rvm_index'
4
+ require_relative 'travis_index'
5
5
 
6
6
  module TravisCheckRubies
7
7
  class Version
8
- ROOT_URL = 'https://rubies.travis-ci.org/'
9
- CACHE_TIME = 24 * 60 * 60
10
-
11
8
  class << self
12
9
  def convert(version_or_string)
13
10
  version_or_string.is_a?(self) ? version_or_string : new(version_or_string)
14
11
  end
15
12
 
16
13
  def available
17
- @available ||= begin
18
- index_urls.select do |url|
19
- url.start_with?(base_url)
20
- end.map do |url|
21
- new(url[%r{([^/]+)\.tar\.(?:gz|bz2)$}, 1])
22
- end.sort
23
- end
14
+ @available ||= [TravisIndex, RvmIndex].map(&:new).map(&:version_strings).inject(:|).map{ |s| new(s) }.sort
24
15
  end
25
16
 
26
17
  def update(version, parts: 0..2, allow_pre: false, intermediary: true, exclude: [], conservative: false)
@@ -72,47 +63,6 @@ module TravisCheckRubies
72
63
 
73
64
  Hash[versions.map{ |v| [v, updates[v]] }]
74
65
  end
75
-
76
- private
77
-
78
- def cache_path
79
- @cache_path ||= FSPath(ENV['XDG_CACHE_HOME'] || '~/.cache').expand_path / 'travis_check_rubies.txt'
80
- end
81
-
82
- def index_urls
83
- @index_urls ||= (cached_index_data || fetch_index_data).split("\n")
84
- end
85
-
86
- def cached_index_data
87
- return unless cache_path.size?
88
- return unless cache_path.mtime + CACHE_TIME > Time.now
89
- data = cache_path.read
90
- data if data.start_with?(ROOT_URL)
91
- end
92
-
93
- def fetch_index_data
94
- data = Net::HTTP.get(URI(ROOT_URL + 'index.txt'))
95
-
96
- cache_path.dirname.mkpath
97
- FSPath.temp_file('travis_check_rubies', cache_path.dirname) do |f|
98
- f.write(data)
99
- f.path.rename(cache_path)
100
- end
101
-
102
- data
103
- end
104
-
105
- def base_url
106
- @base_url ||= if ENV['TRAVIS']
107
- sys_path = `rvm debug`[/(?:system|remote.path):\s*"(.*?)"/, 1]
108
- "#{ROOT_URL}#{sys_path}/"
109
- else
110
- base_ubuntu_url = "#{ROOT_URL}ubuntu/"
111
- first_ubuntu_url = index_urls.sort.find{ |url| url.start_with?(base_ubuntu_url) }
112
- fail "First ubuntu url (#{ROOT_URL}ubuntu/*) not fount out of:\n#{index_urls.join("\n")}" unless first_ubuntu_url
113
- first_ubuntu_url[%r{^.*/}]
114
- end
115
- end
116
66
  end
117
67
 
118
68
  include Comparable
@@ -0,0 +1,48 @@
1
+ require 'rspec'
2
+ require 'travis_check_rubies/fetcher'
3
+
4
+ describe TravisCheckRubies::Fetcher do
5
+ describe '#data' do
6
+ subject{ described_class.new(url) }
7
+
8
+ let(:url){ 'https://example.com/index.txt' }
9
+ let(:cache_path){ FSPath.temp_file_path }
10
+
11
+ before do
12
+ allow(subject).to receive(:cache_path).and_return(cache_path)
13
+ end
14
+
15
+ it 'returns data from url' do
16
+ allow(Net::HTTP).to receive(:get).with(URI(url)).
17
+ and_return("one\ntwo\nthree")
18
+
19
+ expect(subject.data).to eq("one\ntwo\nthree")
20
+ end
21
+
22
+ it 'caches result' do
23
+ allow(Net::HTTP).to receive(:get).with(URI(url)).
24
+ once.and_return("a\nb\nc")
25
+
26
+ 3.times{ expect(subject.data).to eq("a\nb\nc") }
27
+ end
28
+
29
+ it 'reads cache from file if it is new' do
30
+ cache_path.write "foo\nbar"
31
+ allow(cache_path).to receive(:size?).and_return(616)
32
+ allow(cache_path).to receive(:mtime).and_return(Time.now - described_class::CACHE_TIME / 2)
33
+
34
+ expect(Net::HTTP).not_to receive(:get)
35
+ expect(subject.data).to eq("foo\nbar")
36
+ end
37
+
38
+ it 'writes cache file if it is stale' do
39
+ allow(cache_path).to receive(:size?).and_return(616)
40
+ allow(cache_path).to receive(:mtime).and_return(Time.now - described_class::CACHE_TIME * 2)
41
+ allow(Net::HTTP).to receive(:get).with(URI(url)).
42
+ once.and_return("brave\nnew\nworld")
43
+
44
+ expect(subject.data).to eq("brave\nnew\nworld")
45
+ expect(cache_path.read).to eq("brave\nnew\nworld")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,50 @@
1
+ require 'rspec'
2
+ require 'travis_check_rubies/travis_index'
3
+
4
+ describe TravisCheckRubies::TravisIndex do
5
+ describe '#base_url' do
6
+ before do
7
+ allow(ENV).to receive(:[]).with('TRAVIS').and_return(env_travis)
8
+ end
9
+
10
+ context 'when env variable TRAVIS is set' do
11
+ let(:env_travis){ 'true' }
12
+
13
+ it 'gets base_url from rvm debug' do
14
+
15
+ allow(subject).to receive(:`).with('rvm debug').
16
+ and_return(%Q{ foo: "xxx" \n system: "XXX/YYY" \n bar: "yyy" })
17
+
18
+ expect(subject.send(:base_url)).to eq('https://rubies.travis-ci.org/XXX/YYY/')
19
+ end
20
+ end
21
+
22
+ context 'when env variable TRAVIS is not set' do
23
+ let(:env_travis){ nil }
24
+
25
+ it 'gets base_url from first ubuntu url in index' do
26
+ allow(subject).to receive(:index_urls).and_return(%w[
27
+ https://rubies.travis-ci.org/osx/AAA/1.tar.gz
28
+ https://rubies.travis-ci.org/ubuntu/ZZZ/2.tar.gz
29
+ https://rubies.travis-ci.org/ubuntu/BBB/3.tar.gz
30
+ ])
31
+
32
+ expect(subject.send(:base_url)).to eq('https://rubies.travis-ci.org/ubuntu/BBB/')
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#version_strings' do
38
+ it 'gets versions from index urls matching base_url' do
39
+ allow(subject).to receive(:index_urls).and_return(%w[
40
+ https://rubies.travis-ci.org/osx/AAA/1.tar.gz
41
+ https://rubies.travis-ci.org/ubuntu/ZZZ/2.tar.gz
42
+ https://rubies.travis-ci.org/ubuntu/BBB/4.tar.gz
43
+ https://rubies.travis-ci.org/ubuntu/BBB/3.tar.bz2
44
+ ])
45
+ allow(subject).to receive(:base_url).and_return('https://rubies.travis-ci.org/ubuntu/BBB/')
46
+
47
+ expect(subject.version_strings).to match_array(%w[3 4])
48
+ end
49
+ end
50
+ end
@@ -10,12 +10,6 @@ describe TravisCheckRubies::Version do
10
10
  strs.map{ |str| described_class.new(str) }
11
11
  end
12
12
 
13
- def cleanup_instance_variables(o)
14
- o.instance_variables.each do |name|
15
- o.remove_instance_variable(name)
16
- end
17
- end
18
-
19
13
  describe 'parsing' do
20
14
  {
21
15
  '1.2.3-pre1' => {
@@ -202,116 +196,12 @@ describe TravisCheckRubies::Version do
202
196
  end
203
197
  end
204
198
 
205
- describe '.index_urls' do
206
- let(:cache_path){ FSPath.temp_file_path }
207
-
208
- before do
209
- cleanup_instance_variables(described_class)
210
- allow(described_class).to receive(:cache_path).and_return(cache_path)
211
- end
212
-
213
- it 'returns urls from text index of rubies.travis-ci.org' do
214
- allow(Net::HTTP).to receive(:get).with(URI('https://rubies.travis-ci.org/index.txt')).
215
- and_return("one\ntwo\nthree")
216
-
217
- expect(described_class.send(:index_urls)).to eq(%w[one two three])
218
- end
219
-
220
- it 'caches result' do
221
- allow(Net::HTTP).to receive(:get).with(URI('https://rubies.travis-ci.org/index.txt')).
222
- once.and_return("a\nb\nc")
223
-
224
- 3.times{ expect(described_class.send(:index_urls)).to eq(%w[a b c]) }
225
- end
226
-
227
- it 'reads cache from file if it is new' do
228
- cache_path.write "https://rubies.travis-ci.org/foo"
229
- allow(cache_path).to receive(:size?).and_return(616)
230
- allow(cache_path).to receive(:mtime).and_return(Time.now - described_class::CACHE_TIME / 2)
231
-
232
- expect(Net::HTTP).not_to receive(:get)
233
- expect(described_class.send(:index_urls)).to eq(%w[https://rubies.travis-ci.org/foo])
234
- end
235
-
236
- it 'ignores bad cache' do
237
- cache_path.write "http://rubies.travis-ci.org/foo"
238
- allow(cache_path).to receive(:size?).and_return(616)
239
- allow(cache_path).to receive(:mtime).and_return(Time.now - described_class::CACHE_TIME / 2)
240
-
241
- allow(Net::HTTP).to receive(:get).with(URI('https://rubies.travis-ci.org/index.txt')).
242
- once.and_return("brave\nnew\nworld")
243
- expect(described_class.send(:index_urls)).to eq(%w[brave new world])
244
- expect(cache_path.read).to eq("brave\nnew\nworld")
245
- end
246
-
247
- it 'writes cache file if it is stale' do
248
- allow(cache_path).to receive(:size?).and_return(616)
249
- allow(cache_path).to receive(:mtime).and_return(Time.now - described_class::CACHE_TIME * 2)
250
- allow(Net::HTTP).to receive(:get).with(URI('https://rubies.travis-ci.org/index.txt')).
251
- once.and_return("brave\nnew\nworld")
252
-
253
- expect(described_class.send(:index_urls)).to eq(%w[brave new world])
254
- expect(cache_path.read).to eq("brave\nnew\nworld")
255
- end
256
- end
257
-
258
- describe '.base_url' do
259
- before do
260
- cleanup_instance_variables(described_class)
261
- allow(ENV).to receive(:[]).with('TRAVIS').and_return(env_travis)
262
- end
263
-
264
- context 'when env variable TRAVIS is set' do
265
- let(:env_travis){ 'true' }
266
-
267
- it 'gets base_url from rvm debug' do
268
- allow(described_class).to receive(:`).with('rvm debug').
269
- and_return(%Q{ foo: "xxx" \n system: "XXX/YYY" \n bar: "yyy" })
270
-
271
- expect(described_class.send(:base_url)).to eq('https://rubies.travis-ci.org/XXX/YYY/')
272
- end
273
- end
274
-
275
- context 'when env variable TRAVIS is not set' do
276
- let(:env_travis){ nil }
277
-
278
- it 'gets base_url from first ubuntu url in index' do
279
- allow(described_class).to receive(:index_urls).and_return(%w[
280
- https://rubies.travis-ci.org/osx/AAA/1.tar.gz
281
- https://rubies.travis-ci.org/ubuntu/ZZZ/2.tar.gz
282
- https://rubies.travis-ci.org/ubuntu/BBB/3.tar.gz
283
- ])
284
-
285
- expect(described_class.send(:base_url)).to eq('https://rubies.travis-ci.org/ubuntu/BBB/')
286
- end
287
- end
288
- end
289
-
290
199
  describe '.available' do
291
- before do
292
- cleanup_instance_variables(described_class)
293
- end
294
-
295
- it 'gets sorted versions from index urls matching base_url' do
296
- allow(described_class).to receive(:index_urls).and_return(%w[
297
- https://rubies.travis-ci.org/osx/AAA/1.tar.gz
298
- https://rubies.travis-ci.org/ubuntu/ZZZ/2.tar.gz
299
- https://rubies.travis-ci.org/ubuntu/BBB/4.tar.gz
300
- https://rubies.travis-ci.org/ubuntu/BBB/3.tar.bz2
301
- ])
302
- allow(described_class).to receive(:base_url).and_return('https://rubies.travis-ci.org/ubuntu/BBB/')
303
-
304
- expect(described_class.available).to eq([v('3'), v('4')])
305
- end
306
-
307
- it 'caches result' do
308
- allow(described_class).to receive(:index_urls).once.and_return(%w[
309
- https://rubies.travis-ci.org/ubuntu/CCC/a.tar.gz
310
- https://rubies.travis-ci.org/ubuntu/CCC/b.tar.bz2
311
- ])
312
- allow(described_class).to receive(:base_url).and_return('https://rubies.travis-ci.org/ubuntu/CCC/')
200
+ it 'gets distinct sorted versions by combining indexes' do
201
+ allow(TravisCheckRubies::TravisIndex).to receive(:new).and_return(double(version_strings: %w[e d c b a]))
202
+ allow(TravisCheckRubies::RvmIndex).to receive(:new).and_return(double(version_strings: %w[d e f g h]))
313
203
 
314
- 3.times{ expect(described_class.available).to eq([v('a'), v('b')]) }
204
+ expect(described_class.available).to eq(vs(%w[a b c d e f g h]))
315
205
  end
316
206
  end
317
207
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'travis_check_rubies'
5
- s.version = '0.4.0'
5
+ s.version = '0.5.0'
6
6
  s.summary = 'Are you using the latest rubies in .travis.yml?'
7
7
  s.description = 'Check if `.travis.yml` specifies latest available rubies from listed on https://rubies.travis-ci.org and propose changes'
8
8
  s.homepage = "http://github.com/toy/#{s.name}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis_check_rubies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fspath
@@ -67,9 +67,14 @@ files:
67
67
  - README.markdown
68
68
  - bin/travis_check_rubies
69
69
  - lib/travis_check_rubies.rb
70
+ - lib/travis_check_rubies/fetcher.rb
71
+ - lib/travis_check_rubies/rvm_index.rb
72
+ - lib/travis_check_rubies/travis_index.rb
70
73
  - lib/travis_check_rubies/travis_yml.rb
71
74
  - lib/travis_check_rubies/updater.rb
72
75
  - lib/travis_check_rubies/version.rb
76
+ - spec/travis_check_rubies/fetcher_spec.rb
77
+ - spec/travis_check_rubies/travis_index_spec.rb
73
78
  - spec/travis_check_rubies/updater_spec.rb
74
79
  - spec/travis_check_rubies/version_spec.rb
75
80
  - travis_check_rubies.gemspec
@@ -78,7 +83,7 @@ licenses:
78
83
  - MIT
79
84
  metadata:
80
85
  bug_tracker_uri: https://github.com/toy/travis_check_rubies/issues
81
- documentation_uri: https://www.rubydoc.info/gems/travis_check_rubies/0.4.0
86
+ documentation_uri: https://www.rubydoc.info/gems/travis_check_rubies/0.5.0
82
87
  source_code_uri: https://github.com/toy/travis_check_rubies
83
88
  post_install_message:
84
89
  rdoc_options: []
@@ -95,10 +100,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
100
  - !ruby/object:Gem::Version
96
101
  version: '0'
97
102
  requirements: []
98
- rubygems_version: 3.0.3
103
+ rubygems_version: 3.0.6
99
104
  signing_key:
100
105
  specification_version: 4
101
106
  summary: Are you using the latest rubies in .travis.yml?
102
107
  test_files:
108
+ - spec/travis_check_rubies/fetcher_spec.rb
109
+ - spec/travis_check_rubies/travis_index_spec.rb
103
110
  - spec/travis_check_rubies/updater_spec.rb
104
111
  - spec/travis_check_rubies/version_spec.rb