recent_ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70acf82ea562f877b9336246857d9fa430da031ecce7b2a33177b7466842644c
4
- data.tar.gz: 8d7877f3335bc076ed310f466380a81fdca866f4cdad92afba1a2531d60327de
3
+ metadata.gz: a626dae98bcb8ac0b68c2089454706ffcee4a319eee7559f19b7ec918b3c84e1
4
+ data.tar.gz: 816502e54a5bfd77e5ee6386a8c50197a5edf307949f4ca6ce421c343e904154
5
5
  SHA512:
6
- metadata.gz: a04056344a2af842976c31397df0b77e462421afe60b333ed7cb4d286eb8a0ec9d24ea3e57f7411971cdd1289fd8e68ab3ddd9542b50e4ba1a752de403f315c2
7
- data.tar.gz: e075082df5ef0d07fec859ee3f168961fbc889c65acfe85f918f784a81da9abb89014dadedb9b5599e8e86847a28dc33f5f4c4fd7d5195b55f4c973e2cdd0362
6
+ metadata.gz: 4c5a2ccb5f8315f8d7185162fb78cf58e1240a6276225319427608e4a542c382133e529bb625a4a8dbb8fb4cefcbbbb057f767879193054706843b24af6696ea
7
+ data.tar.gz: 01c25327c51eaa090c9c314a57593060f8354871b3f391133c214e1587abd5ee51f99c5f3c440bdc5b76e3737b85d58df89eee4feee9e91ae7c0696876496baf
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Recent Ruby
2
2
 
3
- This script takes a Ruby version number, compares it to all available Ruby versions, and throws an error unless the supplied version number contains the latest security patches.
3
+ This script takes a Ruby version number, compares it to all available Ruby versions, and throws an error unless the supplied version number contains the latest security patches. Put it in your build pipeline and you'll never deploy an app to an unpatched Ruby again.
4
4
 
5
5
  ## Why
6
6
 
7
- Heroku (and other platforms) use the Gemfile to determine which version of Ruby to use. This means, whenever a Ruby vulnerability is found, you need to personally update your Gemfile in order to be safe. This also means you need to pay close attention to the Ruby security notices. On smaller teams, this is often overlooked.
7
+ Heroku (and other platforms) use the Gemfile to determine which version of Ruby to use. This means, whenever a Ruby vulnerability is found, you need to update your Gemfile in order to be safe. More importantly it means you need to pay close attention to the Ruby security notices. On smaller teams, this is often overlooked.
8
8
 
9
- For Ruby gems, you can use Brakeman or Hakiri or Github itself to stay up-to-date with security patches. For your Ruby version, you can now use Recent Ruby.
9
+ For gems, you can use Brakeman or Hakiri or Github itself to stay up-to-date with security patches. For your Ruby version, you can now use Recent Ruby.
10
10
 
11
11
  ## Installation
12
12
 
@@ -24,25 +24,33 @@ gem 'recent_ruby', require: false
24
24
 
25
25
  ## Usage
26
26
 
27
- Just add Recent Ruby in your CI/CD build process, wherever you would put Rubocop or Brakeman. Recent Ruby can check either your Gemfile, or whatever is supplied as a command line argument, and checks if that version of Ruby is the most recent TEENY/PATCH release for that minor version. It also makes sure that your minor version is not End-of-Life yet. If your version of Ruby does happen to be out of date and potentially insecure, it exits with status code 1. This means you can simply drop it into your .circle.yml or your Semaphore build step, or wherever you usually put these things.
27
+ Just add Recent Ruby in your CI/CD build process, wherever you would put Rubocop or Brakeman. Recent Ruby can check either your Gemfile, or whatever is supplied as a command line argument, and checks if that version of Ruby is the most recent TEENY/PATCH release for that minor version.
28
+
29
+ It also makes sure that your minor version is not End-of-Life yet. If your version of Ruby does happen to be out of date and potentially insecure, it exits with status code 1. This means you can simply drop it into your .circle.yml or your Semaphore build step, or wherever you usually put these things.
28
30
 
29
31
  ## Examples
30
32
 
31
- Version number supplied on command line (2.3.7 was the latest 2.3 release at the time of this writing):
33
+ Outdated version number supplied on command line (2.3.7 was the latest 2.3 release at the time of this writing):
32
34
 
33
35
  ```
34
36
  $ recent_ruby --version-string 2.3.1
35
37
  Downloading latest list of Rubies from Github...
36
38
  Comparing version numbers...
37
39
  Current version is 2.3.1, but the latest patch release for 2.3 is 2.3.7!
40
+ ```
38
41
 
42
+ Latest release for 2.3:
43
+ ```
39
44
  $ recent_ruby --version-string 2.3.7
40
45
  Downloading latest list of Rubies from Github...
41
46
  Comparing version numbers...
42
47
  Downloading details for 2.3.7...
43
48
  Checking EOL status...
44
49
  Ruby version check completed successfully.
50
+ ```
45
51
 
52
+ Latest release for 2.0, which is End-of-Life (no longer getting security patches):
53
+ ```
46
54
  $ recent_ruby --version-string 2.0.0-p648
47
55
  Downloading latest list of Rubies from Github...
48
56
  Comparing version numbers...
@@ -67,6 +75,16 @@ Comparing version numbers...
67
75
  Current version is 2.3.3, but the latest patch release for 2.3 is 2.3.7!
68
76
  ```
69
77
 
78
+ Build steps I use on in the project settings on SemaphoreCI:
79
+
80
+ ```
81
+ # Setup:
82
+ gem install recent_ruby --no-rdoc --no-ri
83
+
84
+ # Build:
85
+ recent_ruby --gemfile Gemfile
86
+ ```
87
+
70
88
  ## How
71
89
 
72
90
  If `--gemfile` was supplied, we use the parser gem to extract the Ruby version from the Gemfile.
@@ -77,4 +95,13 @@ Since the ruby-build repository is well maintained and used in production by man
77
95
 
78
96
  ## Contributing
79
97
 
80
- Feel free to create issues for any problems you may have. Patches are welcome, especially if they come with a Cucumber scenario.
98
+ Feel free to create issues for any problems you may have. Patches are welcome, especially if they come with a Cucumber scenario.
99
+
100
+ ## Contributors
101
+
102
+ - Lucas Luitjes
103
+ - Cedric Hartskeerl
104
+
105
+ ## License
106
+
107
+ This project is MIT licensed.
@@ -1,7 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'recent_ruby/version'
2
4
  require 'recent_ruby/xml_ast'
3
5
 
4
6
  module RecentRuby
7
+ RUBY_NODE_XPATH = "//send[symbol-val[@value='ruby']]"
8
+ VERSION_XPATH = "#{RUBY_NODE_XPATH}/str/string-val/@value"
9
+ PATCHLEVEL_XPATH = "#{RUBY_NODE_XPATH}/hash/pair[sym[symbol-val[@value='patchlevel']]]"
10
+ PATCHLEVEL_VALUE_XPATH = "#{PATCHLEVEL_XPATH}/int/integer-val/@value"
11
+
5
12
  def http_get(url)
6
13
  uri = URI(url)
7
14
  Net::HTTP.start(uri.host, uri.port,
@@ -29,19 +36,21 @@ module RecentRuby
29
36
  def parse_gemfile(gemfile)
30
37
  ast = Parser::CurrentRuby.parse(File.read(gemfile))
31
38
  xml = RecentRuby::XMLAST.new(ast)
32
- version = xml.xpath("//send[symbol-val[@value='ruby']]/str/string-val/@value") || [nil]
33
- version = version.first ? version.first.value : nil
39
+ version = xml.xpath(VERSION_XPATH)&.first&.value
34
40
  unless version
35
41
  puts 'Unable to find ruby version in gemfile.'
36
42
  exit(1)
37
43
  end
44
+
45
+ patchlevel = xml.xpath(PATCHLEVEL_VALUE_XPATH)&.first&.value
46
+ version += "-p#{patchlevel}" if patchlevel
38
47
  version
39
48
  end
40
49
 
41
50
  def validate_mri_version(version)
42
51
  return if version =~ /^(\d+\.\d+\.\d+(-p\d+)?)$/
43
- puts 'Only stable release MRI version strings are currently supported. (e.g. 2.3.1 or 2.3.1-p12)'
44
- exit(1)
52
+ puts 'Only stable release MRI version strings are currently supported. (e.g. 2.3.1 or 2.3.1-p12)'
53
+ exit(1)
45
54
  end
46
55
 
47
56
  def get_rubies(versions_url)
@@ -1,3 +1,3 @@
1
1
  module RecentRuby
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -1,55 +1,60 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'parser/current'
2
4
  require 'rexml/document'
3
5
 
4
6
  module RecentRuby
5
-
6
- # Class comes from: https://medium.com/rubyinside/using-xpath-to-rewrite-ruby-code-with-ease-8f635af65b5b
7
- # TODO: turn into a separate gem
8
-
9
- class XMLAST
10
- include REXML
11
- attr_reader :doc
12
-
13
- def initialize sexp
14
- @doc = Document.new "<root></root>"
15
- @sexp = sexp
16
- root = @doc.root
17
- populate_tree(root, sexp)
18
- end
19
-
20
- def populate_tree xml, sexp
21
- if sexp.is_a?(String) ||
22
- sexp.is_a?(Symbol) ||
23
- sexp.is_a?(Numeric) ||
24
- sexp.is_a?(NilClass)
25
- el = Element.new(sexp.class.to_s.downcase + "-val")
26
- el.add_attribute 'value', sexp.to_s
27
- xml.add_element el
28
- else
29
- el = Element.new(sexp.type.to_s)
30
- el.add_attribute('id', sexp.object_id)
31
-
32
- sexp.children.each{ |n| populate_tree(el, n) }
33
- xml.add_element el
34
- end
35
- end
36
-
37
- def treewalk sexp=@sexp
38
- return sexp unless sexp&.respond_to?(:children)
39
- [sexp, sexp.children.map {|n| treewalk(n) }].flatten
40
- end
41
-
42
- def xpath path
43
- results = XPath.match(doc, path)
44
- results.map do |n|
45
- if n.respond_to?(:attributes) && n.attributes['id']
46
- treewalk.find do |m|
47
- m.object_id.to_s == n.attributes['id']
48
- end
49
- else
50
- n
51
- end
52
- end
53
- end
54
- end
7
+ # Class comes from: https://medium.com/rubyinside/using-xpath-to-rewrite-ruby-code-with-ease-8f635af65b5b
8
+ # TODO: turn into a separate gem
9
+
10
+ class XMLAST
11
+ include REXML
12
+ attr_reader :doc
13
+
14
+ def initialize(sexp)
15
+ @doc = Document.new '<root></root>'
16
+ @sexp = sexp
17
+ root = @doc.root
18
+ populate_tree(root, sexp)
19
+ end
20
+
21
+ def populate_tree(xml, sexp)
22
+ if sexp.is_a?(String) ||
23
+ sexp.is_a?(Symbol) ||
24
+ sexp.is_a?(Numeric) ||
25
+ sexp.is_a?(NilClass)
26
+ el = Element.new(sexp.class.to_s.downcase + '-val')
27
+ el.add_attribute 'value', sexp.to_s
28
+ xml.add_element el
29
+ else
30
+ el = Element.new(sexp.type.to_s)
31
+ el.add_attribute('id', sexp.object_id)
32
+
33
+ sexp.children.each { |n| populate_tree(el, n) }
34
+ xml.add_element el
35
+ end
36
+ end
37
+
38
+ def treewalk(sexp = @sexp)
39
+ return sexp unless sexp&.respond_to?(:children)
40
+ [sexp, sexp.children.map { |n| treewalk(n) }].flatten
41
+ end
42
+
43
+ def xpath(path)
44
+ results = XPath.match(doc, path)
45
+ results.map do |n|
46
+ if n.respond_to?(:attributes) && n.attributes['id']
47
+ treewalk.find do |m|
48
+ m.object_id.to_s == n.attributes['id']
49
+ end
50
+ else
51
+ n
52
+ end
53
+ end
54
+ end
55
+
56
+ def pp
57
+ doc.write(STDOUT, 2)
58
+ end
59
+ end
55
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recent_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Luitjes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - ".gitignore"
134
+ - ".rubocop.yml"
134
135
  - Gemfile
135
136
  - Gemfile.lock
136
137
  - LICENSE